-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support PHPStan 2.0 #144
Support PHPStan 2.0 #144
Changes from 8 commits
f83aafa
2d8e399
9e92a5c
921cf28
5f72717
18efdf5
afebf42
e9c6e15
a6be6a1
d8fb908
c8b2513
78679b7
66b658e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,21 +7,17 @@ | |
"php": ">=8.1", | ||
"nette/utils": "^3.2.9 || ^4.0", | ||
"webmozart/assert": "^1.11", | ||
"phpstan/phpstan": "^1.11", | ||
"phpstan/phpstan": "^2.0", | ||
"symplify/rule-doc-generator-contracts": "^11.2" | ||
}, | ||
"require-dev": { | ||
"nikic/php-parser": "^4.19", | ||
"symplify/phpstan-extensions": "^11.4", | ||
"symplify/rule-doc-generator": "^12.2", | ||
"phpunit/phpunit": "^10.5", | ||
"symfony/framework-bundle": "6.1.*", | ||
"rector/rector": "^1.2.3", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you use "rector/rector": "dev-main as 1.2.10", to test rector for CI? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I applied it to f83aafa |
||
"symplify/easy-coding-standard": "^12.3", | ||
"phpstan/extension-installer": "^1.4", | ||
"tomasvotruba/class-leak": "^0.2", | ||
"tomasvotruba/unused-public": "^0.3.10", | ||
"tomasvotruba/type-coverage": "^0.3.1" | ||
"rector/rector": "dev-main as 1.2.10", | ||
"phpstan/extension-installer": "^1.4" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
|
@@ -36,10 +32,6 @@ | |
"stubs" | ||
], | ||
"files": [ | ||
"tests/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule/Fixture/SomePhpFeatureRector.php", | ||
"vendor/rector/rector/src/Contract/Rector/RectorInterface.php", | ||
"vendor/rector/rector/src/Contract/Rector/ConfigurableRectorInterface.php", | ||
"vendor/rector/rector/vendor/rector/rector-downgrade-php/src/Set/ValueObject/DowngradeSetList.php" | ||
] | ||
}, | ||
"extra": { | ||
|
@@ -58,7 +50,7 @@ | |
"scripts": { | ||
"check-cs": "vendor/bin/ecs check --ansi", | ||
"fix-cs": "vendor/bin/ecs check --fix --ansi", | ||
"phpstan": "vendor/bin/phpstan analyse --ansi --error-format symplify", | ||
"phpstan": "vendor/bin/phpstan analyse --ansi", | ||
"rector": "vendor/bin/rector process --dry-run --ansi", | ||
"docs": "vendor/bin/rule-doc-generator generate src --readme --ansi" | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,13 @@ | |
use PhpParser\Node\Stmt\ClassConst; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Rules\RuleErrorBuilder; | ||
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; | ||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
/** | ||
* @implements Rule<ClassConst> | ||
* @see \Symplify\PHPStanRules\Tests\Rules\AnnotateRegexClassConstWithRegexLinkRule\AnnotateRegexClassConstWithRegexLinkRuleTest | ||
*/ | ||
final class AnnotateRegexClassConstWithRegexLinkRule implements Rule, DocumentedRuleInterface | ||
|
@@ -31,17 +33,13 @@ final class AnnotateRegexClassConstWithRegexLinkRule implements Rule, Documented | |
*/ | ||
private const ALL_MODIFIERS = 'imsxeADSUXJu'; | ||
|
||
/** | ||
* @return class-string<Node> | ||
*/ | ||
public function getNodeType(): string | ||
{ | ||
return ClassConst::class; | ||
} | ||
|
||
/** | ||
* @param ClassConst $node | ||
* @return string[] | ||
*/ | ||
public function processNode(Node $node, Scope $scope): array | ||
{ | ||
|
@@ -69,7 +67,7 @@ public function processNode(Node $node, Scope $scope): array | |
return []; | ||
} | ||
|
||
return [self::ERROR_MESSAGE]; | ||
return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add identifier here as well |
||
} | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
use PhpParser\Node\Stmt\Interface_; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Rules\RuleErrorBuilder; | ||
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; | ||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
@@ -30,17 +31,13 @@ final class CheckRequiredInterfaceInContractNamespaceRule implements Rule, Docum | |
*/ | ||
private const A_CONTRACT_NAMESPACE_REGEX = '#\bContracts?\b#'; | ||
|
||
/** | ||
* @return class-string<Node> | ||
*/ | ||
public function getNodeType(): string | ||
{ | ||
return Interface_::class; | ||
} | ||
|
||
/** | ||
* @param Interface_ $node | ||
* @return string[] | ||
*/ | ||
public function processNode(Node $node, Scope $scope): array | ||
{ | ||
|
@@ -53,7 +50,7 @@ public function processNode(Node $node, Scope $scope): array | |
return []; | ||
} | ||
|
||
return [self::ERROR_MESSAGE]; | ||
return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add identifier here as well |
||
} | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
use PHPStan\Node\InClassNode; | ||
use PHPStan\Reflection\ClassReflection; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Rules\RuleError; | ||
use PHPStan\Rules\RuleErrorBuilder; | ||
use PHPUnit\Framework\TestCase; | ||
use Rector\Rector\AbstractRector; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
|
@@ -23,6 +25,7 @@ | |
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
/** | ||
* @implements Rule<InClassNode> | ||
* @see \Symplify\PHPStanRules\Tests\Rules\ClassNameRespectsParentSuffixRule\ClassNameRespectsParentSuffixRuleTest | ||
*/ | ||
final class ClassNameRespectsParentSuffixRule implements Rule, DocumentedRuleInterface, ConfigurableRuleInterface | ||
|
@@ -62,17 +65,13 @@ public function __construct( | |
$this->parentClasses = array_merge($parentClasses, self::DEFAULT_PARENT_CLASSES); | ||
} | ||
|
||
/** | ||
* @return class-string<Node> | ||
*/ | ||
public function getNodeType(): string | ||
{ | ||
return InClassNode::class; | ||
} | ||
|
||
/** | ||
* @param InClassNode $node | ||
* @return string[] | ||
*/ | ||
public function processNode(Node $node, Scope $scope): array | ||
{ | ||
|
@@ -117,7 +116,7 @@ class SomeCommand extends Command | |
} | ||
|
||
/** | ||
* @return array<int, string> | ||
* @return list<RuleError> | ||
*/ | ||
private function processClassNameAndShort(ClassReflection $classReflection): array | ||
{ | ||
|
@@ -132,7 +131,7 @@ private function processClassNameAndShort(ClassReflection $classReflection): arr | |
} | ||
|
||
$errorMessage = sprintf(self::ERROR_MESSAGE, $expectedSuffix); | ||
return [$errorMessage]; | ||
return [RuleErrorBuilder::message($errorMessage)->build()]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add identifier here as well |
||
} | ||
|
||
return []; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,13 +9,15 @@ | |
use PhpParser\Node\Expr\ArrayItem; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Rules\RuleErrorBuilder; | ||
use PHPStan\Type\Constant\ConstantStringType; | ||
use PHPStan\Type\TypeWithClassName; | ||
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; | ||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
/** | ||
* @implements Rule<Array_> | ||
* @see \Symplify\PHPStanRules\Tests\Rules\Complexity\ForbiddenArrayMethodCallRule\ForbiddenArrayMethodCallRuleTest | ||
*/ | ||
final class ForbiddenArrayMethodCallRule implements Rule, DocumentedRuleInterface | ||
|
@@ -25,17 +27,13 @@ final class ForbiddenArrayMethodCallRule implements Rule, DocumentedRuleInterfac | |
*/ | ||
public const ERROR_MESSAGE = 'Array method calls [$this, "method"] are not allowed. Use explicit method instead to help PhpStorm, PHPStan and Rector understand your code'; | ||
|
||
/** | ||
* @return class-string<Node> | ||
*/ | ||
public function getNodeType(): string | ||
{ | ||
return Array_::class; | ||
} | ||
|
||
/** | ||
* @param Array_ $node | ||
* @return string[] | ||
*/ | ||
public function processNode(Node $node, Scope $scope): array | ||
{ | ||
|
@@ -58,7 +56,7 @@ public function processNode(Node $node, Scope $scope): array | |
return []; | ||
} | ||
|
||
return [self::ERROR_MESSAGE]; | ||
return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add identifier here as well |
||
} | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,13 @@ | |
use PHPStan\Analyser\Scope; | ||
use PHPStan\Node\InClassNode; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Rules\RuleErrorBuilder; | ||
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; | ||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
/** | ||
* @implements Rule<InClassNode> | ||
* @see \Symplify\PHPStanRules\Tests\Rules\Domain\RequireAttributeNamespaceRule\RequireAttributeNamespaceRuleTest | ||
*/ | ||
final class RequireAttributeNamespaceRule implements Rule, DocumentedRuleInterface | ||
|
@@ -59,7 +61,6 @@ public function getNodeType(): string | |
|
||
/** | ||
* @param InClassNode $node | ||
* @return string[] | ||
*/ | ||
public function processNode(Node $node, Scope $scope): array | ||
{ | ||
|
@@ -74,6 +75,6 @@ public function processNode(Node $node, Scope $scope): array | |
return []; | ||
} | ||
|
||
return [self::ERROR_MESSAGE]; | ||
return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add identifier here as well |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,13 @@ | |
use PHPStan\Analyser\Scope; | ||
use PHPStan\Node\InClassNode; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Rules\RuleErrorBuilder; | ||
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; | ||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
/** | ||
* @implements Rule<InClassNode> | ||
* @see \Symplify\PHPStanRules\Tests\Rules\Domain\RequireExceptionNamespaceRule\RequireExceptionNamespaceRuleTest | ||
*/ | ||
final class RequireExceptionNamespaceRule implements Rule, DocumentedRuleInterface | ||
|
@@ -48,17 +50,13 @@ final class SomeException extends Exception | |
]); | ||
} | ||
|
||
/** | ||
* @return class-string<Node> | ||
*/ | ||
public function getNodeType(): string | ||
{ | ||
return InClassNode::class; | ||
} | ||
|
||
/** | ||
* @param InClassNode $node | ||
* @return string[] | ||
*/ | ||
public function processNode(Node $node, Scope $scope): array | ||
{ | ||
|
@@ -77,6 +75,6 @@ public function processNode(Node $node, Scope $scope): array | |
return []; | ||
} | ||
|
||
return [self::ERROR_MESSAGE]; | ||
return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add identifier here as well, basically, add unique identifier on message error |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you revert this, rector should run now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted a6be6a1 d8fb908