diff --git a/phpstan-baseline-level-4.neon b/phpstan-baseline-level-4.neon index 8615e5aac..8010f3cbc 100644 --- a/phpstan-baseline-level-4.neon +++ b/phpstan-baseline-level-4.neon @@ -500,11 +500,6 @@ parameters: count: 1 path: src/Bundle/ChillCalendarBundle/Entity/Calendar.php - - - message: "#^Method Chill\\\\CalendarBundle\\\\Entity\\\\Calendar\\:\\:getUsers\\(\\) should return Doctrine\\\\Common\\\\Collections\\\\Collection&iterable\\ but returns Doctrine\\\\Common\\\\Collections\\\\ReadableCollection\\<\\(int\\|string\\), Chill\\\\MainBundle\\\\Entity\\\\User\\|null\\>\\.$#" - count: 1 - path: src/Bundle/ChillCalendarBundle/Entity/Calendar.php - - message: "#^Property Chill\\\\CalendarBundle\\\\Entity\\\\CalendarRange\\:\\:\\$id is never written, only read\\.$#" count: 1 @@ -3505,31 +3500,12 @@ parameters: count: 1 path: src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php - - - message: "#^Method Chill\\\\PersonBundle\\\\Entity\\\\AccompanyingPeriod\\:\\:getAvailablePersonLocation\\(\\) should return Doctrine\\\\Common\\\\Collections\\\\Collection&iterable\\ but returns Doctrine\\\\Common\\\\Collections\\\\ReadableCollection\\<\\(int\\|string\\), Chill\\\\PersonBundle\\\\Entity\\\\Person\\|null\\>\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php - - - - message: "#^Method Chill\\\\PersonBundle\\\\Entity\\\\AccompanyingPeriod\\:\\:getComments\\(\\) should return Doctrine\\\\Common\\\\Collections\\\\Collection but returns Doctrine\\\\Common\\\\Collections\\\\ReadableCollection\\<\\(int\\|string\\), mixed\\>\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php - message: "#^Method Chill\\\\PersonBundle\\\\Entity\\\\AccompanyingPeriod\\:\\:getCreatedAt\\(\\) should return DateTime\\|null but returns DateTimeInterface\\|null\\.$#" count: 1 path: src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php - - - message: "#^Method Chill\\\\PersonBundle\\\\Entity\\\\AccompanyingPeriod\\:\\:getOpenParticipations\\(\\) should return Doctrine\\\\Common\\\\Collections\\\\Collection but returns Doctrine\\\\Common\\\\Collections\\\\ReadableCollection\\<\\(int\\|string\\), mixed\\>\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php - - - - message: "#^Method Chill\\\\PersonBundle\\\\Entity\\\\AccompanyingPeriod\\:\\:getParticipationsContainsPerson\\(\\) should return Doctrine\\\\Common\\\\Collections\\\\Collection but returns Doctrine\\\\Common\\\\Collections\\\\ReadableCollection\\<\\(int\\|string\\), mixed\\>\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php - - message: "#^Method Chill\\\\PersonBundle\\\\Entity\\\\AccompanyingPeriod\\:\\:getRecursiveSocialActions\\(\\) has invalid return type Chill\\\\PersonBundle\\\\Entity\\\\SocialAction\\.$#" count: 1 @@ -3655,26 +3631,6 @@ parameters: count: 1 path: src/Bundle/ChillPersonBundle/Entity/Household/Household.php - - - message: "#^Method Chill\\\\PersonBundle\\\\Entity\\\\Household\\\\Household\\:\\:getCurrentMembersIds\\(\\) should return Doctrine\\\\Common\\\\Collections\\\\Collection but returns Doctrine\\\\Common\\\\Collections\\\\ReadableCollection\\<\\(int\\|string\\), int\\|null\\>\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Entity/Household/Household.php - - - - message: "#^Method Chill\\\\PersonBundle\\\\Entity\\\\Household\\\\Household\\:\\:getCurrentPersons\\(\\) should return Doctrine\\\\Common\\\\Collections\\\\Collection but returns Doctrine\\\\Common\\\\Collections\\\\ReadableCollection\\<\\(int\\|string\\), Chill\\\\PersonBundle\\\\Entity\\\\Person\\|null\\>\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Entity/Household/Household.php - - - - message: "#^Method Chill\\\\PersonBundle\\\\Entity\\\\Household\\\\Household\\:\\:getMembersDuringMembership\\(\\) should return Doctrine\\\\Common\\\\Collections\\\\Collection&iterable\\ but returns Doctrine\\\\Common\\\\Collections\\\\ReadableCollection\\<\\(int\\|string\\), mixed\\>\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Entity/Household/Household.php - - - - message: "#^Method Chill\\\\PersonBundle\\\\Entity\\\\Household\\\\Household\\:\\:getMembersOnRange\\(\\) should return Doctrine\\\\Common\\\\Collections\\\\Collection but returns Doctrine\\\\Common\\\\Collections\\\\ReadableCollection\\<\\(int\\|string\\), mixed\\>\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Entity/Household/Household.php - - message: "#^PHPDoc tag @return with type array\\ is incompatible with native type Doctrine\\\\Common\\\\Collections\\\\Collection\\.$#" count: 1 @@ -4140,11 +4096,6 @@ parameters: count: 1 path: src/Bundle/ChillPersonBundle/Repository/ResidentialAddressRepository.php - - - message: "#^Dead catch \\- Exception is never thrown in the try block\\.$#" - count: 2 - path: src/Bundle/ChillPersonBundle/Search/PersonSearch.php - - message: "#^Method Chill\\\\PersonBundle\\\\Search\\\\PersonSearch\\:\\:renderResult\\(\\) should return string but returns array\\\\>\\.$#" count: 1 @@ -4320,11 +4271,6 @@ parameters: count: 1 path: src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php - - - message: "#^Call to an undefined method Doctrine\\\\Common\\\\Collections\\\\ReadableCollection\\<\\(int\\|string\\), Chill\\\\PersonBundle\\\\Entity\\\\Person\\|null\\>\\:\\:add\\(\\)\\.$#" - count: 3 - path: src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php - - message: "#^Call to function array_key_exists\\(\\) with 'category' and array will always evaluate to true\\.$#" count: 1 @@ -5030,11 +4976,6 @@ parameters: count: 1 path: src/Bundle/ChillThirdPartyBundle/DependencyInjection/Configuration.php - - - message: "#^Method Chill\\\\ThirdPartyBundle\\\\Entity\\\\ThirdParty\\:\\:getActiveChildren\\(\\) should return Doctrine\\\\Common\\\\Collections\\\\Collection but returns Doctrine\\\\Common\\\\Collections\\\\ReadableCollection\\<\\(int\\|string\\), mixed\\>\\.$#" - count: 1 - path: src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php - - message: "#^PHPDoc tag @return with type DateTime\\|null is not subtype of native type DateTimeImmutable\\|null\\.$#" count: 1 diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 20970a799..a89386f29 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,10 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Variable property access on \\$this\\(Chill\\\\ActivityBundle\\\\Entity\\\\ActivityType\\)\\.$#" - count: 3 - path: src/Bundle/ChillActivityBundle/Entity/ActivityType.php - - message: "#^Foreach overwrites \\$key with its key variable\\.$#" count: 1 @@ -20,11 +15,6 @@ parameters: count: 1 path: src/Bundle/ChillEventBundle/Form/ChoiceLoader/EventChoiceLoader.php - - - message: "#^Variable method call on object\\.$#" - count: 2 - path: src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php - - message: "#^Cannot unset offset '_token' on array\\{formatter\\: mixed, export\\: mixed, centers\\: mixed, alias\\: string\\}\\.$#" count: 1 @@ -50,46 +40,11 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/Form/ChoiceLoader/PostalCodeChoiceLoader.php - - - message: "#^Variable \\$message on left side of \\?\\? always exists and is not nullable\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/Templating/ChillTwigHelper.php - - - - message: "#^Variable \\$sqls on left side of \\?\\? always exists and is not nullable\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Actions/Remove/PersonMove.php - - - - message: "#^Class Chill\\\\PersonBundle\\\\Entity\\\\Person constructor invoked with 1 parameter, 0 required\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php - - - - message: "#^Variable \\$street1Value might not be defined\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php - - - - message: "#^Variable method call on mixed\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php - - message: "#^Foreach overwrites \\$value with its value variable\\.$#" count: 1 path: src/Bundle/ChillPersonBundle/Form/ChoiceLoader/PersonChoiceLoader.php - - - message: "#^Foreach overwrites \\$action with its value variable\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Repository/SocialWork/GoalRepository.php - - - - message: "#^Foreach overwrites \\$action with its value variable\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Repository/SocialWork/ResultRepository.php - - message: "#^Foreach overwrites \\$value with its value variable\\.$#" count: 1 diff --git a/phpstan-deprecations.neon b/phpstan-deprecations.neon index aa8506411..c83feeb59 100644 --- a/phpstan-deprecations.neon +++ b/phpstan-deprecations.neon @@ -32,14 +32,6 @@ parameters: path: src/Bundle/ChillActivityBundle/Form/ActivityType.php - - - message: """ - #^Instantiation of deprecated class Symfony\\\\Component\\\\Security\\\\Core\\\\Role\\\\Role\\: - since Symfony 4\\.3, to be removed in 5\\.0\\. Use strings as roles instead\\.$# - """ - count: 1 - path: src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php - - message: """ #^Parameter \\$centerResolverDispatcher of method Chill\\\\ActivityBundle\\\\Repository\\\\ActivityACLAwareRepository\\:\\:__construct\\(\\) has typehint with deprecated interface Chill\\\\MainBundle\\\\Security\\\\Resolver\\\\CenterResolverDispatcherInterface\\: @@ -199,14 +191,6 @@ parameters: count: 2 path: src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadLanguages.php - - - message: """ - #^Class Chill\\\\MainBundle\\\\Entity\\\\User implements deprecated interface Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\AdvancedUserInterface\\: - since Symfony 4\\.1$# - """ - count: 1 - path: src/Bundle/ChillMainBundle/Entity/User.php - - message: """ #^Return type of method Chill\\\\MainBundle\\\\Entity\\\\User\\:\\:getRoles\\(\\) has typehint with deprecated class Symfony\\\\Component\\\\Security\\\\Core\\\\Role\\\\Role\\: @@ -329,22 +313,6 @@ parameters: count: 1 path: src/Bundle/ChillPersonBundle/Actions/ActionEvent.php - - - message: """ - #^Call to deprecated method getCurrentAccompanyingPeriod\\(\\) of class Chill\\\\PersonBundle\\\\Entity\\\\Person\\: - since 1\\.1 use `getOpenedAccompanyingPeriod instead$# - """ - count: 1 - path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php - - - - message: """ - #^Instantiation of deprecated class Symfony\\\\Component\\\\EventDispatcher\\\\Event\\: - since Symfony 4\\.3, use "Symfony\\\\Contracts\\\\EventDispatcher\\\\Event" instead$# - """ - count: 1 - path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php - - message: """ #^Class Chill\\\\PersonBundle\\\\Controller\\\\AccompanyingCourseController extends deprecated class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\Controller\\: @@ -541,11 +509,3 @@ parameters: count: 3 path: src/Bundle/ChillTaskBundle/Timeline/TaskLifeCycleEventTimelineProvider.php - - - message: """ - #^Instantiation of deprecated class Symfony\\\\Component\\\\Security\\\\Core\\\\Role\\\\Role\\: - since Symfony 4\\.3, to be removed in 5\\.0\\. Use strings as roles instead\\.$# - """ - count: 1 - path: src/Bundle/ChillThirdPartyBundle/Search/ThirdPartySearch.php - diff --git a/phpstan-types.neon b/phpstan-types.neon index 97be89e0e..7a2e3764a 100644 --- a/phpstan-types.neon +++ b/phpstan-types.neon @@ -100,11 +100,6 @@ parameters: count: 1 path: src/Bundle/ChillDocStoreBundle/Entity/DocumentCategory.php - - - message: "#^Method Chill\\\\EventBundle\\\\Entity\\\\Participation\\:\\:offsetGet\\(\\) should return mixed but return statement is missing\\.$#" - count: 1 - path: src/Bundle/ChillEventBundle/Entity/Participation.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 1 @@ -340,11 +335,6 @@ parameters: count: 1 path: src/Bundle/ChillPersonBundle/Form/Type/PersonPhoneType.php - - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" - count: 3 - path: src/Bundle/ChillPersonBundle/Search/PersonSearch.php - - message: "#^Method Chill\\\\PersonBundle\\\\Search\\\\PersonSearch\\:\\:renderResult\\(\\) should return string but return statement is missing\\.$#" count: 1 diff --git a/phpstan.neon.dist b/phpstan.neon.dist index b3164f6d7..9c611830d 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,7 +2,7 @@ parameters: level: 5 paths: - src/ - reportUnmatchedIgnoredErrors: false + reportUnmatchedIgnoredErrors: true excludePaths: - .php_cs* - docs/ diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php index 1f44a1af0..a6e0fc694 100644 --- a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php @@ -380,6 +380,7 @@ class ActivityType throw new InvalidArgumentException('Field "' . $field . '" not found'); } + /** @phpstan-ignore-next-line */ return $this->{$property}; } @@ -538,6 +539,7 @@ class ActivityType throw new InvalidArgumentException('Field "' . $field . '" not found'); } + /** @phpstan-ignore-next-line */ return self::FIELD_REQUIRED === $this->{$property}; } @@ -549,6 +551,7 @@ class ActivityType throw new InvalidArgumentException('Field "' . $field . '" not found'); } + /** @phpstan-ignore-next-line */ return self::FIELD_INVISIBLE !== $this->{$property}; } diff --git a/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php b/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php index 39e119bac..998219581 100644 --- a/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php +++ b/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php @@ -280,11 +280,13 @@ class ApiController extends AbstractCRUDController switch ($request->getMethod()) { case Request::METHOD_DELETE: // oups... how to use property accessor to remove element ? + /* @phpstan-ignore-next-line as we do not find a simpler way to do this */ $entity->{'remove' . ucfirst($property)}($postedData); break; case Request::METHOD_POST: + /* @phpstan-ignore-next-line as we do not find a simpler way to do this */ $entity->{'add' . ucfirst($property)}($postedData); break; diff --git a/src/Bundle/ChillMainBundle/Templating/ChillTwigHelper.php b/src/Bundle/ChillMainBundle/Templating/ChillTwigHelper.php index ade9139f1..a503426f0 100644 --- a/src/Bundle/ChillMainBundle/Templating/ChillTwigHelper.php +++ b/src/Bundle/ChillMainBundle/Templating/ChillTwigHelper.php @@ -90,7 +90,7 @@ class ChillTwigHelper extends AbstractExtension return $twig->render($t, array_merge([ 'value' => $value, - 'message' => $message ?? 'No value', + 'message' => $message, ], $options)); } } diff --git a/src/Bundle/ChillPersonBundle/Actions/Remove/PersonMove.php b/src/Bundle/ChillPersonBundle/Actions/Remove/PersonMove.php index 385a4b531..13a62094d 100644 --- a/src/Bundle/ChillPersonBundle/Actions/Remove/PersonMove.php +++ b/src/Bundle/ChillPersonBundle/Actions/Remove/PersonMove.php @@ -117,7 +117,7 @@ class PersonMove $from->getId() ); - return $sqls ?? []; + return $sqls; } protected function createDeleteSQL(ClassMetadata $metadata, Person $from, $field): string diff --git a/src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php b/src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php index 841aaaaf8..139305a0d 100644 --- a/src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php +++ b/src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php @@ -283,8 +283,7 @@ final class ImportPeopleFromCSVCommand extends Command $openingDateString = trim($row[array_search('opening_date', $headers, true)]); $openingDate = $this->processDate($openingDateString, $this->input->getOption('opening_date_format')); - // @TODO: Fix the constructor parameter, $openingDate does not exists. - $person = $openingDate instanceof DateTime ? new Person($openingDate) : new Person(); + $person = new Person(); // add the center $center = $this->getCenter($row, $headers); @@ -377,6 +376,7 @@ final class ImportPeopleFromCSVCommand extends Command $address->setPostcode($postalCode); if (in_array('street1', $headers, true)) { + /** @phpstan-ignore-next-line as this command is deprecated */ $address->setStreetAddress1($street1Value); } $address->setValidFrom(new DateTime('today')); @@ -1024,7 +1024,6 @@ final class ImportPeopleFromCSVCommand extends Command foreach ($possibleFormats as $format) { $this->logger->debug("Trying format {$format}", [__METHOD__]); - /** @phpstan-ignore-next-line */ $dateR = strptime($value, $format); if (is_array($dateR) && '' === $dateR['unparsed']) { diff --git a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php index 09f7dd513..4f43879fd 100644 --- a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php +++ b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php @@ -407,6 +407,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord private function createExpectedPerson($default): Person { + /** @var Person $person */ $person = $this->loader->loadData([ Person::class => [ 'person' => [ @@ -439,10 +440,15 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord break; case 'countryOfBirth': + $country = $this->countryRepository + ->findOneBy(['countryCode' => $value]); + $person->setCountryOfBirth($country); + + break; case 'nationality': $country = $this->countryRepository ->findOneBy(['countryCode' => $value]); - $person->{'set' . ucfirst($key)}($country); + $person->setNationality($country); break; @@ -484,42 +490,6 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord return $this->getReference($ref); } - /** - * Create a random address. - * - * @return Address - */ - private function getRandomAddress() - { - return (new Address()) - ->setStreetAddress1($this->faker->streetAddress) - ->setStreetAddress2( - mt_rand(0, 9) > 5 ? $this->faker->streetAddress : '' - ) - ->setPoint( - mt_rand(0, 9) > 5 ? $this->getRandomPoint() : null - ) - ->setPostcode($this->getReference( - LoadPostalCodes::$refs[array_rand(LoadPostalCodes::$refs)] - )) - ->setValidFrom($this->faker->dateTimeBetween('-5 years')); - } - - /** - * Create a random point. - * - * @return Point - */ - private function getRandomPoint() - { - $lonBrussels = 4.35243; - $latBrussels = 50.84676; - $lon = $lonBrussels + 0.01 * mt_rand(-5, 5); - $lat = $latBrussels + 0.01 * mt_rand(-5, 5); - - return Point::fromLonLat($lon, $lat); - } - private function getRandomSocialIssue(): SocialIssue { if (0 === count($this->cacheSocialIssues)) { diff --git a/src/Bundle/ChillPersonBundle/Repository/SocialWork/GoalRepository.php b/src/Bundle/ChillPersonBundle/Repository/SocialWork/GoalRepository.php index eaf8e9ee8..c667eafbf 100644 --- a/src/Bundle/ChillPersonBundle/Repository/SocialWork/GoalRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/SocialWork/GoalRepository.php @@ -111,9 +111,9 @@ final class GoalRepository implements ObjectRepository $orx = $qb->expr()->orX(); $i = 0; - foreach ($actions as $action) { + foreach ($actions as $act) { $orx->add(":action_{$i} MEMBER OF g.socialActions"); - $qb->setParameter("action_{$i}", $action); + $qb->setParameter("action_{$i}", $act); } $qb->where($orx); diff --git a/src/Bundle/ChillPersonBundle/Repository/SocialWork/ResultRepository.php b/src/Bundle/ChillPersonBundle/Repository/SocialWork/ResultRepository.php index 76fbb592c..747611500 100644 --- a/src/Bundle/ChillPersonBundle/Repository/SocialWork/ResultRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/SocialWork/ResultRepository.php @@ -146,9 +146,9 @@ final class ResultRepository implements ObjectRepository $orx = $qb->expr()->orX(); $i = 0; - foreach ($actions as $action) { + foreach ($actions as $act) { $orx->add(":action_{$i} MEMBER OF r.socialActions"); - $qb->setParameter("action_{$i}", $action); + $qb->setParameter("action_{$i}", $act); } $qb->where($orx);