fix phpstan, cs, and rector rules

This commit is contained in:
Julien Fastré 2024-05-28 12:45:07 +02:00
parent 059e4a0acd
commit 56d173046d
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
27 changed files with 30 additions and 65 deletions

View File

@ -76,7 +76,7 @@
"phpunit/phpunit": ">= 7.5", "phpunit/phpunit": ">= 7.5",
"psalm/plugin-phpunit": "^0.18.4", "psalm/plugin-phpunit": "^0.18.4",
"psalm/plugin-symfony": "^4.0.2", "psalm/plugin-symfony": "^4.0.2",
"rector/rector": "^0.17.7", "rector/rector": "^1.1.0",
"symfony/debug-bundle": "^5.1", "symfony/debug-bundle": "^5.1",
"symfony/dotenv": "^4.4", "symfony/dotenv": "^4.4",
"symfony/maker-bundle": "^1.20", "symfony/maker-bundle": "^1.20",

View File

@ -0,0 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$records of method League\\\\Csv\\\\Writer\\:\\:insertAll\\(\\) expects iterable\\<array\\<float\\|int\\|string\\|Stringable\\|null\\>\\>, iterable\\<array\\<string, bool\\|int\\|string\\>\\> given\\.$#"
count: 1
path: src/Bundle/ChillMainBundle/Controller/UserExportController.php

View File

@ -31,4 +31,5 @@ includes:
- phpstan-baseline-level-3.neon - phpstan-baseline-level-3.neon
- phpstan-baseline-level-4.neon - phpstan-baseline-level-4.neon
- phpstan-baseline-level-5.neon - phpstan-baseline-level-5.neon
- phpstan-baseline-2024-05.neon

View File

@ -45,9 +45,6 @@ return static function (RectorConfig $rectorConfig): void {
// skip some path... // skip some path...
$rectorConfig->skip([ $rectorConfig->skip([
// we need to discuss this: are we going to have FALSE in tests instead of an error ?
\Rector\Php71\Rector\FuncCall\CountOnNullRector::class,
// we must adapt service definition // we must adapt service definition
\Rector\Symfony\Symfony28\Rector\MethodCall\GetToConstructorInjectionRector::class, \Rector\Symfony\Symfony28\Rector\MethodCall\GetToConstructorInjectionRector::class,
\Rector\Symfony\Symfony34\Rector\Closure\ContainerGetNameToTypeInTestsRector::class, \Rector\Symfony\Symfony34\Rector\Closure\ContainerGetNameToTypeInTestsRector::class,

View File

@ -49,20 +49,17 @@ interface CustomFieldInterface
/** /**
* Return if the value can be considered as empty. * Return if the value can be considered as empty.
*
* @param mixed $value the value passed throug the deserialize function
*/ */
public function isEmptyValue($value, CustomField $customField); public function isEmptyValue(mixed $value, CustomField $customField);
/** /**
* Return a repsentation of the value of the CustomField. * Return a repsentation of the value of the CustomField.
* *
* @param mixed $value the raw value, **not deserialized** (= as stored in the db)
* @param \Chill\CustomFieldsBundle\CustomField\CustomField $customField * @param \Chill\CustomFieldsBundle\CustomField\CustomField $customField
* *
* @return string an html representation of the value * @return string an html representation of the value
*/ */
public function render($value, CustomField $customField, $documentType = 'html'); public function render(mixed $value, CustomField $customField, $documentType = 'html');
/** /**
* Transform the value into a format that can be stored in DB. * Transform the value into a format that can be stored in DB.

View File

@ -399,8 +399,6 @@ final class CustomFieldsChoiceTest extends KernelTestCase
/** /**
* @dataProvider emptyDataProvider * @dataProvider emptyDataProvider
*
* @param mixed $data deserialized data
*/ */
public function testIsEmptyValueEmpty(mixed $data) public function testIsEmptyValueEmpty(mixed $data)
{ {

View File

@ -29,7 +29,7 @@ class JWTOnDavUrlAuthenticator extends JWTTokenAuthenticator
TokenExtractorInterface $tokenExtractor, TokenExtractorInterface $tokenExtractor,
private readonly DavOnUrlTokenExtractor $davOnUrlTokenExtractor, private readonly DavOnUrlTokenExtractor $davOnUrlTokenExtractor,
TokenStorageInterface $preAuthenticationTokenStorage, TokenStorageInterface $preAuthenticationTokenStorage,
TranslatorInterface $translator = null, ?TranslatorInterface $translator = null,
) { ) {
parent::__construct($jwtManager, $dispatcher, $tokenExtractor, $preAuthenticationTokenStorage, $translator); parent::__construct($jwtManager, $dispatcher, $tokenExtractor, $preAuthenticationTokenStorage, $translator);
} }

View File

@ -149,7 +149,7 @@ final readonly class WopiEditTwigExtensionRuntime implements RuntimeExtensionInt
* @throws \Twig\Error\RuntimeError * @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError * @throws \Twig\Error\SyntaxError
*/ */
public function renderButtonGroup(Environment $environment, StoredObject $document, string $title = null, bool $canEdit = true, array $options = []): string public function renderButtonGroup(Environment $environment, StoredObject $document, ?string $title = null, bool $canEdit = true, array $options = []): string
{ {
$accessToken = $this->davTokenProvider->createToken( $accessToken = $this->davTokenProvider->createToken(
$document, $document,
@ -174,7 +174,7 @@ final readonly class WopiEditTwigExtensionRuntime implements RuntimeExtensionInt
]); ]);
} }
public function renderEditButton(Environment $environment, StoredObject $document, array $options = null): string public function renderEditButton(Environment $environment, StoredObject $document, ?array $options = null): string
{ {
return $environment->render(self::TEMPLATE, [ return $environment->render(self::TEMPLATE, [
'document' => $document, 'document' => $document,

View File

@ -32,7 +32,7 @@ class StoredObjectVoterTest extends TestCase
/** /**
* @dataProvider provideDataVote * @dataProvider provideDataVote
*/ */
public function testVote(TokenInterface $token, null|object $subject, string $attribute, mixed $expected): void public function testVote(TokenInterface $token, ?object $subject, string $attribute, mixed $expected): void
{ {
$voter = new StoredObjectVoter(); $voter = new StoredObjectVoter();
@ -98,7 +98,7 @@ class StoredObjectVoterTest extends TestCase
]; ];
} }
private function buildToken(StoredObjectRoleEnum $storedObjectRoleEnum = null, StoredObject $storedObject = null): TokenInterface private function buildToken(?StoredObjectRoleEnum $storedObjectRoleEnum = null, ?StoredObject $storedObject = null): TokenInterface
{ {
$token = $this->prophesize(TokenInterface::class); $token = $this->prophesize(TokenInterface::class);

View File

@ -206,8 +206,6 @@ class EventTypeController extends AbstractController
/** /**
* Creates a form to delete a EventType entity by id. * Creates a form to delete a EventType entity by id.
* *
* @param mixed $id The entity id
*
* @return \Symfony\Component\Form\Form The form * @return \Symfony\Component\Form\Form The form
*/ */
private function createDeleteForm(mixed $id) private function createDeleteForm(mixed $id)

View File

@ -206,8 +206,6 @@ class RoleController extends AbstractController
/** /**
* Creates a form to delete a Role entity by id. * Creates a form to delete a Role entity by id.
* *
* @param mixed $id The entity id
*
* @return \Symfony\Component\Form\Form The form * @return \Symfony\Component\Form\Form The form
*/ */
private function createDeleteForm(mixed $id) private function createDeleteForm(mixed $id)

View File

@ -206,8 +206,6 @@ class StatusController extends AbstractController
/** /**
* Creates a form to delete a Status entity by id. * Creates a form to delete a Status entity by id.
* *
* @param mixed $id The entity id
*
* @return \Symfony\Component\Form\Form The form * @return \Symfony\Component\Form\Form The form
*/ */
private function createDeleteForm(mixed $id) private function createDeleteForm(mixed $id)

View File

@ -700,7 +700,6 @@ class CRUDController extends AbstractController
* and view. * and view.
* *
* @param string $action * @param string $action
* @param mixed $entity the entity for the current request, or an array of entities
* *
* @return string the path to the template * @return string the path to the template
* *

View File

@ -317,8 +317,8 @@ final class PermissionsGroupController extends AbstractController
} }
return strcmp( return strcmp(
$translatableStringHelper->localize($a->getScope()->getName()), (string) $translatableStringHelper->localize($a->getScope()->getName()),
$translatableStringHelper->localize($b->getScope()->getName()) (string) $translatableStringHelper->localize($b->getScope()->getName())
); );
} }
); );
@ -451,8 +451,6 @@ final class PermissionsGroupController extends AbstractController
/** /**
* Creates a form to delete a link to roleScope. * Creates a form to delete a link to roleScope.
*
* @param mixed $permissionsGroup The entity id
*/ */
private function createDeleteRoleScopeForm( private function createDeleteRoleScopeForm(
PermissionsGroup $permissionsGroup, PermissionsGroup $permissionsGroup,

View File

@ -73,6 +73,7 @@ final readonly class UserExportController
) )
); );
$csv->addFormatter(fn (array $row) => null !== ($row['absenceStart'] ?? null) ? array_merge($row, ['absenceStart' => $row['absenceStart']->format('Y-m-d')]) : $row); $csv->addFormatter(fn (array $row) => null !== ($row['absenceStart'] ?? null) ? array_merge($row, ['absenceStart' => $row['absenceStart']->format('Y-m-d')]) : $row);
/* @phpstan-ignore-next-line as phpstan seem to ignore that we transform datetime into string */
$csv->insertAll($users); $csv->insertAll($users);
return new StreamedResponse( return new StreamedResponse(

View File

@ -344,11 +344,11 @@ class LoadPostalCodes extends AbstractFixture implements OrderedFixtureInterface
->findOneBy(['countryCode' => $countryCode]); ->findOneBy(['countryCode' => $countryCode]);
foreach ($lines as $line) { foreach ($lines as $line) {
$code = str_getcsv($line); $code = str_getcsv((string) $line);
$c = new PostalCode(); $c = new PostalCode();
$c->setCountry($country) $c->setCountry($country)
->setCode($code[0]) ->setCode($code[0])
->setName(\ucwords(\strtolower($code[1]))); ->setName(\ucwords(\strtolower((string) $code[1])));
if (null !== ($code[3] ?? null)) { if (null !== ($code[3] ?? null)) {
$c->setRefPostalCodeId($code[3]); $c->setRefPostalCodeId($code[3]);

View File

@ -73,7 +73,6 @@ interface AggregatorInterface extends ModifierInterface
* *
* @param string $key The column key, as added in the query * @param string $key The column key, as added in the query
* @param mixed[] $values The values from the result. if there are duplicates, those might be given twice. Example: array('FR', 'BE', 'CZ', 'FR', 'BE', 'FR') * @param mixed[] $values The values from the result. if there are duplicates, those might be given twice. Example: array('FR', 'BE', 'CZ', 'FR', 'BE', 'FR')
* @param mixed $data The data from the export's form (as defined in `buildForm`
* *
* @return \Closure where the first argument is the value, and the function should return the label to show in the formatted file. Example : `function($countryCode) use ($countries) { return $countries[$countryCode]->getName(); }` * @return \Closure where the first argument is the value, and the function should return the label to show in the formatted file. Example : `function($countryCode) use ($countries) { return $countries[$countryCode]->getName(); }`
*/ */

View File

@ -30,8 +30,6 @@ interface ExportElementValidatedInterface
/** /**
* validate the form's data and, if required, build a contraint * validate the form's data and, if required, build a contraint
* violation on the data. * violation on the data.
*
* @param mixed $data the data, as returned by the user
*/ */
public function validateForm(mixed $data, ExecutionContextInterface $context); public function validateForm(mixed $data, ExecutionContextInterface $context);
} }

View File

@ -96,7 +96,6 @@ interface ExportInterface extends ExportElementInterface
* *
* @param string $key The column key, as added in the query * @param string $key The column key, as added in the query
* @param mixed[] $values The values from the result. if there are duplicates, those might be given twice. Example: array('FR', 'BE', 'CZ', 'FR', 'BE', 'FR') * @param mixed[] $values The values from the result. if there are duplicates, those might be given twice. Example: array('FR', 'BE', 'CZ', 'FR', 'BE', 'FR')
* @param mixed $data The data from the export's form (as defined in `buildForm`)
* *
* @return (callable(string|int|float|'_header'|null $value): string|int|\DateTimeInterface) where the first argument is the value, and the function should return the label to show in the formatted file. Example : `function($countryCode) use ($countries) { return $countries[$countryCode]->getName(); }` * @return (callable(string|int|float|'_header'|null $value): string|int|\DateTimeInterface) where the first argument is the value, and the function should return the label to show in the formatted file. Example : `function($countryCode) use ($countries) { return $countries[$countryCode]->getName(); }`
*/ */

View File

@ -552,7 +552,6 @@ class ExportManager
* *
* This function check the acl. * This function check the acl.
* *
* @param mixed $data the data under the initial 'filters' data
* @param \Chill\MainBundle\Entity\Center[] $centers the picked centers * @param \Chill\MainBundle\Entity\Center[] $centers the picked centers
* *
* @throw UnauthorizedHttpException if the user is not authorized * @throw UnauthorizedHttpException if the user is not authorized
@ -615,9 +614,6 @@ class ExportManager
return $usedTypes; return $usedTypes;
} }
/**
* @param mixed $data the data from the filter key of the ExportType
*/
private function retrieveUsedFilters(mixed $data): iterable private function retrieveUsedFilters(mixed $data): iterable
{ {
if (null === $data) { if (null === $data) {
@ -634,8 +630,6 @@ class ExportManager
/** /**
* Retrieve the filter used in this export. * Retrieve the filter used in this export.
* *
* @param mixed $data the data from the `filters` key of the ExportType
*
* @return array an array with types * @return array an array with types
*/ */
private function retrieveUsedFiltersType(mixed $data): iterable private function retrieveUsedFiltersType(mixed $data): iterable

View File

@ -257,10 +257,10 @@ class SearchProvider
$this->mustBeExtracted[] = $matches[0][$key]; $this->mustBeExtracted[] = $matches[0][$key];
// strip parenthesis // strip parenthesis
if ( if (
'"' === mb_substr((string) $match, 0, 1) '"' === mb_substr($match, 0, 1)
&& '"' === mb_substr((string) $match, mb_strlen((string) $match) - 1) && '"' === mb_substr($match, mb_strlen($match) - 1)
) { ) {
$match = trim(mb_substr((string) $match, 1, mb_strlen((string) $match) - 2)); $match = trim(mb_substr($match, 1, mb_strlen($match) - 2));
} }
$terms[$matches[1][$key]] = $match; $terms[$matches[1][$key]] = $match;
} }

View File

@ -199,8 +199,6 @@ class AuthorizationHelper implements AuthorizationHelperInterface
* if the entity implements Chill\MainBundle\Entity\HasScopeInterface, * if the entity implements Chill\MainBundle\Entity\HasScopeInterface,
* the scope is taken into account. * the scope is taken into account.
* *
* @param mixed $entity the entity may also implement HasScopeInterface
*
* @return bool true if the user has access * @return bool true if the user has access
*/ */
public function userHasAccess(User $user, mixed $entity, string $attribute) public function userHasAccess(User $user, mixed $entity, string $attribute)

View File

@ -788,7 +788,7 @@ class AccompanyingPeriod implements
if (self::STEP_DRAFT === $this->getStep()) { if (self::STEP_DRAFT === $this->getStep()) {
return [[self::STEP_DRAFT]]; return [[self::STEP_DRAFT]];
} }
if (str_starts_with($this->getStep(), 'CONFIRM')) { if (str_starts_with((string) $this->getStep(), 'CONFIRM')) {
return [[self::STEP_DRAFT, self::STEP_CONFIRMED]]; return [[self::STEP_DRAFT, self::STEP_CONFIRMED]];
} }
if (self::STEP_CLOSED === $this->getStep()) { if (self::STEP_CLOSED === $this->getStep()) {

View File

@ -1787,10 +1787,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this; return $this;
} }
/** public function setSpokenLanguages(mixed $spokenLanguages): self
* @param Collection $spokenLanguages
*/
public function setSpokenLanguages($spokenLanguages): self
{ {
$this->spokenLanguages = $spokenLanguages; $this->spokenLanguages = $spokenLanguages;

View File

@ -112,8 +112,8 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
$andWhereSearchClause = []; $andWhereSearchClause = [];
$andWhereSearchClauseArgs = []; $andWhereSearchClauseArgs = [];
if ('' !== trim($default)) { if ('' !== trim((string) $default)) {
foreach (\explode(' ', $default) as $str) { foreach (\explode(' ', (string) $default) as $str) {
if ('' === trim($str)) { if ('' === trim($str)) {
continue; continue;
} }

View File

@ -686,20 +686,9 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
return $this; return $this;
} }
/** public function setCenters(Collection $centers): self
* @return $this
*/
public function setCenters(Collection $centers)
{ {
foreach ($centers as $center) { $this->centers = $centers;
$this->addCenter($center);
}
foreach ($this->centers as $center) {
if (false === $centers->contains($center)) {
$this->removeCenter($center);
}
}
return $this; return $this;
} }

View File

@ -17,7 +17,7 @@ use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Export\ListInterface; use Chill\MainBundle\Export\ListInterface;
use PhpParser\Node; use PhpParser\Node;
use Rector\Core\Rector\AbstractRector; use Rector\Rector\AbstractRector;
use Rector\Symfony\NodeAnalyzer\ClassAnalyzer; use Rector\Symfony\NodeAnalyzer\ClassAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;