Skip to content

Commit

Permalink
[TASK] Fix phpstan for level 5, Generate baseline for level max (#465)
Browse files Browse the repository at this point in the history
* [TASK] Fix phpstan for level 5

* [TASK] Raise phpstan level to max and generate baseline
  • Loading branch information
linawolf authored Nov 22, 2024
1 parent 60a5dc3 commit 6bc9ab2
Show file tree
Hide file tree
Showing 9 changed files with 319 additions and 7 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@
"fix:php": [
"@fix:php:cs-fixer"
],
"update:phpstan-baseline": [
"@php phpstan analyse --generate-baseline"
],
"fix:php:cs-fixer": "@php php-cs-fixer fix",
"satis:install": [
"rm -fr satis",
Expand Down
307 changes: 307 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,307 @@
parameters:
ignoreErrors:
-
message: '#^Parameter \#1 \$environment of class App\\Kernel constructor expects string, mixed given\.$#'
identifier: argument.type
count: 1
path: public/index.php

-
message: '#^Cannot access offset ''composer_name'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 2
path: src/Command/ExtensionsTerJsonCreateCommand.php

-
message: '#^Cannot access offset ''error'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/Command/ExtensionsTerJsonCreateCommand.php

-
message: '#^Parameter \#1 \$dependencies of method App\\Command\\ExtensionsTerJsonCreateCommand\:\:getPackageLinks\(\) expects array\<string, array\<string, string\>\>, array\<mixed, mixed\> given\.$#'
identifier: argument.type
count: 1
path: src/Command/ExtensionsTerJsonCreateCommand.php

-
message: '#^Parameter \#1 \$message of class RuntimeException constructor expects string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/Command/ExtensionsTerJsonCreateCommand.php

-
message: '#^Property App\\Command\\ExtensionsTerJsonCreateCommand\:\:\$extensions \(array\<int, SimpleXMLElement\>\) does not accept array\<SimpleXMLElement\>\.$#'
identifier: assign.propertyType
count: 1
path: src/Command/ExtensionsTerJsonCreateCommand.php

-
message: '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\.$#'
identifier: foreach.nonIterable
count: 1
path: src/Command/ListMissingDownloadsCommand.php

-
message: '#^Binary operation "\." between mixed and ''\:'' results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Command/ListMissingDownloadsCommand.php

-
message: '#^Cannot access offset ''releases'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/Command/ListMissingDownloadsCommand.php

-
message: '#^Cannot access offset ''tar'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/Command/ListMissingDownloadsCommand.php

-
message: '#^Cannot access offset ''url'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 2
path: src/Command/ListMissingDownloadsCommand.php

-
message: '#^Cannot access offset ''zip'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/Command/ListMissingDownloadsCommand.php

-
message: '#^Parameter \#1 \$url of method App\\Command\\ListMissingDownloadsCommand\:\:getFixedUrl\(\) expects string, mixed given\.$#'
identifier: argument.type
count: 2
path: src/Command/ListMissingDownloadsCommand.php

-
message: '#^Parameter \#2 \$release of method App\\Command\\ListMissingDownloadsCommand\:\:getFixedUrl\(\) expects string, mixed given\.$#'
identifier: argument.type
count: 2
path: src/Command/ListMissingDownloadsCommand.php

-
message: '#^Parameter \#1 \$callback of function array_map expects \(callable\(mixed\)\: mixed\)\|null, Closure\(Symfony\\Component\\Validator\\ConstraintViolationInterface\)\: \(string\|Stringable\) given\.$#'
identifier: argument.type
count: 1
path: src/Controller/Api/SitepackageController.php

-
message: '#^Parameter \#1 \$packages of method App\\Service\\ComposerPackagesService\:\:cleanPackagesForVersions\(\) expects array\<string, bool\|string\>, array\<mixed\> given\.$#'
identifier: argument.type
count: 1
path: src/Controller/DefaultController.php

-
message: '#^Binary operation "\." between ''https\://typo3…'' and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Controller/DownloadController.php

-
message: '#^Binary operation "\." between non\-falsy\-string and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Controller/DownloadController.php

-
message: '#^Cannot access offset ''latest'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/Controller/DownloadController.php

-
message: '#^Cannot access offset ''releases'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/Controller/DownloadController.php

-
message: '#^Cannot access offset ''version'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/Controller/DownloadController.php

-
message: '#^Cannot access offset mixed on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/Controller/DownloadController.php

-
message: '#^Cannot cast mixed to string\.$#'
identifier: cast.string
count: 1
path: src/Controller/DownloadController.php

-
message: '#^Method App\\Controller\\DownloadController\:\:getDownloadRedirect\(\) should return array\{url\: string, version\: string, format\: string\} but returns array\{url\: non\-falsy\-string, version\: mixed, format\: ''tar\.gz''\|''tar\.gz\.sig''\|''zip''\|''zip\.sig''\}\.$#'
identifier: return.type
count: 1
path: src/Controller/DownloadController.php

-
message: '#^Parameter \#1 \$version1 of function version_compare expects string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/Controller/DownloadController.php

-
message: '#^Parameter \#2 \.\.\.\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given\.$#'
identifier: argument.type
count: 1
path: src/Controller/DownloadController.php

-
message: '#^Method App\\Controller\\SitepackageController\:\:createEditSitePackageForm\(\) return type with generic interface Symfony\\Component\\Form\\FormInterface does not specify its types\: TData$#'
identifier: missingType.generics
count: 1
path: src/Controller/SitepackageController.php

-
message: '#^Method App\\Controller\\SitepackageController\:\:createNewSitepackageForm\(\) return type with generic interface Symfony\\Component\\Form\\FormInterface does not specify its types\: TData$#'
identifier: missingType.generics
count: 1
path: src/Controller/SitepackageController.php

-
message: '#^Parameter \#2 \.\.\.\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given\.$#'
identifier: argument.type
count: 1
path: src/DataFixtures/ReleaseFixtures.php

-
message: '#^Method App\\Entity\\Release\:\:getMajorVersion\(\) should return App\\Entity\\MajorVersion but returns App\\Entity\\MajorVersion\|null\.$#'
identifier: return.type
count: 1
path: src/Entity/Release.php

-
message: '#^Binary operation "\." between ''Unknown option \('' and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Enum/AbstractEnum.php

-
message: '#^Class App\\Form\\AuthorType extends generic class Symfony\\Component\\Form\\AbstractType but does not specify its types\: TData$#'
identifier: missingType.generics
count: 1
path: src/Form/AuthorType.php

-
message: '#^Method App\\Form\\AuthorType\:\:buildForm\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: src/Form/AuthorType.php

-
message: '#^Cannot access offset ''icon'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/Form/Extension/AbstractIconExtension.php

-
message: '#^Class App\\Form\\SitepackageType extends generic class Symfony\\Component\\Form\\AbstractType but does not specify its types\: TData$#'
identifier: missingType.generics
count: 1
path: src/Form/SitepackageType.php

-
message: '#^Parameter \#1 \$action of method Symfony\\Component\\Form\\FormConfigBuilderInterface\<mixed\>\:\:setAction\(\) expects string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/Form/SitepackageType.php

-
message: '#^Offset ''repositories'' might not exist on array\{name\: string, homepage\: string\|null, repositories\?\: array\<int, array\<string, string\>\>\|null, require\?\: array\<string, string\>\|null, require\-all\: bool, require\-dependencies\: bool, require\-dev\-dependencies\: bool\}\.$#'
identifier: offsetAccess.notFound
count: 1
path: src/Model/SatisJson.php

-
message: '#^Offset ''require'' might not exist on array\{name\: string, homepage\: string\|null, repositories\?\: non\-empty\-array\<int, array\<string, string\>\>\|null, require\?\: array\<string, string\>\|null, require\-all\: bool, require\-dependencies\: bool, require\-dev\-dependencies\: bool\}\.$#'
identifier: offsetAccess.notFound
count: 1
path: src/Model/SatisJson.php

-
message: '#^Method App\\Repository\\MajorVersionRepository\:\:findAllActiveElts\(\) should return array\<App\\Entity\\MajorVersion\> but returns array\<mixed, mixed\>\.$#'
identifier: return.type
count: 1
path: src/Repository/MajorVersionRepository.php

-
message: '#^Method App\\Repository\\MajorVersionRepository\:\:findAllComposerSupported\(\) should return array\<App\\Entity\\MajorVersion\> but returns array\<mixed, mixed\>\.$#'
identifier: return.type
count: 1
path: src/Repository/MajorVersionRepository.php

-
message: '#^Method App\\Repository\\MajorVersionRepository\:\:findLatestLtsComposerSupported\(\) should return App\\Entity\\MajorVersion\|null but returns mixed\.$#'
identifier: return.type
count: 1
path: src/Repository/MajorVersionRepository.php

-
message: '#^Parameter \#1 \$version of method App\\Repository\\MajorVersionRepository\:\:majorVersionDescending\(\) expects App\\Entity\\MajorVersion, mixed given\.$#'
identifier: argument.type
count: 2
path: src/Repository/MajorVersionRepository.php

-
message: '#^Parameter \#1 \$versions of method App\\Repository\\MajorVersionRepository\:\:removeVersionsWithoutReleases\(\) expects array\<int, App\\Entity\\MajorVersion\>, array\<mixed, mixed\> given\.$#'
identifier: argument.type
count: 3
path: src/Repository/MajorVersionRepository.php

-
message: '#^Binary operation "\." between non\-falsy\-string and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Service/CacheWarmupService.php

-
message: '#^Cannot call method getStatusCode\(\) on mixed\.$#'
identifier: method.nonObject
count: 1
path: src/Service/CacheWarmupService.php

-
message: '#^Method App\\Service\\ComposerPackagesService\:\:buildForm\(\) has parameter \$builder with generic interface Symfony\\Component\\Form\\FormBuilderInterface but does not specify its types\: TData$#'
identifier: missingType.generics
count: 1
path: src/Service/ComposerPackagesService.php

-
message: '#^Method App\\Service\\ComposerPackagesService\:\:buildForm\(\) return type with generic interface Symfony\\Component\\Form\\FormInterface does not specify its types\: TData$#'
identifier: missingType.generics
count: 1
path: src/Service/ComposerPackagesService.php

-
message: '#^Offset 0 might not exist on array\{0\?\: string\}\.$#'
identifier: offsetAccess.notFound
count: 1
path: src/Service/ComposerPackagesService.php

-
message: '#^Parameter \#1 \$child of method Symfony\\Component\\Form\\FormBuilderInterface\<mixed\>\:\:add\(\) expects string\|Symfony\\Component\\Form\\FormBuilderInterface, list\<string\>\|string given\.$#'
identifier: argument.type
count: 1
path: src/Service/ComposerPackagesService.php

-
message: '#^Parameter \#1 \$releases of method App\\Twig\\Filter\\SortByVersion\:\:sort\(\) expects Doctrine\\Common\\Collections\\Collection\<int, App\\Entity\\Release\>, mixed given\.$#'
identifier: argument.type
count: 1
path: src/Twig/Filter/SortByVersion.php

-
message: '#^Method App\\Tests\\Functional\\Controller\\Api\\ApiCase\:\:decodeResponse\(\) should return array\<string, mixed\> but returns array\<mixed, mixed\>\.$#'
identifier: return.type
count: 1
path: tests/Functional/Controller/Api/ApiCase.php
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
includes:
- phpstan-baseline.neon
parameters:
level: max
treatPhpDocTypesAsCertain: false
Expand Down
2 changes: 1 addition & 1 deletion src/DataFixtures/ReleaseFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected function generateReleasesForMajorVersion(
for ($changeIteration = 0; $changeIteration < $faker->numberBetween(5, 50); ++$changeIteration) {
$changelog[] = sprintf(
'2019-10-30 7254d67918 [%s] ' . $faker->sentence($faker->numberBetween(4, 8)) . ' (thanks to %s)',
$faker->randomElement($changelogTypes), /** @phpstan-ignore-line */
$faker->randomElement($changelogTypes),
$faker->name()
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Release.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Release implements \JsonSerializable, \Stringable
#[Assert\NotNull]
#[ORM\ManyToOne(targetEntity: MajorVersion::class, inversedBy: 'releases')]
#[ORM\JoinColumn(name: 'major_version', referencedColumnName: 'version')]
private MajorVersion $majorVersion;
private ?MajorVersion $majorVersion;

#[Assert\Valid]
#[ORM\Embedded(class: ReleaseNotes::class)]
Expand Down
2 changes: 1 addition & 1 deletion src/Form/SitepackageType.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
class SitepackageType extends AbstractType
{
/**
* @param array{action: string} $options
* @param array<string, mixed> $options
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/Model/SatisJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class SatisJson implements \Stringable
* @var array{
* name: string,
* homepage: string|null,
* repositories: array<int, array<string, string>>|array{},
* require: array<string, string>|array{},
* repositories?: array<int, array<string, string>>|null,
* require?: array<string, string>|null,
* require-all: bool,
* require-dependencies: bool,
* require-dev-dependencies: bool
Expand Down
2 changes: 1 addition & 1 deletion src/Service/ComposerPackagesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ public function buildForm(FormBuilderInterface $builder): FormInterface

foreach (self::PACKAGES as $package) {
$builder->add(
str_replace('/', '-', $package['name']), /** @phpstan-ignore-line */
str_replace('/', '-', $package['name']),
CheckboxType::class,
[
'value' => $package['name'],
Expand Down
2 changes: 1 addition & 1 deletion src/Twig/Filter/ChangeHighlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function highlightChanges(string $changeList): ?string
$pattern,
static function ($matches): string {
$cssClass = 'change-' . strtolower($matches['type']);
if (isset($matches['important']) && $matches['important'] !== '') {
if ($matches['important'] !== '') {
$cssClass .= ' change-important';
}

Expand Down

0 comments on commit 6bc9ab2

Please sign in to comment.