DX: fix phpstan errors

This commit is contained in:
Julien Fastré 2023-02-07 23:49:56 +01:00
parent f57555dab4
commit 8ccce12e54
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
13 changed files with 21 additions and 201 deletions

View File

@ -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\\<Chill\\\\MainBundle\\\\Entity\\\\User\\> 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\\<Chill\\\\PersonBundle\\\\Entity\\\\Person\\> 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\\<Chill\\\\PersonBundle\\\\Entity\\\\Household\\\\HouseholdMember\\> 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\\<Chill\\\\PersonBundle\\\\Entity\\\\Household\\\\HouseholdMember\\> 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\\<string, array\\<bool\\|Chill\\\\PersonBundle\\\\Entity\\\\Person\\>\\>\\.$#"
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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -2,7 +2,7 @@ parameters:
level: 5
paths:
- src/
reportUnmatchedIgnoredErrors: false
reportUnmatchedIgnoredErrors: true
excludePaths:
- .php_cs*
- docs/

View File

@ -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};
}

View File

@ -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;

View File

@ -90,7 +90,7 @@ class ChillTwigHelper extends AbstractExtension
return $twig->render($t, array_merge([
'value' => $value,
'message' => $message ?? 'No value',
'message' => $message,
], $options));
}
}

View File

@ -117,7 +117,7 @@ class PersonMove
$from->getId()
);
return $sqls ?? [];
return $sqls;
}
protected function createDeleteSQL(ClassMetadata $metadata, Person $from, $field): string

View File

@ -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']) {

View File

@ -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)) {

View File

@ -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);

View File

@ -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);