-
-
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 all 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 |
---|---|---|
|
@@ -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 @@ | |
*/ | ||
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 @@ | |
return []; | ||
} | ||
|
||
return [self::ERROR_MESSAGE]; | ||
return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; | ||
Check failure on line 70 in src/Rules/AnnotateRegexClassConstWithRegexLinkRule.php GitHub Actions / PHPStan
|
||
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 @@ | |
*/ | ||
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 @@ | |
return []; | ||
} | ||
|
||
return [self::ERROR_MESSAGE]; | ||
return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; | ||
Check failure on line 53 in src/Rules/CheckRequiredInterfaceInContractNamespaceRule.php GitHub Actions / PHPStan
|
||
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 @@ | |
$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 | ||
{ | ||
|
@@ -90,7 +89,7 @@ | |
return []; | ||
} | ||
|
||
return $this->processClassNameAndShort($classReflection); | ||
Check failure on line 92 in src/Rules/ClassNameRespectsParentSuffixRule.php GitHub Actions / PHPStan
|
||
} | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
|
@@ -117,7 +116,7 @@ | |
} | ||
|
||
/** | ||
* @return array<int, string> | ||
* @return list<RuleError> | ||
*/ | ||
private function processClassNameAndShort(ClassReflection $classReflection): array | ||
{ | ||
|
@@ -132,7 +131,7 @@ | |
} | ||
|
||
$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 @@ | |
*/ | ||
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 | ||
{ | ||
|
@@ -44,7 +42,7 @@ | |
} | ||
|
||
$typeWithClassName = $this->resolveFirstArrayItemClassType($node, $scope); | ||
if (! $typeWithClassName instanceof TypeWithClassName) { | ||
Check failure on line 45 in src/Rules/Complexity/ForbiddenArrayMethodCallRule.php GitHub Actions / PHPStan
|
||
return []; | ||
} | ||
|
||
|
@@ -58,7 +56,7 @@ | |
return []; | ||
} | ||
|
||
return [self::ERROR_MESSAGE]; | ||
return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; | ||
Check failure on line 59 in src/Rules/Complexity/ForbiddenArrayMethodCallRule.php GitHub Actions / PHPStan
|
||
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 | ||
|
@@ -86,7 +84,7 @@ | |
} | ||
|
||
$firstItemType = $scope->getType($firstItem->value); | ||
if (! $firstItemType instanceof TypeWithClassName) { | ||
Check failure on line 87 in src/Rules/Complexity/ForbiddenArrayMethodCallRule.php GitHub Actions / PHPStan
|
||
return null; | ||
} | ||
|
||
|
@@ -103,7 +101,7 @@ | |
$secondItemValue = $secondItem->value; | ||
|
||
$secondItemType = $scope->getType($secondItemValue); | ||
if (! $secondItemType instanceof ConstantStringType) { | ||
return null; | ||
} | ||
|
||
|
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 @@ | |
|
||
/** | ||
* @param InClassNode $node | ||
* @return string[] | ||
*/ | ||
public function processNode(Node $node, Scope $scope): array | ||
{ | ||
|
@@ -74,6 +75,6 @@ | |
return []; | ||
} | ||
|
||
return [self::ERROR_MESSAGE]; | ||
return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; | ||
Check failure on line 78 in src/Rules/Domain/RequireAttributeNamespaceRule.php GitHub Actions / PHPStan
|
||
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 @@ | |
]); | ||
} | ||
|
||
/** | ||
* @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 @@ | |
return []; | ||
} | ||
|
||
return [self::ERROR_MESSAGE]; | ||
return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; | ||
Check failure on line 78 in src/Rules/Domain/RequireExceptionNamespaceRule.php GitHub Actions / PHPStan
|
||
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 use
to test rector for CI?
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.
I applied it to f83aafa