Skip to content

Commit

Permalink
Bump PHPStan to 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
xificurk committed Jan 17, 2025
1 parent 97bd1e6 commit b18c48d
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 15 deletions.
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
},
"require-dev": {
"nette/tester": "2.5.4",
"phpstan/phpstan": "1.12.7",
"phpstan/phpstan-strict-rules": "1.6.1",
"phpstan/phpstan-nette": "1.3.8",
"nepada/phpstan-nette-tester": "1.2.1",
"spaze/phpstan-disallowed-calls": "4.0.1",
"shipmonk/phpstan-rules": "3.2.1",
"phpstan/phpstan": "2.1.1",
"phpstan/phpstan-strict-rules": "2.0.1",
"phpstan/phpstan-nette": "2.0.2",
"nepada/phpstan-nette-tester": "2.0.0",
"spaze/phpstan-disallowed-calls": "4.1.1",
"shipmonk/phpstan-rules": "4.1.0",
"php-parallel-lint/php-parallel-lint": "1.4.0",
"nepada/coding-standard": "7.14.1",
"nepada/message-bus-doctrine": "^2.1@dev",
Expand Down
42 changes: 42 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,45 @@ parameters:
uncheckedExceptionClasses:
- LogicException
- Nette\InvalidStateException

ignoreErrors:
- # pre-validated config
message: '#^Cannot access property \$onError on mixed\.$#'
identifier: property.nonObject
count: 1
path: src/MessageBusNette/DI/MessageBusExtension.php
- # pre-validated config
message: '#^Cannot access property \$onStart on mixed\.$#'
identifier: property.nonObject
count: 1
path: src/MessageBusNette/DI/MessageBusExtension.php
- # pre-validated config
message: '#^Cannot access property \$onSuccess on mixed\.$#'
identifier: property.nonObject
count: 1
path: src/MessageBusNette/DI/MessageBusExtension.php
- # pre-validated config
message: '#^Parameter \#1 \$bleedingEdge of static method Nepada\\MessageBus\\StaticAnalysis\\MessageHandlerValidationConfiguration\:\:command\(\) expects bool, mixed given\.$#'
identifier: argument.type
count: 1
path: src/MessageBusNette/DI/MessageBusExtension.php
- # pre-validated config
message: '#^Parameter \#1 \$bleedingEdge of static method Nepada\\MessageBus\\StaticAnalysis\\MessageHandlerValidationConfiguration\:\:event\(\) expects bool, mixed given\.$#'
identifier: argument.type
count: 1
path: src/MessageBusNette/DI/MessageBusExtension.php
- # pre-validated config
message: '#^Parameter \#1 \$class of function class_exists expects string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/MessageBusNette/DI/MessageBusExtension.php
- # pre-validated config
message: '#^Parameter \#1 \$definition of method Nepada\\MessageBusNette\\DI\\MessageBusExtension\:\:resolveLoggerService\(\) expects array\{class\: string, arguments\: array\<mixed\>\|null\}\|string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/MessageBusNette/DI/MessageBusExtension.php
-
message: '#^Method Nepada\\MessageBusNette\\DI\\PsrContainerAdapter\:\:get\(\) should return object but returns mixed\.$#'
identifier: return.type
count: 1
path: src/MessageBusNette/DI/PsrContainerAdapter.php
5 changes: 5 additions & 0 deletions phpstan.tests.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ parameters:

ignoreErrors:
- '~Call to static method Tester\\Assert::(type|count|same|notSame)\(\) with .* and .* will always evaluate to true\.~'
-
message: '#^Property NepadaTests\\MessageBusNette\\Fixtures\\Invoice\:\:\$id \(int\|null\) is never assigned int so it can be removed from the property type\.$#'
identifier: property.unusedType
count: 1
path: tests/MessageBusNette/Fixtures/Invoice.php
4 changes: 2 additions & 2 deletions tests/MessageBusNette/DI/MessageBusExtensionTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class MessageBusExtensionTest extends TestCase

/**
* @param iterable<HandlerDescriptor> $handlerDescriptors
* @return string[]
* @return list<string>
*/
private function extractNormalizedHandlerTypes(iterable $handlerDescriptors): array
{
Expand All @@ -88,7 +88,7 @@ class MessageBusExtensionTest extends TestCase
}

/**
* @return mixed[]
* @return list<mixed[]>
*/
protected function bleedingEdgeProvider(): array
{
Expand Down
6 changes: 3 additions & 3 deletions tests/MessageBusNette/Fixtures/TestLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ final class TestLogger extends AbstractLogger
{

/**
* @var array<int, array{level: mixed, message: string|\Stringable, context: array<mixed>}>
* @var list<array{level: mixed, message: string|\Stringable, context: array<string, mixed>}>
*/
public array $records = [];

/**
* @var array<string|int, array<int, array{level: mixed, message: string|\Stringable, context: array<mixed>}>>
* @var array<string|int, array<int, array{level: mixed, message: string|\Stringable, context: array<string, mixed>}>>
*/
public array $recordsByLevel = [];

Expand All @@ -23,7 +23,7 @@ final class TestLogger extends AbstractLogger
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.UselessAnnotation
* @param mixed $level
* @param string|\Stringable $message
* @param array<mixed> $context
* @param array<string, mixed> $context
*/
public function log(mixed $level, $message, array $context = []): void
{
Expand Down
7 changes: 4 additions & 3 deletions tests/MessageBusNette/IntegrationTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use NepadaTests\MessageBusNette\Fixtures\TestLogger;
use NepadaTests\TestCase;
use Nette;
use Tester\Assert;
use function array_values;

require_once __DIR__ . '/../bootstrap.php';

Expand Down Expand Up @@ -323,8 +324,8 @@ class IntegrationTest extends TestCase
}

/**
* @param array<int, array{level: mixed, message: string|\Stringable, context: array<string, mixed>}> $records
* @return array<int, array{level: mixed, message: string|\Stringable, context: array<string, mixed>}>
* @param list<array{level: mixed, message: string|\Stringable, context: array<string, mixed>}> $records
* @return list<array{level: mixed, message: string|\Stringable, context: array<string, mixed>}>
*/
private function normalizeLogRecords(array $records): array
{
Expand Down Expand Up @@ -356,7 +357,7 @@ class IntegrationTest extends TestCase
/** @var EntityManagerInterface $entityManager */
$entityManager = $container->getByType(EntityManagerInterface::class);
$connection = $entityManager->getConnection();
$metadata = $entityManager->getMetadataFactory()->getAllMetadata();
$metadata = array_values($entityManager->getMetadataFactory()->getAllMetadata());

Check failure on line 360 in tests/MessageBusNette/IntegrationTest.phpt

View workflow job for this annotation

GitHub Actions / PHP 8.2

Parameter #1 $array (list<Doctrine\ORM\Mapping\ClassMetadata>) of array_values is already a list, call has no effect.

Check failure on line 360 in tests/MessageBusNette/IntegrationTest.phpt

View workflow job for this annotation

GitHub Actions / PHP 8.2 --prefer-stable

Parameter #1 $array (list<Doctrine\ORM\Mapping\ClassMetadata>) of array_values is already a list, call has no effect.

Check failure on line 360 in tests/MessageBusNette/IntegrationTest.phpt

View workflow job for this annotation

GitHub Actions / PHP 8.2 --prefer-stable --prefer-lowest

Parameter #1 $array (list<Doctrine\ORM\Mapping\ClassMetadata>) of array_values is already a list, call has no effect.

Check failure on line 360 in tests/MessageBusNette/IntegrationTest.phpt

View workflow job for this annotation

GitHub Actions / PHP 8.3

Parameter #1 $array (list<Doctrine\ORM\Mapping\ClassMetadata>) of array_values is already a list, call has no effect.

Check failure on line 360 in tests/MessageBusNette/IntegrationTest.phpt

View workflow job for this annotation

GitHub Actions / PHP 8.3 --prefer-stable

Parameter #1 $array (list<Doctrine\ORM\Mapping\ClassMetadata>) of array_values is already a list, call has no effect.

Check failure on line 360 in tests/MessageBusNette/IntegrationTest.phpt

View workflow job for this annotation

GitHub Actions / PHP 8.3 --prefer-stable --prefer-lowest

Parameter #1 $array (list<Doctrine\ORM\Mapping\ClassMetadata>) of array_values is already a list, call has no effect.

Check failure on line 360 in tests/MessageBusNette/IntegrationTest.phpt

View workflow job for this annotation

GitHub Actions / PHP 8.4

Parameter #1 $array (list<Doctrine\ORM\Mapping\ClassMetadata>) of array_values is already a list, call has no effect.

Check failure on line 360 in tests/MessageBusNette/IntegrationTest.phpt

View workflow job for this annotation

GitHub Actions / PHP 8.4 --prefer-stable

Parameter #1 $array (list<Doctrine\ORM\Mapping\ClassMetadata>) of array_values is already a list, call has no effect.
$schemaTool = new SchemaTool($entityManager);
foreach ($schemaTool->getCreateSchemaSql($metadata) as $query) {
$connection->executeQuery($query);
Expand Down
43 changes: 42 additions & 1 deletion tests/PHPStan/conditional.config.tests.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
<?php
declare(strict_types = 1);

$config = [];
use Composer\Semver\VersionParser;

// Bypass standard composer API because of collision with libraries bundled inside phpstan.phar
$installed = require __DIR__ . '/../../vendor/composer/installed.php';
$versionParser = new VersionParser();
$isInstalled = function (string $packageName, string $versionConstraint) use ($versionParser, $installed): bool {
$constraint = $versionParser->parseConstraints($versionConstraint);
$installedVersion = $installed['versions'][$packageName]['pretty_version']; // @phpstan-ignore offsetAccess.nonOffsetAccessible,offsetAccess.nonOffsetAccessible,offsetAccess.nonOffsetAccessible
assert(is_string($installedVersion));
$provided = $versionParser->parseConstraints($installedVersion);
return $provided->matches($constraint);
};

$config = ['parameters' => ['ignoreErrors' => []]];

if ($isInstalled('psr/log', '<2.0')) {
$config['parameters']['ignoreErrors'][] = [
'message' => '#^Parameter \\#3 \\$context \\(array\\<string, mixed\\>\\) of method NepadaTests\\\\MessageBusNette\\\\Fixtures\\\\TestLogger\\:\\:log\\(\\) should be contravariant with parameter \\$context \\(array(\\<mixed\\>)?\\) of method Psr\\\\Log\\\\LoggerInterface\\:\\:log\\(\\)$#',
'identifier' => 'method.childParameterType',
'count' => 2,
'path' => __DIR__ . '/../../tests/MessageBusNette/Fixtures/TestLogger.php',
];
} else {
$config['parameters']['ignoreErrors'][] = [
'message' => '#^Parameter \\#3 \\$context \\(array\\<string, mixed\\>\\) of method NepadaTests\\\\MessageBusNette\\\\Fixtures\\\\TestLogger\\:\\:log\\(\\) should be contravariant with parameter \\$context \\(array\\) of method Psr\\\\Log\\\\LoggerTrait\\:\\:log\\(\\)$#',
'identifier' => 'method.childParameterType',
'count' => 1,
'path' => __DIR__ . '/../../tests/MessageBusNette/Fixtures/TestLogger.php',
];
$config['parameters']['ignoreErrors'][] = [
'message' => '#^Parameter \\#3 \\$context \\(array\\<string, mixed\\>\\) of method NepadaTests\\\\MessageBusNette\\\\Fixtures\\\\TestLogger\\:\\:log\\(\\) should be contravariant with parameter \\$context \\(array(\\<mixed\\>)?\\) of method Psr\\\\Log\\\\AbstractLogger\\:\\:log\\(\\)$#',
'identifier' => 'method.childParameterType',
'count' => 1,
'path' => __DIR__ . '/../../tests/MessageBusNette/Fixtures/TestLogger.php',
];
$config['parameters']['ignoreErrors'][] = [
'message' => '#^Parameter \\#3 \\$context \\(array\\<string, mixed\\>\\) of method NepadaTests\\\\MessageBusNette\\\\Fixtures\\\\TestLogger\\:\\:log\\(\\) should be contravariant with parameter \\$context \\(array\\<mixed\\>\\) of method Psr\\\\Log\\\\LoggerInterface\\:\\:log\\(\\)$#',
'identifier' => 'method.childParameterType',
'count' => 1,
'path' => __DIR__ . '/../../tests/MessageBusNette/Fixtures/TestLogger.php',
];
}

return $config;

0 comments on commit b18c48d

Please sign in to comment.