Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -6235,54 +6235,6 @@
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/BadgeRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot cast mixed to string\\.$#',
'identifier' => 'cast.string',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/EventCouponRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\EventCouponRepository\\:\\:changeCouponForEvent\\(\\) has parameter \\$coupons with no value type specified in iterable type array\\.$#',
'identifier' => 'missingType.iterableValue',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/EventCouponRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\EventCouponRepository\\:\\:couponsListForEvent\\(\\) has no return type specified\\.$#',
'identifier' => 'missingType.return',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/EventCouponRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\EventCouponRepository\\:\\:initMetadata\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#',
'identifier' => 'missingType.iterableValue',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/EventCouponRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\EventCouponRepository\\:\\:initMetadata\\(\\) should return M of CCMBenchmark\\\\Ting\\\\Repository\\\\Metadata but returns CCMBenchmark\\\\Ting\\\\Repository\\\\Metadata\\<object\\>\\.$#',
'identifier' => 'return.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/EventCouponRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(mixed\\)\\: mixed\\)\\|null, Closure\\(AppBundle\\\\Event\\\\Model\\\\EventCoupon\\)\\: string given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/EventCouponRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$databaseName of method CCMBenchmark\\\\Ting\\\\Repository\\\\Metadata\\<object\\>\\:\\:setDatabase\\(\\) expects string, mixed given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/EventCouponRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$iterator of function iterator_to_array expects iterable, mixed given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/EventCouponRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Argument of an invalid type CCMBenchmark\\\\Ting\\\\Repository\\\\CollectionInterface\\<AppBundle\\\\Event\\\\Model\\\\Event\\>\\|null supplied for foreach, only iterables are supported\\.$#',
'identifier' => 'foreach.nonIterable',
Expand Down
6 changes: 3 additions & 3 deletions sources/AppBundle/Controller/Admin/Event/EventAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace AppBundle\Controller\Admin\Event;

use AppBundle\Event\Entity\Repository\EventCouponRepository;
use AppBundle\Event\Form\EventType;
use AppBundle\Event\Model\Event;
use AppBundle\Event\Model\Repository\EventCouponRepository;
use AppBundle\Event\Model\Repository\EventRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface;
Expand Down Expand Up @@ -35,7 +35,7 @@ public function __invoke(Request $request, $id): Response

$form = $this->createForm(EventType::class, $event);

if ($event->getId() && $couponsImploded = $this->couponRepository->couponsListForEventImploded($event)) {
if ($event->getId() && $couponsImploded = $this->couponRepository->couponsListForEventImploded((int) $event->getId())) {
$form->get('coupons')->setData($couponsImploded);
}

Expand All @@ -49,7 +49,7 @@ public function __invoke(Request $request, $id): Response

if ($form->get('coupons')->getData()) {
$eventCoupons = explode(',', (string) $form->get('coupons')->getData());
$this->couponRepository->changeCouponForEvent($event, $eventCoupons);
$this->couponRepository->changeCouponForEvent((int) $event->getId(), $eventCoupons);
}

$this->addFlash('notice', 'Évènement ' . ($id ? 'modifié' : 'ajouté'));
Expand Down
24 changes: 24 additions & 0 deletions sources/AppBundle/Event/Entity/EventCoupon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace AppBundle\Event\Entity;

use AppBundle\Event\Entity\Repository\EventCouponRepository;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: EventCouponRepository::class)]
#[ORM\Table(name: 'afup_forum_coupon')]
class EventCoupon
Comment thread
Korbeil marked this conversation as resolved.
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
public int $id;

#[ORM\Column(name: 'id_forum', nullable: false)]
public int $eventId;

#[ORM\Column(name: 'texte', length: 45, nullable: false)]
public string $texte;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

namespace AppBundle\Event\Entity\Repository;

use AppBundle\Doctrine\EntityRepository;
use AppBundle\Event\Entity\EventCoupon;
use Doctrine\Persistence\ManagerRegistry;

/**
* @extends EntityRepository<EventCoupon>
*/
final class EventCouponRepository extends EntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, EventCoupon::class);
}

/**
* @param list<string> $coupons
*/
public function changeCouponForEvent(int $eventId, array $coupons): void
{
$this->getEntityManager()->wrapInTransaction(function () use ($eventId, $coupons): void {
($qb = $this->createQueryBuilder('c'))
->delete()
->where($qb->expr()->eq('c.eventId', ':eventId'))
->setParameter('eventId', $eventId)
->getQuery()
->execute();

foreach ($coupons as $coupon) {
$coupon = trim($coupon);
if ($coupon === '') {
continue;
}

$eventCoupon = new EventCoupon();
$eventCoupon->eventId = $eventId;
$eventCoupon->texte = $coupon;
$this->getEntityManager()->persist($eventCoupon);
}

$this->getEntityManager()->flush();
});
}

/**
* @return list<EventCoupon>
*/
public function couponsListForEvent(int $eventId): array
{
return ($qb = $this->createQueryBuilder('c'))
->where($qb->expr()->eq('c.eventId', ':eventId'))
->setParameter('eventId', $eventId)
->orderBy('c.id', 'ASC')
->getQuery()
->getResult();
}

public function couponsListForEventImploded(int $eventId, string $separator = ', '): string
{
$texts = array_map(
static fn(EventCoupon $coupon): string => $coupon->texte,
$this->couponsListForEvent($eventId),
);

return implode($separator, $texts);
}
}
68 changes: 0 additions & 68 deletions sources/AppBundle/Event/Model/EventCoupon.php

This file was deleted.

This file was deleted.

Loading
Loading