From c35994203d7022c215b3b897ebb7ae0ec60c5285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 28 Apr 2023 22:55:01 +0200 Subject: [PATCH] fix phpstan issues --- .../Export/Export/ListActivityHelper.php | 1 - .../Controller/CustomFieldController.php | 3 --- .../CustomFields/CustomFieldLongChoice.php | 9 ++++++-- .../CRUD/Controller/ApiController.php | 2 ++ .../Authorization/AuthorizationHelper.php | 4 ++-- .../PasswordRecover/PasswordRecoverEvent.php | 22 +++++-------------- .../RollingDate/RollingDateConverter.php | 1 - .../Form/ChoiceLoader/PersonChoiceLoader.php | 5 ----- .../DataFixtures/ORM/LoadReports.php | 2 ++ .../Authorization/AuthorizationEvent.php | 18 +++++---------- 10 files changed, 24 insertions(+), 43 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Export/Export/ListActivityHelper.php b/src/Bundle/ChillActivityBundle/Export/Export/ListActivityHelper.php index 5af351b28..43c9f4688 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/ListActivityHelper.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/ListActivityHelper.php @@ -113,7 +113,6 @@ class ListActivityHelper 'usersIds' => self::MSG_KEY . 'users ids', 'thirdPartiesIds' => self::MSG_KEY . 'third parties ids', 'personsIds' => self::MSG_KEY . 'persons ids', - default => throw new LogicException('key not supported'), }; } diff --git a/src/Bundle/ChillCustomFieldsBundle/Controller/CustomFieldController.php b/src/Bundle/ChillCustomFieldsBundle/Controller/CustomFieldController.php index bc7bcfd65..a188ed277 100644 --- a/src/Bundle/ChillCustomFieldsBundle/Controller/CustomFieldController.php +++ b/src/Bundle/ChillCustomFieldsBundle/Controller/CustomFieldController.php @@ -162,9 +162,6 @@ class CustomFieldController extends AbstractController /** * Creates a form to create a CustomField entity. * - * @param CustomField $entity The entity - * @param string - * * @return \Symfony\Component\Form\Form The form */ private function createCreateForm(CustomField $entity, mixed $type) diff --git a/src/Bundle/ChillCustomFieldsBundle/CustomFields/CustomFieldLongChoice.php b/src/Bundle/ChillCustomFieldsBundle/CustomFields/CustomFieldLongChoice.php index 23f7b36bb..aa73af462 100644 --- a/src/Bundle/ChillCustomFieldsBundle/CustomFields/CustomFieldLongChoice.php +++ b/src/Bundle/ChillCustomFieldsBundle/CustomFields/CustomFieldLongChoice.php @@ -15,6 +15,7 @@ use Chill\CustomFieldsBundle\Entity\CustomField; use Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option; use Chill\CustomFieldsBundle\EntityRepository\CustomFieldLongChoice\OptionRepository; use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldDataTransformer; +use Chill\FamilyMembersBundle\Templating\Twig; use Chill\MainBundle\Form\Type\Select2ChoiceType; use Chill\MainBundle\Templating\TranslatableStringHelper; use LogicException; @@ -22,6 +23,7 @@ use Symfony\Bridge\Twig\TwigEngine; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Templating\EngineInterface; use function get_class; use function gettype; use function is_object; @@ -30,8 +32,11 @@ class CustomFieldLongChoice extends AbstractCustomField { public const KEY = 'key'; - public function __construct(private OptionRepository $optionRepository, private TranslatableStringHelper $translatableStringHelper, private TwigEngine $templating) - { + public function __construct( + private OptionRepository $optionRepository, + private TranslatableStringHelper $translatableStringHelper, + private EngineInterface $templating, + ) { } public function buildForm(FormBuilderInterface $builder, CustomField $customField) diff --git a/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php b/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php index c18dfd542..41a37d7ca 100644 --- a/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php +++ b/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php @@ -258,7 +258,9 @@ class ApiController extends AbstractCRUDController } match ($request->getMethod()) { + /* @phpstan-ignore-next-line */ Request::METHOD_DELETE => $entity->{'remove' . ucfirst($property)}($postedData), + /* @phpstan-ignore-next-line */ Request::METHOD_POST => $entity->{'add' . ucfirst($property)}($postedData), default => throw new BadRequestHttpException('this method is not supported'), }; diff --git a/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php b/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php index 2ba3865b7..c431c4492 100644 --- a/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php +++ b/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php @@ -209,9 +209,9 @@ class AuthorizationHelper implements AuthorizationHelperInterface throw new UnexpectedValueException( sprintf( - 'The entity given is not an instance of %s, %s given', + 'The entity given is not an instance of %s or an array of centers, %s given', Center::class, - $center::class + gettype($center) ) ); } diff --git a/src/Bundle/ChillMainBundle/Security/PasswordRecover/PasswordRecoverEvent.php b/src/Bundle/ChillMainBundle/Security/PasswordRecover/PasswordRecoverEvent.php index 8bc23b54a..5c8a01e1d 100644 --- a/src/Bundle/ChillMainBundle/Security/PasswordRecover/PasswordRecoverEvent.php +++ b/src/Bundle/ChillMainBundle/Security/PasswordRecover/PasswordRecoverEvent.php @@ -23,25 +23,15 @@ class PasswordRecoverEvent extends Event public const INVALID_TOKEN = 'chill_main.password_recover_invalid_token'; /** - * @var bool - */ - protected $safelyGenerated; - - /** - * @var User - */ - protected $user; - - /** - * @param type $token - * @param User $user - * @param type $ip * @param bool $safelyGenerated true if generated safely (from console command, etc.) */ - public function __construct(protected $token = null, ?User $user = null, protected $ip = null, bool $safelyGenerated = false) + public function __construct( + private ?string $token = null, + private ?User $user = null, + private $ip = null, + private bool $safelyGenerated = false, + ) { - $this->user = $user; - $this->safelyGenerated = $safelyGenerated; } public function getIp() diff --git a/src/Bundle/ChillMainBundle/Service/RollingDate/RollingDateConverter.php b/src/Bundle/ChillMainBundle/Service/RollingDate/RollingDateConverter.php index 0b9d5e4cd..da59e9e2b 100644 --- a/src/Bundle/ChillMainBundle/Service/RollingDate/RollingDateConverter.php +++ b/src/Bundle/ChillMainBundle/Service/RollingDate/RollingDateConverter.php @@ -87,7 +87,6 @@ class RollingDateConverter implements RollingDateConverterInterface 4, 5, 6 => '04', 7, 8, 9 => '07', 10, 11, 12 => '10', - default => throw new LogicException('this month is not valid: ' . $date->format('n')), }; return DateTimeImmutable::createFromFormat( diff --git a/src/Bundle/ChillPersonBundle/Form/ChoiceLoader/PersonChoiceLoader.php b/src/Bundle/ChillPersonBundle/Form/ChoiceLoader/PersonChoiceLoader.php index 05e720243..684914618 100644 --- a/src/Bundle/ChillPersonBundle/Form/ChoiceLoader/PersonChoiceLoader.php +++ b/src/Bundle/ChillPersonBundle/Form/ChoiceLoader/PersonChoiceLoader.php @@ -30,11 +30,6 @@ class PersonChoiceLoader implements ChoiceLoaderInterface protected array $lazyLoadedPersons = []; - /** - * PersonChoiceLoader constructor. - * - * @param EntityRepository $personRepository - */ public function __construct( protected PersonRepository $personRepository, ?array $centers = null diff --git a/src/Bundle/ChillReportBundle/DataFixtures/ORM/LoadReports.php b/src/Bundle/ChillReportBundle/DataFixtures/ORM/LoadReports.php index ae35e9eac..2dcf69c50 100644 --- a/src/Bundle/ChillReportBundle/DataFixtures/ORM/LoadReports.php +++ b/src/Bundle/ChillReportBundle/DataFixtures/ORM/LoadReports.php @@ -211,6 +211,8 @@ class LoadReports extends AbstractFixture implements ContainerAwareInterface, Or return $result; } } + + throw new \LogicException("should not happens"); } /** diff --git a/src/Bundle/ChillTaskBundle/Security/Authorization/AuthorizationEvent.php b/src/Bundle/ChillTaskBundle/Security/Authorization/AuthorizationEvent.php index eac97c8e2..1607ec56c 100644 --- a/src/Bundle/ChillTaskBundle/Security/Authorization/AuthorizationEvent.php +++ b/src/Bundle/ChillTaskBundle/Security/Authorization/AuthorizationEvent.php @@ -11,6 +11,8 @@ declare(strict_types=1); namespace Chill\TaskBundle\Security\Authorization; +use Chill\PersonBundle\Entity\Person; +use Chill\TaskBundle\Entity\AbstractTask; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; @@ -18,26 +20,16 @@ class AuthorizationEvent extends Event { public const VOTE = 'chill_task.vote'; - /** - * @var TokenInterface - */ - protected $token; - /** * @var bool */ protected $vote; - /** - * @param string $attribute - * @param \Chill\PersonBundle\Entity\Person|\Chill\TaskBundle\Entity\AbstractTask|null $subject - */ public function __construct( - protected \Chill\PersonBundle\Entity\Person|\Chill\TaskBundle\Security\Authorization\Chill\TaskBundle\Entity\AbstractTask|null $subject, - protected $attribute, - TokenInterface $token + private Person|AbstractTask|null $subject, + private string $attribute, + private TokenInterface $token ) { - $this->token = $token; } public function getAttribute()