Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
"php": ">=8.2",
"webmozart/assert": "^1.12 || ^2.0",
"phpstan/phpstan": "^2.1.30",
"nette/utils": "^4.0",
"nette/utils": "^4.1",
"phpstan/phpdoc-parser": "^2.3"
},
"require-dev": {
"nikic/php-parser": "^5.6",
"nikic/php-parser": "^5.7",
"phpunit/phpunit": "^11.5",
"symfony/framework-bundle": "6.1.*",
"phpecs/phpecs": "^2.2",
"tomasvotruba/class-leak": "^2.1",
"rector/rector": "^2.2.11",
"rector/rector": "^2.3",
"phpstan/extension-installer": "^1.4",
"symplify/phpstan-extensions": "^12.0",
"tomasvotruba/unused-public": "^2.1",
"tomasvotruba/type-coverage": "^2.0",
"tomasvotruba/type-coverage": "^2.1",
"shipmonk/composer-dependency-analyser": "^1.8",
"rector/jack": "^0.4.0"
},
Expand All @@ -40,7 +40,8 @@
"stubs"
],
"files": [
"vendor/symfony/dependency-injection/Loader/Configurator/ContainerConfigurator.php"
"vendor/symfony/dependency-injection/Loader/Configurator/ContainerConfigurator.php",
"tests/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule/Fixture/SomePhpFeatureRector.php"
]
},
"config": {
Expand Down
7 changes: 4 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ parameters:
- '#Method Symplify\\PHPStanRules\\(.*?)\:\:getRule\(\) return type with generic interface PHPStan\\Rules\\Rule does not specify its types\: TNodeType#'
- '#Parameter \#2 \$expectedErrors of method PHPStan\\Testing\\RuleTestCase<PHPStan\\Rules\\Rule>\:\:analyse\(\) expects list<array\{0\: string, 1\: int, 2\?\: string\|null\}>, (.*?) given#'

# part of public contract
- '#Method Symplify\\PHPStanRules\\Tests\\Rules\\(.*?)\\(.*?)Test\:\:testRule\(\) has parameter \$(expectedError(.*?)|expectedErrors) with no value type specified in iterable type array#'

# useful to have IDE know the types
- identifier: phpstanApi.instanceofType

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

-
message: '#Generator expects value type array<string, mixed>, list<bool\|float\|int\|list<string>\|PHPStan\\TrinaryLogic\|string\|null> given#'
path: tests/ReturnTypeExtension/NodeGetAttributeTypeExtension/NodeGetAttributeTypeExtensionTest.php

- '#Although PHPStan\\Node\\InClassNode is covered by backward compatibility promise, this instanceof assumption might break because (.*?) not guaranteed to always stay the same#'
- '#PHPStan\\DependencyInjection\\NeonAdapter#'

Expand Down
6 changes: 3 additions & 3 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

return RectorConfig::configure()
->withPhpSets()
->withPreparedSets(deadCode: true, codeQuality: true, codingStyle: true, typeDeclarations: true, privatization: true, naming: true, earlyReturn: true, phpunitCodeQuality: true)
->withPreparedSets(deadCode: true, codeQuality: true, codingStyle: true, typeDeclarations: true, typeDeclarationDocblocks: true, privatization: true, naming: true, earlyReturn: true, phpunitCodeQuality: true)
->withPaths([__DIR__ . '/config', __DIR__ . '/src', __DIR__ . '/tests'])
->withRootFiles()
->withImportNames()
->withSkip([
'*/Source/*',
'*/Fixture/*',
StringClassNameToClassConstantRector::class => [
__DIR__ . '/src/Symfony/NodeAnalyzer/SymfonyControllerAnalyzer.php',
__DIR__ . '/src/Enum',
__DIR__ . '/src/Testing/PHPUnitTestAnalyser.php',
__DIR__ . '/tests/Naming/ClassToSuffixResolverTest.php',
__DIR__ . '/tests/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule/PhpUpgradeImplementsMinPhpVersionInterfaceRuleTest.php',
],
]);
2 changes: 2 additions & 0 deletions src/Rules/NoGlobalConstRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Node;
use PhpParser\Node\Stmt\Const_;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\IdentifierRuleError;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use Symplify\PHPStanRules\Enum\RuleIdentifier;
Expand All @@ -29,6 +30,7 @@ public function getNodeType(): string

/**
* @param Const_ $node
* @return IdentifierRuleError[]
*/
public function processNode(Node $node, Scope $scope): array
{
Expand Down
3 changes: 2 additions & 1 deletion src/Rules/Symfony/RequiredOnlyInAbstractRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PHPStan\Reflection\ClassReflection;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use Symplify\PHPStanRules\Enum\DoctrineClass;
use Symplify\PHPStanRules\Enum\RuleIdentifier\SymfonyRuleIdentifier;
use Symplify\PHPStanRules\NodeAnalyzer\SymfonyRequiredMethodAnalyzer;

Expand All @@ -34,7 +35,7 @@ final class RequiredOnlyInAbstractRule implements Rule
* @var string[]
*/
private const SKIPPED_PARENT_TYPES = [
'Doctrine\ODM\MongoDB\Repository\DocumentRepository',
DoctrineClass::DOCUMENT_REPOSITORY,
];

public function getNodeType(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/NodeAnalyzer/SymfonyControllerAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static function hasRouteAnnotationOrAttribute(ClassLike | ClassMethod $no
return false;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public function testAsserts(string $assertType, string $file, mixed ...$args): v
$this->assertFileAsserts($assertType, $file, ...$args);
}

/**
* @return Iterator<array<string, mixed>>
*/
public static function dataAsserts(): Iterator
{
yield from self::gatherAssertTypes(__DIR__ . '/data/get_parent_node.php.inc');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@

final class CheckRequiredInterfaceInContractNamespaceRuleTest extends RuleTestCase
{
/**
* @param array<int, array<string|int>> $expectedErrorsWithLines
*/
#[DataProvider('provideData')]
public function testRule(string $filePath, array $expectedErrorsWithLines): void
{
$this->analyse([$filePath], $expectedErrorsWithLines);
}

/**
* @return Iterator<array<array<int, mixed>, mixed>>
*/
public static function provideData(): Iterator
{
yield [__DIR__ . '/Fixture/Contract/SkipInterfaceInContract.php', []];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
final class ClassNameRespectsParentSuffixRuleTest extends RuleTestCase
{
/**
* @param mixed[] $expectedErrorMessagesWithLines
* @param array<int, array<string|int>> $expectedErrorMessagesWithLines
*/
#[DataProvider('provideData')]
public function testRule(string $filePath, array $expectedErrorMessagesWithLines): void
{
$this->analyse([$filePath], $expectedErrorMessagesWithLines);
}

/**
* @return Iterator<array<array<int, mixed>, mixed>>
*/
public static function provideData(): Iterator
{
yield [__DIR__ . '/Fixture/SkipCommand.php', []];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
final class ForbiddenArrayMethodCallRuleTest extends RuleTestCase
{
/**
* @param mixed[] $expectedErrorMessagesWithLines
* @param array<int, array<string|int>> $expectedErrorMessagesWithLines
*/
#[DataProvider('provideData')]
public function testRule(string $filePath, array $expectedErrorMessagesWithLines): void
{
$this->analyse([$filePath], $expectedErrorMessagesWithLines);
}

/**
* @return Iterator<array<array<int, mixed>, mixed>>
*/
public static function provideData(): Iterator
{
yield [__DIR__ . '/Fixture/SkipNormalArray.php', []];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
final class NoJustPropertyAssignRuleTest extends RuleTestCase
{
/**
* @param mixed[] $expectedErrorsWithLines
* @param array<int, array<string|int>> $expectedErrorsWithLines
*/
#[DataProvider('provideData')]
public function testRule(string $filePath, array $expectedErrorsWithLines): void
{
$this->analyse([$filePath], $expectedErrorsWithLines);
}

/**
* @return Iterator<array<array<int, mixed>, mixed>>
*/
public static function provideData(): Iterator
{
yield [__DIR__ . '/Fixture/ServiceAssign.php', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
final class ParamNameToTypeConventionRuleTest extends RuleTestCase
{
/**
* @param mixed[] $expectedErrorsWithLines
* @param array<int, array<string|int>> $expectedErrorsWithLines
*/
#[DataProvider('provideData')]
public function testRule(string $filePath, array $expectedErrorsWithLines): void
{
$this->analyse([$filePath], $expectedErrorsWithLines);
}

/**
* @return Iterator<array<array<int, mixed>, mixed>>
*/
public static function provideData(): Iterator
{
$errorMessage = sprintf(ParamNameToTypeConventionRule::ERROR_MESSAGE, 'userId', 'int');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ final class NoDoctrineListenerWithoutContractRuleTest extends RuleTestCase
{
/**
* @param string[] $filePaths
* @param array<int, array<string|int>> $expectedErrorsWithLines
*/
#[DataProvider('provideData')]
public function testRule(array $filePaths, array $expectedErrorsWithLines): void
{
$this->analyse($filePaths, $expectedErrorsWithLines);
}

/**
* @return Iterator<array<array<int, array<int, mixed>>, mixed>>
*/
public static function provideData(): Iterator
{
yield [[__DIR__ . '/Fixture/SkipContractAwareListener.php'], []];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
final class NoGetRepositoryOnServiceRepositoryEntityRuleTest extends RuleTestCase
{
/**
* @param mixed[] $expectedErrorMessagesWithLines
* @param array<int, array<string|int>> $expectedErrorMessagesWithLines
*/
#[DataProvider('provideData')]
public function testRule(string $filePath, array $expectedErrorMessagesWithLines): void
{
$this->analyse([$filePath], $expectedErrorMessagesWithLines);
}

/**
* @return Iterator<array<array<int, mixed>, mixed>>
*/
public static function provideData(): Iterator
{
$errorMessage = sprintf(NoGetRepositoryOnServiceRepositoryEntityRule::ERROR_MESSAGE, 'SomeEntity', SomeServiceRepository::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
final class NoGetRepositoryOutsideServiceRuleTest extends RuleTestCase
{
/**
* @param mixed[] $expectedErrorMessagesWithLines
* @param array<int, array<string|int>> $expectedErrorMessagesWithLines
*/
#[DataProvider('provideData')]
public function testRule(string $filePath, array $expectedErrorMessagesWithLines): void
{
$this->analyse([$filePath], $expectedErrorMessagesWithLines);
}

/**
* @return Iterator<array<array<int, mixed>, mixed>>
*/
public static function provideData(): Iterator
{
yield [__DIR__ . '/Fixture/NonRepositoryUsingEntityManager.php', [[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@

final class NoParentRepositoryRuleTest extends RuleTestCase
{
/**
* @param array<int, array<string|int>> $expectedErrorMessagesWithLines
*/
#[DataProvider('provideData')]
public function testRule(string $filePath, array $expectedErrorMessagesWithLines): void
{
$this->analyse([$filePath], $expectedErrorMessagesWithLines);
}

/**
* @return Iterator<(array<int, array<int, array<int, int>>>|array<int, array<int, array<int, string>>>|array<int, string>)>
*/
public static function provideData(): Iterator
{
yield [__DIR__ . '/Fixture/SomeRepository.php', [[NoParentRepositoryRule::ERROR_MESSAGE, 9]]];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@

final class NoRepositoryCallInDataFixtureRuleTest extends RuleTestCase
{
/**
* @param array<int, array<string|int>> $expectedErrorsWithLines
*/
#[DataProvider('provideData')]
public function testRule(string $filePath, array $expectedErrorsWithLines): void
{
$this->analyse([$filePath], $expectedErrorsWithLines);
}

/**
* @return Iterator<array<array<int, mixed>, mixed>>
*/
public static function provideData(): Iterator
{
yield [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@

final class RequireQueryBuilderOnRepositoryRuleTest extends RuleTestCase
{
/**
* @param array<int, array<string|int>> $expectedErrorsWithLines
*/
#[DataProvider('provideData')]
public function testRule(string $filePath, array $expectedErrorsWithLines): void
{
$this->analyse([$filePath], $expectedErrorsWithLines);
}

/**
* @return Iterator<array<array<int, mixed>, mixed>>
*/
public static function provideData(): Iterator
{
yield [__DIR__ . '/Fixture/SkipCreateQueryBuilderOnRepository.php', []];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@

final class RequireServiceRepositoryParentRuleTest extends RuleTestCase
{
/**
* @param array<int, array<string|int>> $expectedErrorsWithLines
*/
#[DataProvider('provideData')]
public function testRule(string $filePath, array $expectedErrorsWithLines): void
{
$this->analyse([$filePath], $expectedErrorsWithLines);
}

/**
* @return Iterator<array<array<int, mixed>, mixed>>
*/
public static function provideData(): Iterator
{
$errorMessage = sprintf(RequireServiceRepositoryParentRule::ERROR_MESSAGE, DoctrineClass::ODM_SERVICE_REPOSITORY, DoctrineClass::ORM_SERVICE_REPOSITORY, DoctrineClass::ODM_SERVICE_REPOSITORY_INTERFACE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
final class RequireAttributeNamespaceRuleTest extends RuleTestCase
{
/**
* @param mixed[] $expectedErrorMessagesWithLines
* @param array<int, array<string|int>> $expectedErrorMessagesWithLines
*/
#[DataProvider('provideData')]
public function testRule(string $filePath, array $expectedErrorMessagesWithLines): void
{
$this->analyse([$filePath], $expectedErrorMessagesWithLines);
}

/**
* @return Iterator<array<array<int, mixed>, mixed>>
*/
public static function provideData(): Iterator
{
yield [__DIR__ . '/Fixture/MisslocatedAttribute.php', [[RequireAttributeNamespaceRule::ERROR_MESSAGE, 7]]];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
final class RequireExceptionNamespaceRuleTest extends RuleTestCase
{
/**
* @param mixed[] $expectedErrorMessagesWithLines
* @param array<int, array<string|int>> $expectedErrorMessagesWithLines
*/
#[DataProvider('provideData')]
public function testRule(string $filePath, array $expectedErrorMessagesWithLines): void
{
$this->analyse([$filePath], $expectedErrorMessagesWithLines);
}

/**
* @return Iterator<array<array<int, mixed>, mixed>>
*/
public static function provideData(): Iterator
{
yield [__DIR__ . '/Fixture/MisslocatedException.php', [[RequireExceptionNamespaceRule::ERROR_MESSAGE, 9]]];
Expand Down
Loading