Skip to content
Open
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
142 changes: 5 additions & 137 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -757,22 +757,10 @@
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/Form/TicketEventType.php',
];
$ignoreErrors[] = [
'message' => '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#',
'identifier' => 'foreach.nonIterable',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/Form/UserBadgeType.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot call method getBadge\\(\\) on mixed\\.$#',
'identifier' => 'method.nonObject',
'count' => 2,
'path' => __DIR__ . '/sources/AppBundle/Association/Form/UserBadgeType.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot call method getId\\(\\) on mixed\\.$#',
'identifier' => 'method.nonObject',
'count' => 4,
'count' => 2,
'path' => __DIR__ . '/sources/AppBundle/Association/Form/UserBadgeType.php',
];
$ignoreErrors[] = [
Expand All @@ -782,13 +770,13 @@
'path' => __DIR__ . '/sources/AppBundle/Association/Form/UserBadgeType.php',
];
$ignoreErrors[] = [
'message' => '#^Possibly invalid array key type int\\|null\\.$#',
'identifier' => 'offsetAccess.invalidOffset',
'message' => '#^Parameter \\#1 \\$userId of method AppBundle\\\\Event\\\\Entity\\\\Repository\\\\UserBadgeRepository\\:\\:findByUserId\\(\\) expects int, mixed given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/Form/UserBadgeType.php',
];
$ignoreErrors[] = [
'message' => '#^Possibly invalid array key type mixed\\.$#',
'message' => '#^Possibly invalid array key type int\\|null\\.$#',
'identifier' => 'offsetAccess.invalidOffset',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/Form/UserBadgeType.php',
Expand Down Expand Up @@ -1696,7 +1684,7 @@
$ignoreErrors[] = [
'message' => '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#',
'identifier' => 'foreach.nonIterable',
'count' => 3,
'count' => 2,
'path' => __DIR__ . '/sources/AppBundle/Association/UserMembership/BadgesComputer.php',
];
$ignoreErrors[] = [
Expand Down Expand Up @@ -1750,12 +1738,6 @@
$ignoreErrors[] = [
'message' => '#^Cannot call method format\\(\\) on mixed\\.$#',
'identifier' => 'method.nonObject',
'count' => 3,
'path' => __DIR__ . '/sources/AppBundle/Association/UserMembership/BadgesComputer.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot call method getBadge\\(\\) on mixed\\.$#',
'identifier' => 'method.nonObject',
'count' => 2,
'path' => __DIR__ . '/sources/AppBundle/Association/UserMembership/BadgesComputer.php',
];
Expand All @@ -1765,24 +1747,6 @@
'count' => 2,
'path' => __DIR__ . '/sources/AppBundle/Association/UserMembership/BadgesComputer.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot call method getId\\(\\) on mixed\\.$#',
'identifier' => 'method.nonObject',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/UserMembership/BadgesComputer.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot call method getIssuedAt\\(\\) on mixed\\.$#',
'identifier' => 'method.nonObject',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/UserMembership/BadgesComputer.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot call method getLabel\\(\\) on mixed\\.$#',
'identifier' => 'method.nonObject',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/UserMembership/BadgesComputer.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot call method getPath\\(\\) on mixed\\.$#',
'identifier' => 'method.nonObject',
Expand Down Expand Up @@ -3757,72 +3721,24 @@
'count' => 2,
'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Members/GeneralMeeting/ReportsAction.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$entity of method CCMBenchmark\\\\Ting\\\\Repository\\\\Repository\\<AppBundle\\\\Event\\\\Model\\\\UserBadge\\>\\:\\:delete\\(\\) expects AppBundle\\\\Event\\\\Model\\\\UserBadge, AppBundle\\\\Event\\\\Model\\\\UserBadge\\|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/UserBadgeDeleteAction.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access offset \'badge\' on mixed\\.$#',
'identifier' => 'offsetAccess.nonOffsetAccessible',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Members/UserBadgeNewAction.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access offset \'date\' on mixed\\.$#',
'identifier' => 'offsetAccess.nonOffsetAccessible',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Members/UserBadgeNewAction.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access offset \'user\' on mixed\\.$#',
'identifier' => 'offsetAccess.nonOffsetAccessible',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Members/UserBadgeNewAction.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$badgeId of method AppBundle\\\\Event\\\\Model\\\\UserBadge\\:\\:setBadgeId\\(\\) expects int, mixed given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Members/UserBadgeNewAction.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$issuedAt of method AppBundle\\\\Event\\\\Model\\\\UserBadge\\:\\:setIssuedAt\\(\\) expects DateTime\\|null, mixed given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Members/UserBadgeNewAction.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' => '#^Parameter \\#1 \\$userId of method AppBundle\\\\Event\\\\Model\\\\UserBadge\\:\\:setUserId\\(\\) expects int, mixed 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',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Members/UserEditAction.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$iterator of function iterator_to_array expects iterable, mixed given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Members/UserEditAction.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#2 \\$plainPassword of method Symfony\\\\Component\\\\PasswordHasher\\\\Hasher\\\\UserPasswordHasherInterface\\:\\:hashPassword\\(\\) expects string, mixed given\\.$#',
'identifier' => 'argument.type',
Expand Down Expand Up @@ -7213,54 +7129,6 @@
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TicketTypeRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\UserBadgeRepository\\:\\:findByUserId\\(\\) has no return type specified\\.$#',
'identifier' => 'missingType.return',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/UserBadgeRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\UserBadgeRepository\\:\\:findByUserId\\(\\) has parameter \\$userId with no type specified\\.$#',
'identifier' => 'missingType.parameter',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/UserBadgeRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\UserBadgeRepository\\:\\:getHydratorForUserBadge\\(\\) has no return type specified\\.$#',
'identifier' => 'missingType.return',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/UserBadgeRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\UserBadgeRepository\\:\\: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/UserBadgeRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\UserBadgeRepository\\:\\: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/UserBadgeRepository.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/UserBadgeRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$hydrator of method CCMBenchmark\\\\Ting\\\\Repository\\\\Repository\\<AppBundle\\\\Event\\\\Model\\\\UserBadge\\>\\:\\:getCollection\\(\\) expects CCMBenchmark\\\\Ting\\\\Repository\\\\HydratorInterface\\<mixed\\>\\|null, mixed given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/UserBadgeRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Unable to resolve the template type U in call to method CCMBenchmark\\\\Ting\\\\Repository\\\\Repository\\<AppBundle\\\\Event\\\\Model\\\\UserBadge\\>\\:\\:getCollection\\(\\)$#',
'identifier' => 'argument.templateType',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/UserBadgeRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot cast mixed to int\\.$#',
'identifier' => 'cast.int',
Expand Down
6 changes: 3 additions & 3 deletions sources/AppBundle/Association/Form/UserBadgeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace AppBundle\Association\Form;

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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use AppBundle\Association\Model\CompanyMember;
use AppBundle\Association\Model\User;
use AppBundle\Event\Model\Repository\EventRepository;
use AppBundle\Event\Model\Repository\UserBadgeRepository;
use AppBundle\Event\Entity\Repository\UserBadgeRepository;

class BadgesComputer
{
Expand Down Expand Up @@ -38,13 +38,11 @@ private function getSpecificBadges(User $user): array
{
$specific = [];

$userBadges = $this->userBadgeRepository->findByUserId($user->getId());

foreach ($userBadges as $userBadge) {
foreach ($this->userBadgeRepository->findByUserId($user->getId()) as $badgeAttribue) {
$specific[] = [
'date' => $userBadge->getIssuedAt()->format('Y-m-d'),
'id' => $userBadge->getBadge()->getId(),
'tooltip' => $userBadge->getBadge()->getLabel(),
'date' => $badgeAttribue->issuedAt->format('Y-m-d'),
'id' => $badgeAttribue->badgeId,
'tooltip' => $badgeAttribue->badgeLabel,
];
}

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

namespace AppBundle\Controller\Admin\Members;

use AppBundle\Event\Model\Repository\UserBadgeRepository;
use AppBundle\Event\Entity\Repository\UserBadgeRepository;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;

Expand All @@ -14,11 +14,20 @@ public function __construct(private readonly UserBadgeRepository $userBadgeRepos

public function __invoke(Request $request): RedirectResponse
{
$userBadge = $this->userBadgeRepository->getOneBy([
'badgeId' => $request->attributes->get('badgeId'),
'userId' => $request->attributes->get('userId'),
$badgeId = $request->attributes->get('badgeId');
$userId = $request->attributes->get('userId');

if (!is_numeric($badgeId) || !is_numeric($userId)) {
throw new \RuntimeException('Identifiants de badge invalides.');
}

$userBadge = $this->userBadgeRepository->find([
'badgeId' => (int) $badgeId,
'userId' => (int) $userId,
]);
$this->userBadgeRepository->delete($userBadge);
if ($userBadge !== null) {
$this->userBadgeRepository->delete($userBadge);
}

return new RedirectResponse($request->headers->get('referer'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use AppBundle\Association\Form\UserBadgeType;
use AppBundle\Association\Model\Repository\UserRepository;
use AppBundle\Event\Model\Repository\UserBadgeRepository;
use AppBundle\Event\Model\UserBadge;
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;
Expand All @@ -27,10 +27,19 @@ public function __invoke(Request $request): RedirectResponse
$userBadgeForm->handleRequest($request);
$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.');
}

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

return new RedirectResponse($request->headers->get('referer'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use AppBundle\Association\Form\UserEditType;
use AppBundle\Association\Model\Repository\UserRepository;
use AppBundle\AuditLog\Audit;
use AppBundle\Event\Model\Repository\UserBadgeRepository;
use AppBundle\Event\Entity\Repository\UserBadgeRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down
19 changes: 19 additions & 0 deletions sources/AppBundle/Event/Entity/BadgeAttribue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace AppBundle\Event\Entity;

/**
* Badge attribué à un membre, avec les informations du badge portées par
* la table afup_badge (encore gérée par l'entité Ting AppBundle\Event\Model\Badge).
*/
final readonly class BadgeAttribue
{
public function __construct(
public int $userId,
public int $badgeId,
public string $badgeLabel,
public \DateTimeImmutable $issuedAt,
) {}
}
Loading
Loading