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
45 changes: 8 additions & 37 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -752,21 +752,21 @@
'path' => __DIR__ . '/sources/AppBundle/Association/Form/UserBadgeType.php',
];
$ignoreErrors[] = [
'message' => '#^Class AppBundle\\\\Association\\\\Form\\\\UserBadgeType extends generic class Symfony\\\\Component\\\\Form\\\\AbstractType but does not specify its types\\: TData$#',
'identifier' => 'missingType.generics',
'message' => '#^Cannot cast mixed to int\\.$#',
'identifier' => 'cast.int',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/Form/UserBadgeType.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$userId of method AppBundle\\\\Event\\\\Entity\\\\Repository\\\\UserBadgeRepository\\:\\:findByUserId\\(\\) expects int, mixed given\\.$#',
'identifier' => 'argument.type',
'message' => '#^Class AppBundle\\\\Association\\\\Form\\\\UserBadgeType extends generic class Symfony\\\\Component\\\\Form\\\\AbstractType but does not specify its types\\: TData$#',
'identifier' => 'missingType.generics',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/Form/UserBadgeType.php',
];
$ignoreErrors[] = [
'message' => '#^Possibly invalid array key type int\\|null\\.$#',
'identifier' => 'offsetAccess.invalidOffset',
'count' => 1,
'count' => 2,
'path' => __DIR__ . '/sources/AppBundle/Association/Form/UserBadgeType.php',
];
$ignoreErrors[] = [
Expand Down Expand Up @@ -3500,8 +3500,8 @@
'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Members/BadgeNewAction.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$label of method AppBundle\\\\Event\\\\Model\\\\Badge\\:\\:setLabel\\(\\) expects string, mixed given\\.$#',
'identifier' => 'argument.type',
'message' => '#^Property AppBundle\\\\Event\\\\Entity\\\\Badge\\:\\:\\$label \\(string\\) does not accept mixed\\.$#',
'identifier' => 'assign.propertyType',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Members/BadgeNewAction.php',
];
Expand Down Expand Up @@ -3595,18 +3595,6 @@
'count' => 2,
'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Members/GeneralMeeting/ReportsAction.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$url of class Symfony\\\\Component\\\\HttpFoundation\\\\RedirectResponse constructor expects string, string\\|null given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Members/UserBadgeDeleteAction.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$url of class Symfony\\\\Component\\\\HttpFoundation\\\\RedirectResponse constructor expects string, string\\|null given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Members/UserBadgeNewAction.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access offset \'first\' on mixed\\.$#',
'identifier' => 'offsetAccess.nonOffsetAccessible',
Expand Down Expand Up @@ -4507,6 +4495,7 @@
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/ValueResolver/AdminEventSelectionValueResolver.php',
];

$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$code of method AppBundle\\\\Antennes\\\\AntenneRepository\\:\\:findByCode\\(\\) expects string, mixed given\\.$#',
'identifier' => 'argument.type',
Expand Down Expand Up @@ -5821,24 +5810,6 @@
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Planning.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\BadgeRepository\\:\\: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/BadgeRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\BadgeRepository\\:\\:initMetadata\\(\\) return type with generic class CCMBenchmark\\\\Ting\\\\Repository\\\\Metadata does not specify its types\\: T$#',
'identifier' => 'missingType.generics',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/BadgeRepository.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/BadgeRepository.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
13 changes: 7 additions & 6 deletions sources/AppBundle/Association/Form/UserBadgeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace AppBundle\Association\Form;

use AppBundle\Event\Model\Repository\BadgeRepository;
use AppBundle\Event\Entity\Repository\BadgeRepository;
use AppBundle\Event\Entity\Repository\UserBadgeRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
Expand All @@ -24,17 +24,17 @@ public function __construct(
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$userBadgesIds = [];
foreach ($this->userBadgeRepository->findByUserId($options['user']->getId()) as $badgeAttribue) {
$userBadgesIds[$badgeAttribue->badgeId] = $badgeAttribue->badgeId;
foreach ($this->userBadgeRepository->findByUserId((int) $options['user']->getId()) as $userBadge) {
$userBadgesIds[$userBadge->badge->id] = $userBadge->badge->id;
}


$badges = [];
foreach ($this->badgeRepository->getAll() as $badge) {
if (isset($userBadgesIds[$badge->getId()])) {
foreach ($this->badgeRepository->findAll() as $badge) {
if (isset($userBadgesIds[$badge->id])) {
continue;
}
$badges[$badge->getLabel()] = $badge->getId();
$badges[$badge->label] = $badge->id;
}

$builder
Expand All @@ -51,6 +51,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
DateType::class,
[
'label' => 'Date',
'input' => 'datetime_immutable',
],
)
->add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use AppBundle\Association\MemberType;
use AppBundle\Association\Model\CompanyMember;
use AppBundle\Association\Model\User;
use AppBundle\Event\Model\Badge;
use AppBundle\Event\Entity\Badge;
use Aura\SqlQuery\Common\SelectInterface;
use CCMBenchmark\Ting\Driver\Mysqli\Serializer\Boolean;
use CCMBenchmark\Ting\Repository\CollectionInterface;
Expand Down Expand Up @@ -154,7 +154,7 @@ public function loadByBadge(Badge $badge)

return $this
->getPreparedQuery($queryBuilder->getStatement())
->setParams(['badge_id' => $badge->getId()])
->setParams(['badge_id' => $badge->id])
->query($this->getCollection($this->getHydratorForUser()))
;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ private function getSpecificBadges(User $user): array
{
$specific = [];

foreach ($this->userBadgeRepository->findByUserId($user->getId()) as $badgeAttribue) {
$userBadges = $this->userBadgeRepository->findByUserId((int) $user->getId());

foreach ($userBadges as $userBadge) {
$specific[] = [
'date' => $badgeAttribue->issuedAt->format('Y-m-d'),
'id' => $badgeAttribue->badgeId,
'tooltip' => $badgeAttribue->badgeLabel,
'date' => $userBadge->issuedAt->format('Y-m-d'),
'id' => $userBadge->badge->id,
'tooltip' => $userBadge->badge->label,
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace AppBundle\Controller\Admin\Members;

use AppBundle\Association\Model\Repository\UserRepository;
use AppBundle\Event\Model\Repository\BadgeRepository;
use AppBundle\Event\Entity\Repository\BadgeRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;
Expand All @@ -21,7 +21,7 @@ public function __construct(
public function __invoke(Request $request): Response
{
$infos = [];
foreach ($this->badgeRepository->getAll() as $badge) {
foreach ($this->badgeRepository->findAll() as $badge) {
$infos[] = [
'badge' => $badge,
'users' => $this->userRepository->loadByBadge($badge),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace AppBundle\Controller\Admin\Members;

use AppBundle\Association\Form\BadgeType;
use AppBundle\Event\Model\Badge;
use AppBundle\Event\Model\Repository\BadgeRepository;
use AppBundle\Event\Entity\Badge;
use AppBundle\Event\Entity\Repository\BadgeRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Filesystem\Filesystem;
Expand All @@ -33,8 +33,8 @@ public function __invoke(Request $request): Response
$data['image']->move($this->storageDir, $filename);

$badge = new Badge();
$badge->setLabel($data['label']);
$badge->setUrl($filename);
$badge->label = $data['label'];
$badge->url = $filename;
$this->badgeRepository->save($badge);
$this->addFlash('notice', 'Le badge a été ajouté');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,38 @@

namespace AppBundle\Controller\Admin\Members;

use AppBundle\Event\Entity\Badge;
use AppBundle\Event\Entity\Repository\BadgeRepository;
use AppBundle\Event\Entity\Repository\UserBadgeRepository;
use AppBundle\Event\Entity\UserBadge;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class UserBadgeDeleteAction
{
public function __construct(private readonly UserBadgeRepository $userBadgeRepository) {}
public function __construct(
private readonly BadgeRepository $badgeRepository,
private readonly UserBadgeRepository $userBadgeRepository,
) {}

public function __invoke(Request $request): RedirectResponse
{
$badgeId = $request->attributes->get('badgeId');
$userId = $request->attributes->get('userId');

if (!is_numeric($badgeId) || !is_numeric($userId)) {
throw new \RuntimeException('Identifiants de badge invalides.');
$badgeId = $request->attributes->getInt('badgeId');
$badge = $this->badgeRepository->find($badgeId);
if (! $badge instanceof Badge) {
throw new NotFoundHttpException(sprintf('Badge %d inexistant', $badgeId));
}

$userBadge = $this->userBadgeRepository->find([
'badgeId' => (int) $badgeId,
'userId' => (int) $userId,
$userBadge = $this->userBadgeRepository->findOneBy([
'userId' => $request->attributes->getInt('userId'),
'badge' => $badge,
]);
if ($userBadge !== null) {
$this->userBadgeRepository->delete($userBadge);
if (! $userBadge instanceof UserBadge) {
throw new NotFoundHttpException('Attribution de badge introuvable');
}
$this->userBadgeRepository->delete($userBadge);

return new RedirectResponse($request->headers->get('referer'));
return new RedirectResponse($request->headers->get('referer') ?? $request->getRequestUri());
}
}
25 changes: 15 additions & 10 deletions sources/AppBundle/Controller/Admin/Members/UserBadgeNewAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@

use AppBundle\Association\Form\UserBadgeType;
use AppBundle\Association\Model\Repository\UserRepository;
use AppBundle\Event\Entity\Repository\BadgeRepository;
use AppBundle\Event\Entity\Repository\UserBadgeRepository;
use AppBundle\Event\Entity\UserBadge;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class UserBadgeNewAction
{
public function __construct(
private readonly UserRepository $userRepository,
private readonly FormFactoryInterface $formFactory,
private readonly BadgeRepository $badgeRepository,
private readonly UserBadgeRepository $userBadgeRepository,
) {}

Expand All @@ -25,23 +28,25 @@ public function __invoke(Request $request): RedirectResponse
$user = $this->userRepository->get($request->query->get('user_id'));
$userBadgeForm = $this->formFactory->create(UserBadgeType::class, [], ['user' => $user]);
$userBadgeForm->handleRequest($request);
if (!$userBadgeForm->isSubmitted() || !$userBadgeForm->isValid()) {
return new RedirectResponse($request->headers->get('referer') ?? $request->getRequestUri());
}

/** @var array{badge: int, date: \DateTimeInterface, user: string} $data */
$data = $userBadgeForm->getData();

if (
!is_array($data)
|| !is_numeric($data['badge'] ?? null)
|| !is_numeric($data['user'] ?? null)
|| !($data['date'] ?? null) instanceof \DateTimeInterface
) {
throw new \RuntimeException('Données du formulaire d\'attribution de badge invalides.');
$badgeId = (int) $data['badge'];
$badge = $this->badgeRepository->find($badgeId);
if (null === $badge) {
throw new NotFoundHttpException(sprintf('Badge %d inexistant', $badgeId));
}

$userBadge = new UserBadge();
$userBadge->badgeId = (int) $data['badge'];
$userBadge->issuedAt = \DateTimeImmutable::createFromInterface($data['date']);
$userBadge->badge = $badge;
$userBadge->issuedAt = $data['date'];
$userBadge->userId = (int) $data['user'];
$this->userBadgeRepository->save($userBadge);

return new RedirectResponse($request->headers->get('referer'));
return new RedirectResponse($request->headers->get('referer') ?? $request->getRequestUri());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __invoke(Request $request): Response
]);
}

$userBadges = iterator_to_array($this->userBadgeRepository->findByUserId($user->getId()));
$userBadges = $this->userBadgeRepository->findByUserId((int) $user->getId());
$userBadgeForm = $this->createForm(UserBadgeType::class, [], [
'user' => $user,
'action' => $this->generateUrl('admin_members_user_badge_new', [
Expand Down
6 changes: 3 additions & 3 deletions sources/AppBundle/Controller/Website/Badge/ImageAction.php
Comment thread
Korbeil marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace AppBundle\Controller\Website\Badge;

use AppBundle\Event\Model\Repository\BadgeRepository;
use AppBundle\Event\Entity\Repository\BadgeRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
Expand All @@ -20,12 +20,12 @@ public function __construct(

public function __invoke(int $id): Response
{
$badge = $this->badgeRepository->get($id);
$badge = $this->badgeRepository->find($id);
if (null === $badge) {
throw $this->createNotFoundException();
}

$filepath = $this->storageDir . DIRECTORY_SEPARATOR . $badge->getUrl();
$filepath = $this->storageDir . DIRECTORY_SEPARATOR . $badge->url;
if (false === is_file($filepath)) {
throw $this->createNotFoundException();
}
Expand Down
24 changes: 24 additions & 0 deletions sources/AppBundle/Event/Entity/Badge.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\BadgeRepository;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: BadgeRepository::class)]
#[ORM\Table(name: 'afup_badge')]
class Badge
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
public ?int $id = null;

#[ORM\Column(length: 255, nullable: false)]
public string $label;

#[ORM\Column(length: 255, nullable: false)]
public string $url;
}
19 changes: 0 additions & 19 deletions sources/AppBundle/Event/Entity/BadgeAttribue.php

This file was deleted.

Loading
Loading