From 9edcaa52e903082b3e24cf5a6077f76f4f32eba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 4 Mar 2026 15:09:53 +0100 Subject: [PATCH] Fix phpstan issues --- phpstan-baseline.neon | 40 ------------------- phpstan.dist.neon | 1 + .../Audit/RemoveOldAuditCronJob.php | 2 + .../DependencyInjection/Configuration.php | 10 ++++- .../PersonResourceSubjectDisplayer.php | 2 - .../CommentSubjectConverter.php | 2 - .../Controller/PersonController.php | 2 - .../SingleTaskSubjectConverter.php | 4 +- 8 files changed, 14 insertions(+), 49 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 1a66e5be2..6f945dd15 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1803,46 +1803,6 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:canBeUnset\\(\\)\\.$#" - count: 2 - path: src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#" - count: 3 - path: src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php - - - - message: "#^Method Chill\\\\MainBundle\\\\DependencyInjection\\\\Configuration\\:\\:getWidgetFactories\\(\\) has invalid return type Chill\\\\MainBundle\\\\DependencyInjection\\\\Widget\\\\WidgetFactoryInterface\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php - - - - message: "#^PHPDoc tag @param has invalid value \\(WidgetFactoryInterface\\[\\]\\)\\: Unexpected token \"\\\\n \", expected variable at offset 42$#" - count: 1 - path: src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php - - - - message: "#^Parameter \\#1 \\$place of method Chill\\\\MainBundle\\\\DependencyInjection\\\\Configuration\\:\\:filterWidgetByPlace\\(\\) expects string, Chill\\\\MainBundle\\\\DependencyInjection\\\\Widget\\\\type given\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php - - - - message: "#^Parameter \\#1 \\$place of method Chill\\\\MainBundle\\\\DependencyInjection\\\\Configuration\\:\\:getWidgetAliasesbyPlace\\(\\) expects Chill\\\\MainBundle\\\\DependencyInjection\\\\Widget\\\\type, string given\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php - - - - message: "#^Parameter \\$place of method Chill\\\\MainBundle\\\\DependencyInjection\\\\Configuration\\:\\:getWidgetAliasesbyPlace\\(\\) has invalid type Chill\\\\MainBundle\\\\DependencyInjection\\\\Widget\\\\type\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php - - - - message: "#^Parameter \\$widgetFactories of method Chill\\\\MainBundle\\\\DependencyInjection\\\\Configuration\\:\\:setWidgetFactories\\(\\) has invalid type Chill\\\\MainBundle\\\\DependencyInjection\\\\Widget\\\\WidgetFactoryInterface\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php - - message: "#^Call to an undefined method Chill\\\\MainBundle\\\\DependencyInjection\\\\Widget\\\\Factory\\\\WidgetFactoryInterface\\:\\:getAllowedPlaces\\(\\)\\.$#" count: 3 diff --git a/phpstan.dist.neon b/phpstan.dist.neon index 60c36771e..6c6b30fab 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -21,6 +21,7 @@ parameters: - src/Bundle/*/src/migrations/* - src/Bundle/*/src/translations/* - src/Bundle/*/src/Resources/* + - src/Bundle/ChillMainBundle/DependencyInjection/Widget/AddWidgetConfigurationTrait.php includes: - phpstan-baseline.neon diff --git a/src/Bundle/ChillMainBundle/Audit/RemoveOldAuditCronJob.php b/src/Bundle/ChillMainBundle/Audit/RemoveOldAuditCronJob.php index c1cc804d2..6e07a4d83 100644 --- a/src/Bundle/ChillMainBundle/Audit/RemoveOldAuditCronJob.php +++ b/src/Bundle/ChillMainBundle/Audit/RemoveOldAuditCronJob.php @@ -31,6 +31,8 @@ final readonly class RemoveOldAuditCronJob implements CronJobInterface $config = $bag->get('chill_main.audit_trail'); if (is_array($config) && is_string($intervalString = $config['delete_after'] ?? null)) { $this->deleteBefore = new \DateInterval($intervalString); + } else { + throw new \InvalidArgumentException('Invalid configuration for delete_after interval'); } } diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php index a9f3c141b..bbf675e59 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\MainBundle\DependencyInjection; use Chill\MainBundle\DependencyInjection\Widget\AddWidgetConfigurationTrait; +use Symfony\Component\Config\Definition\Builder\ParentNodeDefinitionInterface; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -31,11 +32,16 @@ class Configuration implements ConfigurationInterface $this->setWidgetFactories($widgetFactories); } - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('chill_main'); $rootNode = $treeBuilder->getRootNode(); + if ($rootNode instanceof ParentNodeDefinitionInterface) { + throw new \LogicException('unexpected type'); + } + + /* @phpstan-ignore-next-line */ $rootNode ->children() ->scalarNode('installation_name') @@ -315,6 +321,7 @@ class Configuration implements ConfigurationInterface ->end() // end of root ; + /* @phpstan-ignore-next-line */ $rootNode->children() ->arrayNode('add_address')->addDefaultsIfNotSet()->children() ->scalarNode('default_country')->cannotBeEmpty()->defaultValue('BE')->end() @@ -325,6 +332,7 @@ class Configuration implements ConfigurationInterface ->end() ->end(); + /* @phpstan-ignore-next-line */ $rootNode->children() ->arrayNode('audit_trail')->addDefaultsIfNotSet()->children() ->scalarNode('delete_after')->cannotBeEmpty()->defaultValue('P6M')->info('The duration (a valid interval) before deleting the audit trail. Will be run by a cronjob.')->end() diff --git a/src/Bundle/ChillPersonBundle/Audit/Displayer/PersonResourceSubjectDisplayer.php b/src/Bundle/ChillPersonBundle/Audit/Displayer/PersonResourceSubjectDisplayer.php index 408888793..f24f09a71 100644 --- a/src/Bundle/ChillPersonBundle/Audit/Displayer/PersonResourceSubjectDisplayer.php +++ b/src/Bundle/ChillPersonBundle/Audit/Displayer/PersonResourceSubjectDisplayer.php @@ -15,7 +15,6 @@ use Chill\MainBundle\Audit\Subject; use Chill\MainBundle\Audit\SubjectDisplayerInterface; use Chill\MainBundle\Templating\Entity\ChillEntityRenderManagerInterface; use Chill\PersonBundle\Repository\PersonResourceRepository; -use Chill\PersonBundle\Templating\Entity\PersonRenderInterface; use Symfony\Contracts\Translation\TranslatorInterface; use Twig\Environment; @@ -25,7 +24,6 @@ final readonly class PersonResourceSubjectDisplayer implements SubjectDisplayerI private Environment $twig, private TranslatorInterface $translator, private PersonResourceRepository $personResourceRepository, - private PersonRenderInterface $personRender, private ChillEntityRenderManagerInterface $chillEntityRenderManager, ) {} diff --git a/src/Bundle/ChillPersonBundle/Audit/SubjectConverter/CommentSubjectConverter.php b/src/Bundle/ChillPersonBundle/Audit/SubjectConverter/CommentSubjectConverter.php index 108d472a8..4140e146a 100644 --- a/src/Bundle/ChillPersonBundle/Audit/SubjectConverter/CommentSubjectConverter.php +++ b/src/Bundle/ChillPersonBundle/Audit/SubjectConverter/CommentSubjectConverter.php @@ -27,8 +27,6 @@ class CommentSubjectConverter implements SubjectConverterInterface, SubjectConve public function convert(mixed $subject, bool $includeAssociated = false): SubjectBag { - \assert($subject instanceof Comment); - $main = new SubjectBag(new Subject('accompanying_period_comment', ['id' => $subject->getId()])); if (null !== $subject->getAccompanyingPeriod()) { diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonController.php b/src/Bundle/ChillPersonBundle/Controller/PersonController.php index f9e0786be..0156ffb22 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonController.php @@ -25,7 +25,6 @@ use Chill\PersonBundle\Security\Authorization\PersonVoter; use Doctrine\ORM\EntityManagerInterface; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Form; use Symfony\Component\HttpFoundation\Request; @@ -43,7 +42,6 @@ final class PersonController extends AbstractController private readonly AuthorizationHelperInterface $authorizationHelper, private readonly SimilarPersonMatcher $similarPersonMatcher, private readonly TranslatorInterface $translator, - private readonly EventDispatcherInterface $eventDispatcher, private readonly PersonRepository $personRepository, private readonly ConfigPersonAltNamesHelper $configPersonAltNameHelper, private readonly ValidatorInterface $validator, diff --git a/src/Bundle/ChillTaskBundle/Audit/SubjectConverter/SingleTaskSubjectConverter.php b/src/Bundle/ChillTaskBundle/Audit/SubjectConverter/SingleTaskSubjectConverter.php index 70d013a40..7b6f37333 100644 --- a/src/Bundle/ChillTaskBundle/Audit/SubjectConverter/SingleTaskSubjectConverter.php +++ b/src/Bundle/ChillTaskBundle/Audit/SubjectConverter/SingleTaskSubjectConverter.php @@ -31,9 +31,9 @@ final class SingleTaskSubjectConverter implements SubjectConverterInterface, Sub $main = new SubjectBag($mainSubject); if ($includeAssociated) { - if ($subject->getPerson()) { + if (null !== $subject->getPerson()) { $main->append($this->subjectConverterManager->getSubjectsForEntity($subject->getPerson(), false)); - } elseif ($subject->getCourse()) { + } elseif (null !== $subject->getCourse()) { $main->append($this->subjectConverterManager->getSubjectsForEntity($subject->getCourse(), false)); } }