Skip to content

Commit 3ba52d3

Browse files
authored
[tests] add known doc iterables (#255)
* [tests] add known doc iterables * cs
1 parent 3fa1382 commit 3ba52d3

File tree

87 files changed

+422
-59
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+422
-59
lines changed

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
"php": ">=8.2",
88
"webmozart/assert": "^1.12 || ^2.0",
99
"phpstan/phpstan": "^2.1.30",
10-
"nette/utils": "^4.0",
10+
"nette/utils": "^4.1",
1111
"phpstan/phpdoc-parser": "^2.3"
1212
},
1313
"require-dev": {
14-
"nikic/php-parser": "^5.6",
14+
"nikic/php-parser": "^5.7",
1515
"phpunit/phpunit": "^11.5",
1616
"symfony/framework-bundle": "6.1.*",
1717
"phpecs/phpecs": "^2.2",
1818
"tomasvotruba/class-leak": "^2.1",
19-
"rector/rector": "^2.2.11",
19+
"rector/rector": "^2.3",
2020
"phpstan/extension-installer": "^1.4",
2121
"symplify/phpstan-extensions": "^12.0",
2222
"tomasvotruba/unused-public": "^2.1",
23-
"tomasvotruba/type-coverage": "^2.0",
23+
"tomasvotruba/type-coverage": "^2.1",
2424
"shipmonk/composer-dependency-analyser": "^1.8",
2525
"rector/jack": "^0.4.0"
2626
},
@@ -40,7 +40,8 @@
4040
"stubs"
4141
],
4242
"files": [
43-
"vendor/symfony/dependency-injection/Loader/Configurator/ContainerConfigurator.php"
43+
"vendor/symfony/dependency-injection/Loader/Configurator/ContainerConfigurator.php",
44+
"tests/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule/Fixture/SomePhpFeatureRector.php"
4445
]
4546
},
4647
"config": {

phpstan.neon

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ parameters:
3333
- '#Method Symplify\\PHPStanRules\\(.*?)\:\:getRule\(\) return type with generic interface PHPStan\\Rules\\Rule does not specify its types\: TNodeType#'
3434
- '#Parameter \#2 \$expectedErrors of method PHPStan\\Testing\\RuleTestCase<PHPStan\\Rules\\Rule>\:\:analyse\(\) expects list<array\{0\: string, 1\: int, 2\?\: string\|null\}>, (.*?) given#'
3535

36-
# part of public contract
37-
- '#Method Symplify\\PHPStanRules\\Tests\\Rules\\(.*?)\\(.*?)Test\:\:testRule\(\) has parameter \$(expectedError(.*?)|expectedErrors) with no value type specified in iterable type array#'
38-
3936
# useful to have IDE know the types
4037
- identifier: phpstanApi.instanceofType
4138

@@ -47,6 +44,10 @@ parameters:
4744
# used in tests
4845
- '#Public constant "Symplify\\PHPStanRules\\(.*?)Rule\:\:ERROR_MESSAGE" is never used#'
4946

47+
-
48+
message: '#Generator expects value type array<string, mixed>, list<bool\|float\|int\|list<string>\|PHPStan\\TrinaryLogic\|string\|null> given#'
49+
path: tests/ReturnTypeExtension/NodeGetAttributeTypeExtension/NodeGetAttributeTypeExtensionTest.php
50+
5051
- '#Although PHPStan\\Node\\InClassNode is covered by backward compatibility promise, this instanceof assumption might break because (.*?) not guaranteed to always stay the same#'
5152
- '#PHPStan\\DependencyInjection\\NeonAdapter#'
5253

rector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77

88
return RectorConfig::configure()
99
->withPhpSets()
10-
->withPreparedSets(deadCode: true, codeQuality: true, codingStyle: true, typeDeclarations: true, privatization: true, naming: true, earlyReturn: true, phpunitCodeQuality: true)
10+
->withPreparedSets(deadCode: true, codeQuality: true, codingStyle: true, typeDeclarations: true, typeDeclarationDocblocks: true, privatization: true, naming: true, earlyReturn: true, phpunitCodeQuality: true)
1111
->withPaths([__DIR__ . '/config', __DIR__ . '/src', __DIR__ . '/tests'])
1212
->withRootFiles()
1313
->withImportNames()
1414
->withSkip([
1515
'*/Source/*',
1616
'*/Fixture/*',
1717
StringClassNameToClassConstantRector::class => [
18-
__DIR__ . '/src/Symfony/NodeAnalyzer/SymfonyControllerAnalyzer.php',
18+
__DIR__ . '/src/Enum',
19+
__DIR__ . '/src/Testing/PHPUnitTestAnalyser.php',
1920
__DIR__ . '/tests/Naming/ClassToSuffixResolverTest.php',
20-
__DIR__ . '/tests/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule/PhpUpgradeImplementsMinPhpVersionInterfaceRuleTest.php',
2121
],
2222
]);

src/Rules/NoGlobalConstRule.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpParser\Node;
88
use PhpParser\Node\Stmt\Const_;
99
use PHPStan\Analyser\Scope;
10+
use PHPStan\Rules\IdentifierRuleError;
1011
use PHPStan\Rules\Rule;
1112
use PHPStan\Rules\RuleErrorBuilder;
1213
use Symplify\PHPStanRules\Enum\RuleIdentifier;
@@ -29,6 +30,7 @@ public function getNodeType(): string
2930

3031
/**
3132
* @param Const_ $node
33+
* @return IdentifierRuleError[]
3234
*/
3335
public function processNode(Node $node, Scope $scope): array
3436
{

src/Rules/Symfony/RequiredOnlyInAbstractRule.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHPStan\Reflection\ClassReflection;
1313
use PHPStan\Rules\Rule;
1414
use PHPStan\Rules\RuleErrorBuilder;
15+
use Symplify\PHPStanRules\Enum\DoctrineClass;
1516
use Symplify\PHPStanRules\Enum\RuleIdentifier\SymfonyRuleIdentifier;
1617
use Symplify\PHPStanRules\NodeAnalyzer\SymfonyRequiredMethodAnalyzer;
1718

@@ -34,7 +35,7 @@ final class RequiredOnlyInAbstractRule implements Rule
3435
* @var string[]
3536
*/
3637
private const SKIPPED_PARENT_TYPES = [
37-
'Doctrine\ODM\MongoDB\Repository\DocumentRepository',
38+
DoctrineClass::DOCUMENT_REPOSITORY,
3839
];
3940

4041
public function getNodeType(): string

src/Symfony/NodeAnalyzer/SymfonyControllerAnalyzer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static function hasRouteAnnotationOrAttribute(ClassLike | ClassMethod $no
5959
return false;
6060
}
6161

62-
if (str_contains($docComment->getText(), 'Symfony\Component\Routing\Annotation\Route')) {
62+
if (str_contains($docComment->getText(), SymfonyClass::ROUTE_ANNOTATION)) {
6363
return true;
6464
}
6565

tests/ReturnTypeExtension/NodeGetAttributeTypeExtension/NodeGetAttributeTypeExtensionTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public function testAsserts(string $assertType, string $file, mixed ...$args): v
1919
$this->assertFileAsserts($assertType, $file, ...$args);
2020
}
2121

22+
/**
23+
* @return Iterator<array<string, mixed>>
24+
*/
2225
public static function dataAsserts(): Iterator
2326
{
2427
yield from self::gatherAssertTypes(__DIR__ . '/data/get_parent_node.php.inc');

tests/Rules/CheckRequiredInterfaceInContractNamespaceRule/CheckRequiredInterfaceInContractNamespaceRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@
1212

1313
final class CheckRequiredInterfaceInContractNamespaceRuleTest extends RuleTestCase
1414
{
15+
/**
16+
* @param array<int, array<string|int>> $expectedErrorsWithLines
17+
*/
1518
#[DataProvider('provideData')]
1619
public function testRule(string $filePath, array $expectedErrorsWithLines): void
1720
{
1821
$this->analyse([$filePath], $expectedErrorsWithLines);
1922
}
2023

24+
/**
25+
* @return Iterator<array<array<int, mixed>, mixed>>
26+
*/
2127
public static function provideData(): Iterator
2228
{
2329
yield [__DIR__ . '/Fixture/Contract/SkipInterfaceInContract.php', []];

tests/Rules/ClassNameRespectsParentSuffixRule/ClassNameRespectsParentSuffixRuleTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313
final class ClassNameRespectsParentSuffixRuleTest extends RuleTestCase
1414
{
1515
/**
16-
* @param mixed[] $expectedErrorMessagesWithLines
16+
* @param array<int, array<string|int>> $expectedErrorMessagesWithLines
1717
*/
1818
#[DataProvider('provideData')]
1919
public function testRule(string $filePath, array $expectedErrorMessagesWithLines): void
2020
{
2121
$this->analyse([$filePath], $expectedErrorMessagesWithLines);
2222
}
2323

24+
/**
25+
* @return Iterator<array<array<int, mixed>, mixed>>
26+
*/
2427
public static function provideData(): Iterator
2528
{
2629
yield [__DIR__ . '/Fixture/SkipCommand.php', []];

tests/Rules/Complexity/ForbiddenArrayMethodCallRule/ForbiddenArrayMethodCallRuleTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313
final class ForbiddenArrayMethodCallRuleTest extends RuleTestCase
1414
{
1515
/**
16-
* @param mixed[] $expectedErrorMessagesWithLines
16+
* @param array<int, array<string|int>> $expectedErrorMessagesWithLines
1717
*/
1818
#[DataProvider('provideData')]
1919
public function testRule(string $filePath, array $expectedErrorMessagesWithLines): void
2020
{
2121
$this->analyse([$filePath], $expectedErrorMessagesWithLines);
2222
}
2323

24+
/**
25+
* @return Iterator<array<array<int, mixed>, mixed>>
26+
*/
2427
public static function provideData(): Iterator
2528
{
2629
yield [__DIR__ . '/Fixture/SkipNormalArray.php', []];

0 commit comments

Comments
 (0)