diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml
index 06f4c047..21ef3418 100644
--- a/.github/workflows/code_analysis.yaml
+++ b/.github/workflows/code_analysis.yaml
@@ -44,7 +44,7 @@ jobs:
# see https://github.com/shivammathur/setup-php
- uses: shivammathur/setup-php@v2
with:
- php-version: 8.1
+ php-version: 8.2
coverage: none
# composer install cache - https://github.com/ramsey/composer-install
diff --git a/.github/workflows/downgraded_release.yaml b/.github/workflows/downgraded_release.yaml
index 5cc52efa..ea3871cb 100644
--- a/.github/workflows/downgraded_release.yaml
+++ b/.github/workflows/downgraded_release.yaml
@@ -20,7 +20,7 @@ jobs:
-
uses: "shivammathur/setup-php@v2"
with:
- php-version: 8.1
+ php-version: 8.2
coverage: none
# invoke patches
diff --git a/build/rector-downgrade-php-74.php b/build/rector-downgrade-php-74.php
index e8b7eef9..12c3a100 100644
--- a/build/rector-downgrade-php-74.php
+++ b/build/rector-downgrade-php-74.php
@@ -4,20 +4,11 @@
use Rector\Config\RectorConfig;
use Rector\Removing\Rector\Class_\RemoveInterfacesRector;
-use Rector\Set\ValueObject\DowngradeLevelSetList;
use Symplify\RuleDocGenerator\Contract\ConfigurableRuleInterface;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
-return static function (RectorConfig $rectorConfig): void {
- $rectorConfig->parallel();
-
- $rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_74]);
-
- $rectorConfig->ruleWithConfiguration(RemoveInterfacesRector::class, [
- DocumentedRuleInterface::class,
+return RectorConfig::configure()
+ ->withDowngradeSets(php74: true)
+ ->withConfiguredRule(RemoveInterfacesRector::class, [
ConfigurableRuleInterface::class,
- ]);
-
- $rectorConfig->skip(['*/Tests/*', '*/tests/*', __DIR__ . '/../../tests']);
-};
-
+ ])
+ ->withSkip(['*/Tests/*', '*/tests/*', __DIR__ . '/../../tests']);
diff --git a/composer.json b/composer.json
index 26edb434..5729dfb0 100644
--- a/composer.json
+++ b/composer.json
@@ -4,21 +4,20 @@
"description": "Set of Symplify rules for PHPStan",
"license": "MIT",
"require": {
- "php": ">=8.1",
- "nette/utils": "^3.2.9 || ^4.0",
+ "php": ">=8.2",
+ "nette/utils": "^4.0",
"webmozart/assert": "^1.11",
- "phpstan/phpstan": "^2.0",
- "symplify/rule-doc-generator-contracts": "^11.2"
+ "phpstan/phpstan": "^2.0"
},
"require-dev": {
- "nikic/php-parser": "^5.0",
- "symplify/rule-doc-generator": "^12.2",
- "phpunit/phpunit": "^10.5",
+ "nikic/php-parser": "^5.3",
+ "phpunit/phpunit": "^11.5",
"symfony/framework-bundle": "6.1.*",
- "symplify/easy-coding-standard": "^12.3",
+ "symplify/easy-coding-standard": "^12.5",
"tomasvotruba/class-leak": "^1.2",
"rector/rector": "^2.0",
- "phpstan/extension-installer": "^1.4"
+ "phpstan/extension-installer": "^1.4",
+ "symplify/phpstan-extensions": "^12.0"
},
"autoload": {
"psr-4": {
@@ -52,7 +51,6 @@
"check-cs": "vendor/bin/ecs check --ansi",
"fix-cs": "vendor/bin/ecs check --fix --ansi",
"phpstan": "vendor/bin/phpstan analyse --ansi",
- "rector": "vendor/bin/rector process --dry-run --ansi",
- "docs": "vendor/bin/rule-doc-generator generate src --readme --ansi"
+ "rector": "vendor/bin/rector process --dry-run --ansi"
}
}
diff --git a/config/rector-rules.neon b/config/rector-rules.neon
index dadc827f..798ac4a4 100644
--- a/config/rector-rules.neon
+++ b/config/rector-rules.neon
@@ -1,7 +1,6 @@
rules:
- Symplify\PHPStanRules\Rules\Rector\PhpUpgradeDowngradeRegisteredInSetRule
- Symplify\PHPStanRules\Rules\Rector\PhpUpgradeImplementsMinPhpVersionInterfaceRule
- - Symplify\PHPStanRules\Rules\Rector\RequireAssertConfigureValueObjectRectorRule
- Symplify\PHPStanRules\Rules\Rector\NoInstanceOfStaticReflectionRule
- Symplify\PHPStanRules\Rules\Rector\NoLeadingBackslashInNameRule
- Symplify\PHPStanRules\Rules\Rector\NoClassReflectionStaticReflectionRule
diff --git a/docs/rules_overview.md b/docs/rules_overview.md
deleted file mode 100644
index 1a4c5a98..00000000
--- a/docs/rules_overview.md
+++ /dev/null
@@ -1,1112 +0,0 @@
-# 30 Rules Overview
-
-## AnnotateRegexClassConstWithRegexLinkRule
-
-Add regex101.com link to that shows the regex in practise, so it will be easier to maintain in case of bug/extension in the future
-
-- class: [`Symplify\PHPStanRules\Rules\AnnotateRegexClassConstWithRegexLinkRule`](../src/Rules/AnnotateRegexClassConstWithRegexLinkRule.php)
-
-```php
-class SomeClass
-{
- private const COMPLICATED_REGEX = '#some_complicated_stu|ff#';
-}
-```
-
-:x:
-
-
-
-```php
-class SomeClass
-{
- /**
- * @see https://regex101.com/r/SZr0X5/12
- */
- private const COMPLICATED_REGEX = '#some_complicated_stu|ff#';
-}
-```
-
-:+1:
-
-
-
-## CheckClassNamespaceFollowPsr4Rule
-
-Class like namespace "%s" does not follow PSR-4 configuration in `composer.json`
-
-- class: [`Symplify\PHPStanRules\Rules\CheckClassNamespaceFollowPsr4Rule`](../src/Rules/CheckClassNamespaceFollowPsr4Rule.php)
-
-```php
-// defined "Foo\Bar" namespace in composer.json > autoload > psr-4
-namespace Foo;
-
-class Baz
-{
-}
-```
-
-:x:
-
-
-
-```php
-// defined "Foo\Bar" namespace in composer.json > autoload > psr-4
-namespace Foo\Bar;
-
-class Baz
-{
-}
-```
-
-:+1:
-
-
-
-## CheckRequiredInterfaceInContractNamespaceRule
-
-Interface must be located in "Contract" or "Contracts" namespace
-
-- class: [`Symplify\PHPStanRules\Rules\CheckRequiredInterfaceInContractNamespaceRule`](../src/Rules/CheckRequiredInterfaceInContractNamespaceRule.php)
-
-```php
-namespace App\Repository;
-
-interface ProductRepositoryInterface
-{
-}
-```
-
-:x:
-
-
-
-```php
-namespace App\Contract\Repository;
-
-interface ProductRepositoryInterface
-{
-}
-```
-
-:+1:
-
-
-
-## ClassNameRespectsParentSuffixRule
-
-Class should have suffix "%s" to respect parent type
-
-:wrench: **configure it!**
-
-- class: [`Symplify\PHPStanRules\Rules\ClassNameRespectsParentSuffixRule`](../src/Rules/ClassNameRespectsParentSuffixRule.php)
-
-```yaml
-services:
- -
- class: Symplify\PHPStanRules\Rules\ClassNameRespectsParentSuffixRule
- tags: [phpstan.rules.rule]
- arguments:
- parentClasses:
- - Symfony\Component\Console\Command\Command
-```
-
-↓
-
-```php
-class Some extends Command
-{
-}
-```
-
-:x:
-
-
-
-```php
-class SomeCommand extends Command
-{
-}
-```
-
-:+1:
-
-
-
-## ExplicitClassPrefixSuffixRule
-
-Interface have suffix of "Interface", trait have "Trait" suffix exclusively
-
-- class: [`Symplify\PHPStanRules\Rules\Explicit\ExplicitClassPrefixSuffixRule`](../src/Rules/Explicit/ExplicitClassPrefixSuffixRule.php)
-
-```php
-
-
-```php
-
-
-## ForbiddenArrayMethodCallRule
-
-Array method calls [$this, "method"] are not allowed. Use explicit method instead to help PhpStorm, PHPStan and Rector understand your code
-
-- class: [`Symplify\PHPStanRules\Rules\Complexity\ForbiddenArrayMethodCallRule`](../src/Rules/Complexity/ForbiddenArrayMethodCallRule.php)
-
-```php
-usort($items, [$this, "method"]);
-```
-
-:x:
-
-
-
-```php
-usort($items, function (array $apples) {
- return $this->method($apples);
-};
-```
-
-:+1:
-
-
-
-## ForbiddenExtendOfNonAbstractClassRule
-
-Only abstract classes can be extended
-
-- class: [`Symplify\PHPStanRules\Rules\ForbiddenExtendOfNonAbstractClassRule`](../src/Rules/ForbiddenExtendOfNonAbstractClassRule.php)
-
-```php
-final class SomeClass extends ParentClass
-{
-}
-
-class ParentClass
-{
-}
-```
-
-:x:
-
-
-
-```php
-final class SomeClass extends ParentClass
-{
-}
-
-abstract class ParentClass
-{
-}
-```
-
-:+1:
-
-
-
-## ForbiddenFuncCallRule
-
-Function `"%s()"` cannot be used/left in the code
-
-:wrench: **configure it!**
-
-- class: [`Symplify\PHPStanRules\Rules\ForbiddenFuncCallRule`](../src/Rules/ForbiddenFuncCallRule.php)
-
-```yaml
-services:
- -
- class: Symplify\PHPStanRules\Rules\ForbiddenFuncCallRule
- tags: [phpstan.rules.rule]
- arguments:
- forbiddenFunctions:
- - eval
-```
-
-↓
-
-```php
-echo eval('...');
-```
-
-:x:
-
-
-
-```php
-echo '...';
-```
-
-:+1:
-
-
-
-```yaml
-services:
- -
- class: Symplify\PHPStanRules\Rules\ForbiddenFuncCallRule
- tags: [phpstan.rules.rule]
- arguments:
- forbiddenFunctions:
- dump: 'seems you missed some debugging function'
-```
-
-↓
-
-```php
-dump($value);
-echo $value;
-```
-
-:x:
-
-
-
-```php
-echo $value;
-```
-
-:+1:
-
-
-
-## ForbiddenMultipleClassLikeInOneFileRule
-
-Multiple class/interface/trait is not allowed in single file
-
-- class: [`Symplify\PHPStanRules\Rules\ForbiddenMultipleClassLikeInOneFileRule`](../src/Rules/ForbiddenMultipleClassLikeInOneFileRule.php)
-
-```php
-// src/SomeClass.php
-class SomeClass
-{
-}
-
-interface SomeInterface
-{
-}
-```
-
-:x:
-
-
-
-```php
-// src/SomeClass.php
-class SomeClass
-{
-}
-
-// src/SomeInterface.php
-interface SomeInterface
-{
-}
-```
-
-:+1:
-
-
-
-## ForbiddenNodeRule
-
-"%s" is forbidden to use
-
-:wrench: **configure it!**
-
-- class: [`Symplify\PHPStanRules\Rules\ForbiddenNodeRule`](../src/Rules/ForbiddenNodeRule.php)
-
-```yaml
-services:
- -
- class: Symplify\PHPStanRules\Rules\ForbiddenNodeRule
- tags: [phpstan.rules.rule]
- arguments:
- forbiddenNodes:
- - PhpParser\Node\Expr\ErrorSuppress
-```
-
-↓
-
-```php
-return @strlen('...');
-```
-
-:x:
-
-
-
-```php
-return strlen('...');
-```
-
-:+1:
-
-
-
-## ForbiddenStaticClassConstFetchRule
-
-Avoid static access of constants, as they can change value. Use interface and contract method instead
-
-- class: [`Symplify\PHPStanRules\Rules\ForbiddenStaticClassConstFetchRule`](../src/Rules/ForbiddenStaticClassConstFetchRule.php)
-
-```php
-class SomeClass
-{
- public function run()
- {
- return static::SOME_CONST;
- }
-}
-```
-
-:x:
-
-
-
-```php
-class SomeClass
-{
- public function run()
- {
- return self::SOME_CONST;
- }
-}
-```
-
-:+1:
-
-
-
-## NoDynamicNameRule
-
-Use explicit names over dynamic ones
-
-- class: [`Symplify\PHPStanRules\Rules\NoDynamicNameRule`](../src/Rules/NoDynamicNameRule.php)
-
-```php
-class SomeClass
-{
- public function old(): bool
- {
- return $this->${variable};
- }
-}
-```
-
-:x:
-
-
-
-```php
-class SomeClass
-{
- public function old(): bool
- {
- return $this->specificMethodName();
- }
-}
-```
-
-:+1:
-
-
-
-## NoEntityOutsideEntityNamespaceRule
-
-Class with #[Entity] attribute must be located in "Entity" namespace to be loaded by Doctrine
-
-- class: [`Symplify\PHPStanRules\Rules\NoEntityOutsideEntityNamespaceRule`](../src/Rules/NoEntityOutsideEntityNamespaceRule.php)
-
-```php
-namespace App\ValueObject;
-
-use Doctrine\ORM\Mapping as ORM;
-
-#[ORM\Entity]
-class Product
-{
-}
-```
-
-:x:
-
-
-
-```php
-namespace App\Entity;
-
-use Doctrine\ORM\Mapping as ORM;
-
-#[ORM\Entity]
-class Product
-{
-}
-```
-
-:+1:
-
-
-
-## NoGlobalConstRule
-
-Global constants are forbidden. Use enum-like class list instead
-
-- class: [`Symplify\PHPStanRules\Rules\NoGlobalConstRule`](../src/Rules/NoGlobalConstRule.php)
-
-```php
-const SOME_GLOBAL_CONST = 'value';
-```
-
-:x:
-
-
-
-```php
-class SomeClass
-{
- public function run()
- {
- return self::SOME_CONST;
- }
-}
-```
-
-:+1:
-
-
-
-## NoInlineStringRegexRule
-
-Use local named constant instead of inline string for regex to explain meaning by constant name
-
-- class: [`Symplify\PHPStanRules\Rules\NoInlineStringRegexRule`](../src/Rules/NoInlineStringRegexRule.php)
-
-```php
-class SomeClass
-{
- public function run($value)
- {
- return preg_match('#some_stu|ff#', $value);
- }
-}
-```
-
-:x:
-
-
-
-```php
-class SomeClass
-{
- /**
- * @var string
- */
- public const SOME_STUFF_REGEX = '#some_stu|ff#';
-
- public function run($value)
- {
- return preg_match(self::SOME_STUFF_REGEX, $value);
- }
-}
-```
-
-:+1:
-
-
-
-## NoReferenceRule
-
-Use explicit return value over magic &reference
-
-- class: [`Symplify\PHPStanRules\Rules\NoReferenceRule`](../src/Rules/NoReferenceRule.php)
-
-```php
-class SomeClass
-{
- public function run(&$value)
- {
- }
-}
-```
-
-:x:
-
-
-
-```php
-class SomeClass
-{
- public function run($value)
- {
- return $value;
- }
-}
-```
-
-:+1:
-
-
-
-## NoReturnArrayVariableListRule
-
-Use value object over return of values
-
-- class: [`Symplify\PHPStanRules\Rules\NoReturnArrayVariableListRule`](../src/Rules/NoReturnArrayVariableListRule.php)
-
-```php
-class ReturnVariables
-{
- public function run($value, $value2): array
- {
- return [$value, $value2];
- }
-}
-```
-
-:x:
-
-
-
-```php
-final class ReturnVariables
-{
- public function run($value, $value2): ValueObject
- {
- return new ValueObject($value, $value2);
- }
-}
-```
-
-:+1:
-
-
-
-## NoReturnSetterMethodRule
-
-Setter method cannot return anything, only set value
-
-- class: [`Symplify\PHPStanRules\Rules\NoReturnSetterMethodRule`](../src/Rules/NoReturnSetterMethodRule.php)
-
-```php
-final class SomeClass
-{
- private $name;
-
- public function setName(string $name): int
- {
- return 1000;
- }
-}
-```
-
-:x:
-
-
-
-```php
-final class SomeClass
-{
- private $name;
-
- public function setName(string $name): void
- {
- $this->name = $name;
- }
-}
-```
-
-:+1:
-
-
-
-## NoSingleInterfaceImplementerRule
-
-Interface "%s" has only single implementer. Consider using the class directly as there is no point in using the interface.
-
-- class: [`Symplify\PHPStanRules\Rules\NoSingleInterfaceImplementerRule`](../src/Rules/NoSingleInterfaceImplementerRule.php)
-
-```php
-class SomeClass implements SomeInterface
-{
-}
-
-interface SomeInterface
-{
-}
-```
-
-:x:
-
-
-
-```php
-class SomeClass implements SomeInterface
-{
-}
-
-class AnotherClass implements SomeInterface
-{
-}
-
-interface SomeInterface
-{
-}
-```
-
-:+1:
-
-
-
-## NoTestMocksRule
-
-Mocking "%s" class is forbidden. Use direct/anonymous class instead for better static analysis
-
-- class: [`Symplify\PHPStanRules\Rules\PHPUnit\NoTestMocksRule`](../src/Rules/PHPUnit/NoTestMocksRule.php)
-
-```php
-use PHPUnit\Framework\TestCase;
-
-final class SkipApiMock extends TestCase
-{
- public function test()
- {
- $someTypeMock = $this->createMock(SomeType::class);
- }
-}
-```
-
-:x:
-
-
-
-```php
-use PHPUnit\Framework\TestCase;
-
-final class SkipApiMock extends TestCase
-{
- public function test()
- {
- $someTypeMock = new class() implements SomeType {};
- }
-}
-```
-
-:+1:
-
-
-
-## PreferredClassRule
-
-Instead of "%s" class/interface use "%s"
-
-:wrench: **configure it!**
-
-- class: [`Symplify\PHPStanRules\Rules\PreferredClassRule`](../src/Rules/PreferredClassRule.php)
-
-```yaml
-services:
- -
- class: Symplify\PHPStanRules\Rules\PreferredClassRule
- tags: [phpstan.rules.rule]
- arguments:
- oldToPreferredClasses:
- SplFileInfo: CustomFileInfo
-```
-
-↓
-
-```php
-class SomeClass
-{
- public function run()
- {
- return new SplFileInfo('...');
- }
-}
-```
-
-:x:
-
-
-
-```php
-class SomeClass
-{
- public function run()
- {
- return new CustomFileInfo('...');
- }
-}
-```
-
-:+1:
-
-
-
-## PreventParentMethodVisibilityOverrideRule
-
-Change `"%s()"` method visibility to "%s" to respect parent method visibility.
-
-- class: [`Symplify\PHPStanRules\Rules\PreventParentMethodVisibilityOverrideRule`](../src/Rules/PreventParentMethodVisibilityOverrideRule.php)
-
-```php
-class SomeParentClass
-{
- public function run()
- {
- }
-}
-
-class SomeClass extends SomeParentClass
-{
- protected function run()
- {
- }
-}
-```
-
-:x:
-
-
-
-```php
-class SomeParentClass
-{
- public function run()
- {
- }
-}
-
-class SomeClass extends SomeParentClass
-{
- public function run()
- {
- }
-}
-```
-
-:+1:
-
-
-
-## RegexSuffixInRegexConstantRule
-
-Name your constant with "_REGEX" suffix, instead of "%s"
-
-- class: [`Symplify\PHPStanRules\Rules\RegexSuffixInRegexConstantRule`](../src/Rules/RegexSuffixInRegexConstantRule.php)
-
-```php
-class SomeClass
-{
- public const SOME_NAME = '#some\s+name#';
-
- public function run($value)
- {
- $somePath = preg_match(self::SOME_NAME, $value);
- }
-}
-```
-
-:x:
-
-
-
-```php
-class SomeClass
-{
- public const SOME_NAME_REGEX = '#some\s+name#';
-
- public function run($value)
- {
- $somePath = preg_match(self::SOME_NAME_REGEX, $value);
- }
-}
-```
-
-:+1:
-
-
-
-## RequireAttributeNameRule
-
-Attribute must have all names explicitly defined
-
-- class: [`Symplify\PHPStanRules\Rules\RequireAttributeNameRule`](../src/Rules/RequireAttributeNameRule.php)
-
-```php
-use Symfony\Component\Routing\Annotation\Route;
-
-class SomeController
-{
- #[Route("/path")]
- public function someAction()
- {
- }
-}
-```
-
-:x:
-
-
-
-```php
-use Symfony\Component\Routing\Annotation\Route;
-
-class SomeController
-{
- #[Route(path: "/path")]
- public function someAction()
- {
- }
-}
-```
-
-:+1:
-
-
-
-## RequireAttributeNamespaceRule
-
-Attribute must be located in "Attribute" namespace
-
-- class: [`Symplify\PHPStanRules\Rules\Domain\RequireAttributeNamespaceRule`](../src/Rules/Domain/RequireAttributeNamespaceRule.php)
-
-```php
-// app/Entity/SomeAttribute.php
-namespace App\Controller;
-
-#[\Attribute]
-final class SomeAttribute
-{
-}
-```
-
-:x:
-
-
-
-```php
-// app/Attribute/SomeAttribute.php
-namespace App\Attribute;
-
-#[\Attribute]
-final class SomeAttribute
-{
-}
-```
-
-:+1:
-
-
-
-## RequireExceptionNamespaceRule
-
-`Exception` must be located in "Exception" namespace
-
-- class: [`Symplify\PHPStanRules\Rules\Domain\RequireExceptionNamespaceRule`](../src/Rules/Domain/RequireExceptionNamespaceRule.php)
-
-```php
-// app/Controller/SomeException.php
-namespace App\Controller;
-
-final class SomeException extends Exception
-{
-
-}
-```
-
-:x:
-
-
-
-```php
-// app/Exception/SomeException.php
-namespace App\Exception;
-
-final class SomeException extends Exception
-{
-}
-```
-
-:+1:
-
-
-
-## RequireInvokableControllerRule
-
-Use invokable controller with `__invoke()` method instead of named action method
-
-- class: [`Symplify\PHPStanRules\Symfony\Rules\RequireInvokableControllerRule`](../src/Symfony/Rules/RequireInvokableControllerRule.php)
-
-```php
-use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
-use Symfony\Component\Routing\Annotation\Route;
-
-final class SomeController extends AbstractController
-{
- #[Route()]
- public function someMethod()
- {
- }
-}
-```
-
-:x:
-
-
-
-```php
-use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
-use Symfony\Component\Routing\Annotation\Route;
-
-final class SomeController extends AbstractController
-{
- #[Route()]
- public function __invoke()
- {
- }
-}
-```
-
-:+1:
-
-
-
-## RequireUniqueEnumConstantRule
-
-Enum constants "%s" are duplicated. Make them unique instead
-
-- class: [`Symplify\PHPStanRules\Rules\Enum\RequireUniqueEnumConstantRule`](../src/Rules/Enum/RequireUniqueEnumConstantRule.php)
-
-```php
-use MyCLabs\Enum\Enum;
-
-class SomeClass extends Enum
-{
- private const YES = 'yes';
-
- private const NO = 'yes';
-}
-```
-
-:x:
-
-
-
-```php
-use MyCLabs\Enum\Enum;
-
-class SomeClass extends Enum
-{
- private const YES = 'yes';
-
- private const NO = 'no';
-}
-```
-
-:+1:
-
-
-
-## SeeAnnotationToTestRule
-
-Class "%s" is missing `@see` annotation with test case class reference
-
-:wrench: **configure it!**
-
-- class: [`Symplify\PHPStanRules\Rules\SeeAnnotationToTestRule`](../src/Rules/SeeAnnotationToTestRule.php)
-
-```yaml
-services:
- -
- class: Symplify\PHPStanRules\Rules\SeeAnnotationToTestRule
- tags: [phpstan.rules.rule]
- arguments:
- requiredSeeTypes:
- - Rule
-```
-
-↓
-
-```php
-class SomeClass extends Rule
-{
-}
-```
-
-:x:
-
-
-
-```php
-/**
- * @see SomeClassTest
- */
-class SomeClass extends Rule
-{
-}
-```
-
-:+1:
-
-
-
-## UppercaseConstantRule
-
-Constant "%s" must be uppercase
-
-- class: [`Symplify\PHPStanRules\Rules\UppercaseConstantRule`](../src/Rules/UppercaseConstantRule.php)
-
-```php
-final class SomeClass
-{
- public const some = 'value';
-}
-```
-
-:x:
-
-
-
-```php
-final class SomeClass
-{
- public const SOME = 'value';
-}
-```
-
-:+1:
-
-
diff --git a/phpstan.neon b/phpstan.neon
index c6011fab..a6a39ddb 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -4,6 +4,7 @@ includes:
parameters:
treatPhpDocTypesAsCertain: false
+ errorFormat: symplify
level: 8
@@ -50,27 +51,22 @@ parameters:
# overly detailed
- '#Class Symplify\\PHPStanRules\\Collector\\(.*?) implements generic interface PHPStan\\Collectors\\Collector but does not specify its types\: TNodeType, TValue#'
- -
- identifier: argument.type
-
- -
- identifier: phpstanApi.instanceofType
-
- -
- identifier: return.type
+ # useful to have IDE know the types
+ - identifier: phpstanApi.instanceofType
-
identifier: class.notFound
path: tests/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule/PhpUpgradeImplementsMinPhpVersionInterfaceRuleTest.php
+ # overly detailed
-
- identifier: phpstanApi.runtimeReflection
-
- -
- identifier: phpstanApi.instanceofAssumption
+ message: '#Parameter \#2 \$expectedErrors of method PHPStan\\Testing\\RuleTestCase<(.*?)>::analyse\(\) expects list, (.*?) given#'
+ path: tests
+ # fast effective check
-
- identifier: generics.wrongParent
+ message: '#Function is_a\(\) is a runtime reflection concept that might not work in PHPStan because it uses fully static reflection engine#'
+ path: src/Rules/SeeAnnotationToTestRule.php
- -
- identifier: method.childReturnType
+ # handle next
+ - '#Method Symplify\\PHPStanRules\\Rules\\AbstractSymplifyRule\:\:processNode\(\) should return list but returns array#'
diff --git a/src/Enum/RuleIdentifier.php b/src/Enum/RuleIdentifier.php
new file mode 100644
index 00000000..de72e835
--- /dev/null
+++ b/src/Enum/RuleIdentifier.php
@@ -0,0 +1,173 @@
+
*/
-abstract class AbstractSymplifyRule implements Rule, ManyNodeRuleInterface, DocumentedRuleInterface
+abstract class AbstractSymplifyRule implements Rule, ManyNodeRuleInterface
{
/**
* @return class-string
diff --git a/src/Rules/AnnotateRegexClassConstWithRegexLinkRule.php b/src/Rules/AnnotateRegexClassConstWithRegexLinkRule.php
index e624a06e..bb9ce2fd 100644
--- a/src/Rules/AnnotateRegexClassConstWithRegexLinkRule.php
+++ b/src/Rules/AnnotateRegexClassConstWithRegexLinkRule.php
@@ -12,7 +12,7 @@
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -20,7 +20,7 @@
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\AnnotateRegexClassConstWithRegexLinkRule\AnnotateRegexClassConstWithRegexLinkRuleTest
*/
-final class AnnotateRegexClassConstWithRegexLinkRule implements Rule, DocumentedRuleInterface
+final class AnnotateRegexClassConstWithRegexLinkRule implements Rule
{
/**
* @var string
@@ -67,29 +67,9 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
- return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
- }
-
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [new CodeSample(
- <<<'CODE_SAMPLE'
-class SomeClass
-{
- private const COMPLICATED_REGEX = '#some_complicated_stu|ff#';
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-class SomeClass
-{
- /**
- * @see https://regex101.com/r/SZr0X5/12
- */
- private const COMPLICATED_REGEX = '#some_complicated_stu|ff#';
-}
-CODE_SAMPLE
- )]);
+ return [RuleErrorBuilder::message(self::ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::REGEX_ANNOTATE_CLASS_CONST)
+ ->build()];
}
private function isNonSingleCharRegexPattern(string $value): bool
diff --git a/src/Rules/CheckClassNamespaceFollowPsr4Rule.php b/src/Rules/CheckClassNamespaceFollowPsr4Rule.php
index d4c40840..e1073358 100644
--- a/src/Rules/CheckClassNamespaceFollowPsr4Rule.php
+++ b/src/Rules/CheckClassNamespaceFollowPsr4Rule.php
@@ -13,15 +13,12 @@
use Symplify\PHPStanRules\Composer\ClassNamespaceMatcher;
use Symplify\PHPStanRules\Composer\ComposerAutoloadResolver;
use Symplify\PHPStanRules\Composer\Psr4PathValidator;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\CheckClassNamespaceFollowPsr4Rule\CheckClassNamespaceFollowPsr4RuleTest
*/
-final class CheckClassNamespaceFollowPsr4Rule implements Rule, DocumentedRuleInterface
+final class CheckClassNamespaceFollowPsr4Rule implements Rule
{
/**
* @var string
@@ -91,31 +88,6 @@ public function processNode(Node $node, Scope $scope): array
return [RuleErrorBuilder::message($errorMessage)->identifier('check.classnamespacepsr4')->build()];
}
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-// defined "Foo\Bar" namespace in composer.json > autoload > psr-4
-namespace Foo;
-
-class Baz
-{
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-// defined "Foo\Bar" namespace in composer.json > autoload > psr-4
-namespace Foo\Bar;
-
-class Baz
-{
-}
-CODE_SAMPLE
- ),
- ]);
- }
-
private function resolveNamespaceBeforeClass(ClassLike $classLike, Scope $scope): ?string
{
if (! $classLike->name instanceof Identifier) {
diff --git a/src/Rules/CheckRequiredInterfaceInContractNamespaceRule.php b/src/Rules/CheckRequiredInterfaceInContractNamespaceRule.php
index 2658a039..72536530 100644
--- a/src/Rules/CheckRequiredInterfaceInContractNamespaceRule.php
+++ b/src/Rules/CheckRequiredInterfaceInContractNamespaceRule.php
@@ -10,15 +10,13 @@
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;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
/**
* @see \Symplify\PHPStanRules\Tests\Rules\CheckRequiredInterfaceInContractNamespaceRule\CheckRequiredInterfaceInContractNamespaceRuleTest
* @implements Rule
*/
-final class CheckRequiredInterfaceInContractNamespaceRule implements Rule, DocumentedRuleInterface
+final class CheckRequiredInterfaceInContractNamespaceRule implements Rule
{
/**
* @var string
@@ -50,29 +48,8 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
- return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
- }
-
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-namespace App\Repository;
-
-interface ProductRepositoryInterface
-{
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-namespace App\Contract\Repository;
-
-interface ProductRepositoryInterface
-{
-}
-CODE_SAMPLE
- ),
- ]);
+ return [RuleErrorBuilder::message(self::ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::REQUIRED_INTERFACE_CONTRACT_NAMESPACE)
+ ->build()];
}
}
diff --git a/src/Rules/ClassNameRespectsParentSuffixRule.php b/src/Rules/ClassNameRespectsParentSuffixRule.php
index 3e71032d..72d31392 100644
--- a/src/Rules/ClassNameRespectsParentSuffixRule.php
+++ b/src/Rules/ClassNameRespectsParentSuffixRule.php
@@ -11,6 +11,7 @@
use PHPStan\Analyser\Scope;
use PHPStan\Node\InClassNode;
use PHPStan\Reflection\ClassReflection;
+use PHPStan\Rules\IdentifierRuleError;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
@@ -18,17 +19,14 @@
use Rector\Rector\AbstractRector;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
use Symplify\PHPStanRules\Naming\ClassToSuffixResolver;
-use Symplify\RuleDocGenerator\Contract\ConfigurableRuleInterface;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\ClassNameRespectsParentSuffixRule\ClassNameRespectsParentSuffixRuleTest
*/
-final class ClassNameRespectsParentSuffixRule implements Rule, DocumentedRuleInterface, ConfigurableRuleInterface
+final class ClassNameRespectsParentSuffixRule implements Rule
{
/**
* @var string
@@ -92,31 +90,8 @@ public function processNode(Node $node, Scope $scope): array
return $this->processClassNameAndShort($classReflection);
}
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new ConfiguredCodeSample(
- <<<'CODE_SAMPLE'
-class Some extends Command
-{
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-class SomeCommand extends Command
-{
-}
-CODE_SAMPLE
- ,
- [
- 'parentClasses' => ['Symfony\Component\Console\Command\Command'],
- ]
- ),
- ]);
- }
-
/**
- * @return list
+ * @return list
*/
private function processClassNameAndShort(ClassReflection $classReflection): array
{
@@ -131,7 +106,9 @@ private function processClassNameAndShort(ClassReflection $classReflection): arr
}
$errorMessage = sprintf(self::ERROR_MESSAGE, $expectedSuffix);
- return [RuleErrorBuilder::message($errorMessage)->build()];
+ return [RuleErrorBuilder::message($errorMessage)
+ ->identifier(RuleIdentifier::CLASS_NAME_RESPECTS_PARENT_SUFFIX)
+ ->build()];
}
return [];
diff --git a/src/Rules/Complexity/ForbiddenArrayMethodCallRule.php b/src/Rules/Complexity/ForbiddenArrayMethodCallRule.php
index 63d6877a..68c42fe9 100644
--- a/src/Rules/Complexity/ForbiddenArrayMethodCallRule.php
+++ b/src/Rules/Complexity/ForbiddenArrayMethodCallRule.php
@@ -12,15 +12,13 @@
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;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
/**
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\Complexity\ForbiddenArrayMethodCallRule\ForbiddenArrayMethodCallRuleTest
*/
-final class ForbiddenArrayMethodCallRule implements Rule, DocumentedRuleInterface
+final class ForbiddenArrayMethodCallRule implements Rule
{
/**
* @var string
@@ -56,24 +54,9 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
- return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
- }
-
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-usort($items, [$this, "method"]);
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-usort($items, function (array $apples) {
- return $this->method($apples);
-};
-CODE_SAMPLE
- ),
- ]);
+ return [RuleErrorBuilder::message(self::ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::FORBIDDEN_ARRAY_METHOD_CALL)
+ ->build()];
}
private function resolveFirstArrayItemClassType(Array_ $array, Scope $scope): ?TypeWithClassName
diff --git a/src/Rules/Domain/RequireAttributeNamespaceRule.php b/src/Rules/Domain/RequireAttributeNamespaceRule.php
index cb2fe1df..5a2646e0 100644
--- a/src/Rules/Domain/RequireAttributeNamespaceRule.php
+++ b/src/Rules/Domain/RequireAttributeNamespaceRule.php
@@ -9,48 +9,19 @@
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;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
/**
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\Domain\RequireAttributeNamespaceRule\RequireAttributeNamespaceRuleTest
*/
-final class RequireAttributeNamespaceRule implements Rule, DocumentedRuleInterface
+final class RequireAttributeNamespaceRule implements Rule
{
/**
* @var string
*/
public const ERROR_MESSAGE = 'Attribute must be located in "Attribute" namespace';
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-// app/Entity/SomeAttribute.php
-namespace App\Controller;
-
-#[\Attribute]
-final class SomeAttribute
-{
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-// app/Attribute/SomeAttribute.php
-namespace App\Attribute;
-
-#[\Attribute]
-final class SomeAttribute
-{
-}
-CODE_SAMPLE
- ),
- ]);
- }
-
/**
* @return class-string
*/
@@ -75,6 +46,8 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
- return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
+ return [RuleErrorBuilder::message(self::ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::REQUIRE_ATTRIBUTE_NAMESPACE)
+ ->build()];
}
}
diff --git a/src/Rules/Domain/RequireExceptionNamespaceRule.php b/src/Rules/Domain/RequireExceptionNamespaceRule.php
index d4f8d304..a5cea4f8 100644
--- a/src/Rules/Domain/RequireExceptionNamespaceRule.php
+++ b/src/Rules/Domain/RequireExceptionNamespaceRule.php
@@ -8,48 +8,21 @@
use PHPStan\Analyser\Scope;
use PHPStan\Node\InClassNode;
use PHPStan\Rules\Rule;
+use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
/**
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\Domain\RequireExceptionNamespaceRule\RequireExceptionNamespaceRuleTest
*/
-final class RequireExceptionNamespaceRule implements Rule, DocumentedRuleInterface
+final class RequireExceptionNamespaceRule implements Rule
{
/**
* @var string
*/
public const ERROR_MESSAGE = 'Exception must be located in "Exception" namespace';
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-// app/Controller/SomeException.php
-namespace App\Controller;
-
-final class SomeException extends Exception
-{
-
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-// app/Exception/SomeException.php
-namespace App\Exception;
-
-final class SomeException extends Exception
-{
-}
-CODE_SAMPLE
- ),
- ]);
- }
-
public function getNodeType(): string
{
return InClassNode::class;
@@ -75,6 +48,8 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
- return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
+ return [RuleErrorBuilder::message(self::ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::REQUIRE_EXCEPTION_NAMESPACE)
+ ->build()];
}
}
diff --git a/src/Rules/Enum/RequireUniqueEnumConstantRule.php b/src/Rules/Enum/RequireUniqueEnumConstantRule.php
index 9568f85c..74c88892 100644
--- a/src/Rules/Enum/RequireUniqueEnumConstantRule.php
+++ b/src/Rules/Enum/RequireUniqueEnumConstantRule.php
@@ -11,16 +11,14 @@
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\Constant\ConstantStringType;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
use Symplify\PHPStanRules\NodeAnalyzer\EnumAnalyzer;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\Enum\RequireUniqueEnumConstantRule\RequireUniqueEnumConstantRuleTest
*/
-final class RequireUniqueEnumConstantRule implements Rule, DocumentedRuleInterface
+final class RequireUniqueEnumConstantRule implements Rule
{
/**
* @var string
@@ -58,36 +56,12 @@ public function processNode(Node $node, Scope $scope): array
}
$errorMessage = sprintf(self::ERROR_MESSAGE, implode('", "', $duplicatedConstantValues));
- return [RuleErrorBuilder::message($errorMessage)->build()];
- }
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-use MyCLabs\Enum\Enum;
+ $identifierRuleError = RuleErrorBuilder::message($errorMessage)
+ ->identifier(RuleIdentifier::REQUIRE_UNIQUE_ENUM_CONSTANT)
+ ->build();
-class SomeClass extends Enum
-{
- private const YES = 'yes';
-
- private const NO = 'yes';
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-use MyCLabs\Enum\Enum;
-
-class SomeClass extends Enum
-{
- private const YES = 'yes';
-
- private const NO = 'no';
-}
-CODE_SAMPLE
- ),
- ]);
+ return [$identifierRuleError];
}
/**
diff --git a/src/Rules/Explicit/ExplicitClassPrefixSuffixRule.php b/src/Rules/Explicit/ExplicitClassPrefixSuffixRule.php
index 2c3f0154..8cba8675 100644
--- a/src/Rules/Explicit/ExplicitClassPrefixSuffixRule.php
+++ b/src/Rules/Explicit/ExplicitClassPrefixSuffixRule.php
@@ -11,19 +11,18 @@
use PhpParser\Node\Stmt\Interface_;
use PhpParser\Node\Stmt\Trait_;
use PHPStan\Analyser\Scope;
+use PHPStan\Rules\IdentifierRuleError;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
use function str_ends_with;
/**
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\Explicit\ExplicitClassPrefixSuffixRule\ExplicitClassPrefixSuffixRuleTest
*/
-final class ExplicitClassPrefixSuffixRule implements Rule, DocumentedRuleInterface
+final class ExplicitClassPrefixSuffixRule implements Rule
{
/**
* @api
@@ -48,45 +47,6 @@ public function getNodeType(): string
return ClassLike::class;
}
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition('Interface have suffix of "Interface", trait have "Trait" suffix exclusively', [
- new CodeSample(
- <<<'CODE_SAMPLE'
-
+ * @return list
*/
private function processInterfaceSuffix(Identifier $identifier): array
{
@@ -121,14 +81,18 @@ private function processInterfaceSuffix(Identifier $identifier): array
}
if (str_ends_with($identifier->toString(), 'Trait')) {
- return [RuleErrorBuilder::message(self::TRAIT_ERROR_MESSAGE)->build()];
+ return [RuleErrorBuilder::message(self::TRAIT_ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::EXPLICIT_TRAIT_SUFFIX_NAME)
+ ->build()];
}
- return [RuleErrorBuilder::message(self::INTERFACE_ERROR_MESSAGE)->build()];
+ return [RuleErrorBuilder::message(self::INTERFACE_ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::EXPLICIT_INTERFACE_SUFFIX_NAME)
+ ->build()];
}
/**
- * @return list
+ * @return list
*/
private function processTraitSuffix(Identifier $identifier): array
{
@@ -136,28 +100,39 @@ private function processTraitSuffix(Identifier $identifier): array
return [];
}
- return [RuleErrorBuilder::message(self::TRAIT_ERROR_MESSAGE)->build()];
+ return [RuleErrorBuilder::message(self::TRAIT_ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::EXPLICIT_TRAIT_SUFFIX_NAME)
+ ->build()];
}
/**
- * @return list
+ * @return list
*/
private function processClassSuffix(Identifier $identifier, bool $isAbstract): array
{
if ($isAbstract && ! str_starts_with($identifier->toString(), 'Abstract')) {
- return [RuleErrorBuilder::message(self::ABSTRACT_ERROR_MESSAGE)->build()];
+ return [RuleErrorBuilder::message(self::ABSTRACT_ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::EXPLICIT_ABSTRACT_PREFIX_NAME)
+ ->build()];
}
if (! $isAbstract && str_starts_with($identifier->toString(), 'Abstract')) {
- return [RuleErrorBuilder::message(self::ABSTRACT_ERROR_MESSAGE)->build()];
+ return [RuleErrorBuilder::message(self::ABSTRACT_ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::EXPLICIT_ABSTRACT_PREFIX_NAME)
+ ->build()
+ ];
}
if (str_ends_with($identifier->toString(), 'Interface')) {
- return [RuleErrorBuilder::message(self::INTERFACE_ERROR_MESSAGE)->build()];
+ return [RuleErrorBuilder::message(self::INTERFACE_ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::EXPLICIT_INTERFACE_SUFFIX_NAME)
+ ->build()];
}
if (str_ends_with($identifier->toString(), 'Trait')) {
- return [RuleErrorBuilder::message(self::TRAIT_ERROR_MESSAGE)->build()];
+ return [RuleErrorBuilder::message(self::TRAIT_ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::EXPLICIT_TRAIT_SUFFIX_NAME)
+ ->build()];
}
return [];
diff --git a/src/Rules/ForbiddenExtendOfNonAbstractClassRule.php b/src/Rules/ForbiddenExtendOfNonAbstractClassRule.php
index 9e79bfdd..e808d13f 100644
--- a/src/Rules/ForbiddenExtendOfNonAbstractClassRule.php
+++ b/src/Rules/ForbiddenExtendOfNonAbstractClassRule.php
@@ -10,15 +10,13 @@
use PHPStan\Reflection\ClassReflection;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
/**
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\ForbiddenExtendOfNonAbstractClassRule\ForbiddenExtendOfNonAbstractClassRuleTest
*/
-final class ForbiddenExtendOfNonAbstractClassRule implements Rule, DocumentedRuleInterface
+final class ForbiddenExtendOfNonAbstractClassRule implements Rule
{
/**
* @var string
@@ -64,33 +62,8 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
- return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
- }
-
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-final class SomeClass extends ParentClass
-{
-}
-
-class ParentClass
-{
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-final class SomeClass extends ParentClass
-{
-}
-
-abstract class ParentClass
-{
-}
-CODE_SAMPLE
- ),
- ]);
+ return [RuleErrorBuilder::message(self::ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::FORBIDDEN_EXTEND_OF_NON_ABSTRACT_CLASS)
+ ->build()];
}
}
diff --git a/src/Rules/ForbiddenFuncCallRule.php b/src/Rules/ForbiddenFuncCallRule.php
index 519de861..94b92dd4 100644
--- a/src/Rules/ForbiddenFuncCallRule.php
+++ b/src/Rules/ForbiddenFuncCallRule.php
@@ -9,23 +9,21 @@
use PhpParser\Node\Name;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
+use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\ObjectType;
use PHPStan\Type\TypeCombinator;
use SimpleXMLElement;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
use Symplify\PHPStanRules\Formatter\RequiredWithMessageFormatter;
use Symplify\PHPStanRules\Matcher\ArrayStringAndFnMatcher;
use Symplify\PHPStanRules\ValueObject\Configuration\RequiredWithMessage;
-use Symplify\RuleDocGenerator\Contract\ConfigurableRuleInterface;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\ForbiddenFuncCallRule\ForbiddenFuncCallRuleTest
*/
-final class ForbiddenFuncCallRule implements Rule, DocumentedRuleInterface, ConfigurableRuleInterface
+final class ForbiddenFuncCallRule implements Rule
{
/**
* @var string
@@ -70,47 +68,17 @@ public function processNode(Node $node, Scope $scope): array
}
$errorMessage = $this->createErrorMessage($requiredWithMessage, $funcName);
- return [RuleErrorBuilder::message($errorMessage)->build()];
+
+ $ruleError = RuleErrorBuilder::message($errorMessage)
+ ->identifier(RuleIdentifier::FORBIDDEN_FUNC_CALL)
+ ->build();
+
+ return [$ruleError];
}
return [];
}
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new ConfiguredCodeSample(
- <<<'CODE_SAMPLE'
-echo eval('...');
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-echo '...';
-CODE_SAMPLE
- ,
- [
- 'forbiddenFunctions' => ['eval'],
- ]
- ),
- new ConfiguredCodeSample(
- <<<'CODE_SAMPLE'
-dump($value);
-echo $value;
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-echo $value;
-CODE_SAMPLE
- ,
- [
- 'forbiddenFunctions' => [
- 'dump' => 'seems you missed some debugging function',
- ],
- ]
- ),
- ]);
- }
-
private function shouldAllowSpecialCase(FuncCall $funcCall, Scope $scope, string $functionName): bool
{
if ($functionName !== 'property_exists') {
diff --git a/src/Rules/ForbiddenMultipleClassLikeInOneFileRule.php b/src/Rules/ForbiddenMultipleClassLikeInOneFileRule.php
index fedf59ca..563abe24 100644
--- a/src/Rules/ForbiddenMultipleClassLikeInOneFileRule.php
+++ b/src/Rules/ForbiddenMultipleClassLikeInOneFileRule.php
@@ -12,15 +12,13 @@
use PHPStan\Node\FileNode;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
/**
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\ForbiddenMultipleClassLikeInOneFileRule\ForbiddenMultipleClassLikeInOneFileRuleTest
*/
-final class ForbiddenMultipleClassLikeInOneFileRule implements Rule, DocumentedRuleInterface
+final class ForbiddenMultipleClassLikeInOneFileRule implements Rule
{
/**
* @var string
@@ -60,36 +58,8 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
- return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
- }
-
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-// src/SomeClass.php
-class SomeClass
-{
-}
-
-interface SomeInterface
-{
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-// src/SomeClass.php
-class SomeClass
-{
-}
-
-// src/SomeInterface.php
-interface SomeInterface
-{
-}
-CODE_SAMPLE
- ),
- ]);
+ return [RuleErrorBuilder::message(self::ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::MULTIPLE_CLASS_LIKE_IN_FILE)
+ ->build()];
}
}
diff --git a/src/Rules/ForbiddenNodeRule.php b/src/Rules/ForbiddenNodeRule.php
index 7e946737..c6004574 100644
--- a/src/Rules/ForbiddenNodeRule.php
+++ b/src/Rules/ForbiddenNodeRule.php
@@ -5,24 +5,20 @@
namespace Symplify\PHPStanRules\Rules;
use PhpParser\Node;
-use PhpParser\Node\Expr\ErrorSuppress;
use PhpParser\Node\Scalar\Encapsed;
use PhpParser\Node\Scalar\EncapsedStringPart;
use PhpParser\PrettyPrinter\Standard;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
-use Symplify\RuleDocGenerator\Contract\ConfigurableRuleInterface;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
use Webmozart\Assert\Assert;
/**
* @see \Symplify\PHPStanRules\Tests\Rules\ForbiddenNodeRule\ForbiddenNodeRuleTest
* @implements Rule
*/
-final class ForbiddenNodeRule implements Rule, DocumentedRuleInterface, ConfigurableRuleInterface
+final class ForbiddenNodeRule implements Rule
{
/**
* @var string
@@ -69,28 +65,13 @@ public function processNode(Node $node, Scope $scope): array
$errorMessage = sprintf(self::ERROR_MESSAGE, $contents);
- return [RuleErrorBuilder::message($errorMessage)->build()];
+ $ruleError = RuleErrorBuilder::message($errorMessage)
+ ->identifier(RuleIdentifier::FORBIDDEN_NODE)
+ ->build();
+
+ return [$ruleError];
}
return [];
}
-
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new ConfiguredCodeSample(
- <<<'CODE_SAMPLE'
-return @strlen('...');
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-return strlen('...');
-CODE_SAMPLE
- ,
- [
- 'forbiddenNodes' => [ErrorSuppress::class],
- ]
- ),
- ]);
- }
}
diff --git a/src/Rules/ForbiddenStaticClassConstFetchRule.php b/src/Rules/ForbiddenStaticClassConstFetchRule.php
index 4d2de5eb..ede0bf82 100644
--- a/src/Rules/ForbiddenStaticClassConstFetchRule.php
+++ b/src/Rules/ForbiddenStaticClassConstFetchRule.php
@@ -10,15 +10,13 @@
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;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
/**
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\ForbiddenStaticClassConstFetchRule\ForbiddenStaticClassConstFetchRuleTest
*/
-final class ForbiddenStaticClassConstFetchRule implements Rule, DocumentedRuleInterface
+final class ForbiddenStaticClassConstFetchRule implements Rule
{
/**
* @var string
@@ -43,33 +41,8 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
- return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
- }
-
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-class SomeClass
-{
- public function run()
- {
- return static::SOME_CONST;
- }
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-class SomeClass
-{
- public function run()
- {
- return self::SOME_CONST;
- }
-}
-CODE_SAMPLE
- ),
- ]);
+ return [RuleErrorBuilder::message(self::ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::FORBIDDEN_STATIC_CLASS_CONST_FETCH)
+ ->build()];
}
}
diff --git a/src/Rules/NoDynamicNameRule.php b/src/Rules/NoDynamicNameRule.php
index bad7204b..149cc866 100644
--- a/src/Rules/NoDynamicNameRule.php
+++ b/src/Rules/NoDynamicNameRule.php
@@ -16,8 +16,6 @@
use PHPStan\Analyser\Scope;
use PHPStan\Rules\RuleErrorBuilder;
use Symplify\PHPStanRules\TypeAnalyzer\CallableTypeAnalyzer;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Symplify\PHPStanRules\Tests\Rules\NoDynamicNameRule\NoDynamicNameRuleTest
@@ -80,31 +78,4 @@ public function process(Node $node, Scope $scope): array
return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
}
-
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-class SomeClass
-{
- public function old(): bool
- {
- return $this->${variable};
- }
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-class SomeClass
-{
- public function old(): bool
- {
- return $this->specificMethodName();
- }
-}
-CODE_SAMPLE
- ),
- ]);
- }
}
diff --git a/src/Rules/NoEntityOutsideEntityNamespaceRule.php b/src/Rules/NoEntityOutsideEntityNamespaceRule.php
index 936102a8..797df7cf 100644
--- a/src/Rules/NoEntityOutsideEntityNamespaceRule.php
+++ b/src/Rules/NoEntityOutsideEntityNamespaceRule.php
@@ -10,14 +10,12 @@
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;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
/**
* @implements Rule
*/
-final class NoEntityOutsideEntityNamespaceRule implements Rule, DocumentedRuleInterface
+final class NoEntityOutsideEntityNamespaceRule implements Rule
{
/**
* @var string
@@ -49,38 +47,9 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
- return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
- }
-
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(
- self::ERROR_MESSAGE,
- [
- new CodeSample(
- <<<'CODE_SAMPLE'
-namespace App\ValueObject;
-
-use Doctrine\ORM\Mapping as ORM;
-
-#[ORM\Entity]
-class Product
-{
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-namespace App\Entity;
-
-use Doctrine\ORM\Mapping as ORM;
-
-#[ORM\Entity]
-class Product
-{
-}
-CODE_SAMPLE
- )]
- );
+ return [RuleErrorBuilder::message(self::ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::NO_ENTITY_OUTSIDE_ENTITY_NAMESPACE)
+ ->build()];
}
private function hasEntityAttribute(Class_ $class): bool
diff --git a/src/Rules/NoGlobalConstRule.php b/src/Rules/NoGlobalConstRule.php
index 2d28944b..d3260851 100644
--- a/src/Rules/NoGlobalConstRule.php
+++ b/src/Rules/NoGlobalConstRule.php
@@ -9,15 +9,13 @@
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;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
/**
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\NoGlobalConstRule\NoGlobalConstRuleTest
*/
-final class NoGlobalConstRule implements Rule, DocumentedRuleInterface
+final class NoGlobalConstRule implements Rule
{
/**
* @var string
@@ -34,27 +32,10 @@ public function getNodeType(): string
*/
public function processNode(Node $node, Scope $scope): array
{
- return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
- }
+ $identifierRuleError = RuleErrorBuilder::message(self::ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::NO_GLOBAL_CONST)
+ ->build();
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-const SOME_GLOBAL_CONST = 'value';
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-class SomeClass
-{
- public function run()
- {
- return self::SOME_CONST;
- }
-}
-CODE_SAMPLE
- ),
- ]);
+ return [$identifierRuleError];
}
}
diff --git a/src/Rules/NoInlineStringRegexRule.php b/src/Rules/NoInlineStringRegexRule.php
index 572be954..00a1fae0 100644
--- a/src/Rules/NoInlineStringRegexRule.php
+++ b/src/Rules/NoInlineStringRegexRule.php
@@ -11,20 +11,19 @@
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\Scope;
+use PHPStan\Rules\IdentifierRuleError;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
use Symplify\PHPStanRules\NodeAnalyzer\RegexFuncCallAnalyzer;
use Symplify\PHPStanRules\NodeAnalyzer\RegexStaticCallAnalyzer;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\NoInlineStringRegexRule\NoInlineStringRegexRuleTest
*/
-final class NoInlineStringRegexRule implements Rule, DocumentedRuleInterface
+final class NoInlineStringRegexRule implements Rule
{
/**
* @var string
@@ -58,40 +57,8 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-class SomeClass
-{
- public function run($value)
- {
- return preg_match('#some_stu|ff#', $value);
- }
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-class SomeClass
-{
- /**
- * @var string
- */
- public const SOME_STUFF_REGEX = '#some_stu|ff#';
-
- public function run($value)
- {
- return preg_match(self::SOME_STUFF_REGEX, $value);
- }
-}
-CODE_SAMPLE
- ),
- ]);
- }
-
/**
- * @return list
+ * @return list
*/
private function processRegexFuncCall(FuncCall $funcCall): array
{
@@ -106,11 +73,13 @@ private function processRegexFuncCall(FuncCall $funcCall): array
return [];
}
- return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
+ return [RuleErrorBuilder::message(self::ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::CLASS_CONSTANT_REGEX)
+ ->build()];
}
/**
- * @return list
+ * @return list
*/
private function processRegexStaticCall(StaticCall $staticCall): array
{
@@ -132,6 +101,8 @@ private function processRegexStaticCall(StaticCall $staticCall): array
return [];
}
- return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
+ return [RuleErrorBuilder::message(self::ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::CLASS_CONSTANT_REGEX)
+ ->build()];
}
}
diff --git a/src/Rules/NoReferenceRule.php b/src/Rules/NoReferenceRule.php
index bb189225..9f297f31 100644
--- a/src/Rules/NoReferenceRule.php
+++ b/src/Rules/NoReferenceRule.php
@@ -18,8 +18,6 @@
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
use Symplify\PHPStanRules\ParentClassMethodNodeResolver;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use function array_map;
/**
@@ -73,32 +71,6 @@ public function process(Node $node, Scope $scope): array
);
}
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-class SomeClass
-{
- public function run(&$value)
- {
- }
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-class SomeClass
-{
- public function run($value)
- {
- return $value;
- }
-}
-CODE_SAMPLE
- ),
- ]);
- }
-
/**
* @return string[]
*/
diff --git a/src/Rules/NoReturnArrayVariableListRule.php b/src/Rules/NoReturnArrayVariableListRule.php
index 94f1466a..9ea844b3 100644
--- a/src/Rules/NoReturnArrayVariableListRule.php
+++ b/src/Rules/NoReturnArrayVariableListRule.php
@@ -15,17 +15,15 @@
use PHPStan\Reflection\MethodReflection;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
use Symplify\PHPStanRules\ParentClassMethodNodeResolver;
use Symplify\PHPStanRules\Testing\StaticPHPUnitEnvironment;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\NoReturnArrayVariableListRule\NoReturnArrayVariableListRuleTest
*/
-final class NoReturnArrayVariableListRule implements Rule, DocumentedRuleInterface
+final class NoReturnArrayVariableListRule implements Rule
{
/**
* @var string
@@ -70,34 +68,11 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
- return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
- }
+ $identifierRuleError = RuleErrorBuilder::message(self::ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::NO_RETURN_ARRAY_VARIABLE_LIST)
+ ->build();
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-class ReturnVariables
-{
- public function run($value, $value2): array
- {
- return [$value, $value2];
- }
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-final class ReturnVariables
-{
- public function run($value, $value2): ValueObject
- {
- return new ValueObject($value, $value2);
- }
-}
-CODE_SAMPLE
- ),
- ]);
+ return [$identifierRuleError];
}
private function shouldSkip(Scope $scope, Return_ $return): bool
diff --git a/src/Rules/NoReturnSetterMethodRule.php b/src/Rules/NoReturnSetterMethodRule.php
index ff4a6220..6ab647dc 100644
--- a/src/Rules/NoReturnSetterMethodRule.php
+++ b/src/Rules/NoReturnSetterMethodRule.php
@@ -13,17 +13,15 @@
use PHPStan\Reflection\ClassReflection;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
use Symplify\PHPStanRules\NodeFinder\TypeAwareNodeFinder;
use Symplify\PHPStanRules\NodeVisitor\HasScopedReturnNodeVisitor;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\NoReturnSetterMethodRule\NoReturnSetterMethodRuleTest
*/
-final class NoReturnSetterMethodRule implements Rule, DocumentedRuleInterface
+final class NoReturnSetterMethodRule implements Rule
{
/**
* @var string
@@ -51,7 +49,6 @@ public function getNodeType(): string
/**
* @param ClassMethod $node
- * @return string[]
*/
public function processNode(Node $node, Scope $scope): array
{
@@ -77,38 +74,9 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
- return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
- }
-
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-final class SomeClass
-{
- private $name;
-
- public function setName(string $name): int
- {
- return 1000;
- }
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-final class SomeClass
-{
- private $name;
-
- public function setName(string $name): void
- {
- $this->name = $name;
- }
-}
-CODE_SAMPLE
- ),
- ]);
+ return [RuleErrorBuilder::message(self::ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::NO_RETURN_SETTER_METHOD)
+ ->build()];
}
private function hasReturnReturnFunctionLike(ClassMethod $classMethod): bool
diff --git a/src/Rules/NoSingleInterfaceImplementerRule.php b/src/Rules/NoSingleInterfaceImplementerRule.php
index 95d9bd88..f40ebe56 100644
--- a/src/Rules/NoSingleInterfaceImplementerRule.php
+++ b/src/Rules/NoSingleInterfaceImplementerRule.php
@@ -14,14 +14,12 @@
use Symplify\PHPStanRules\Collector\ImplementedInterfaceCollector;
use Symplify\PHPStanRules\Collector\InterfaceCollector;
use Symplify\PHPStanRules\Collector\InterfaceOfAbstractClassCollector;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
/**
* @see \Symplify\PHPStanRules\Tests\Rules\NoSingleInterfaceImplementerRule\NoSingleInterfaceImplementerRuleTest
*/
-final class NoSingleInterfaceImplementerRule implements Rule, DocumentedRuleInterface
+final class NoSingleInterfaceImplementerRule implements Rule
{
/**
* @api used in test
@@ -58,7 +56,7 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
- $errorMessages = [];
+ $ruleErrors = [];
foreach ($onceImplementedInterfaces as $onceImplementedInterface) {
$interfaceReflection = $this->reflectionProvider->getClass($onceImplementedInterface);
@@ -67,43 +65,13 @@ public function processNode(Node $node, Scope $scope): array
continue;
}
- $errorMessages[] = RuleErrorBuilder::message(sprintf(self::ERROR_MESSAGE, $onceImplementedInterface))
+ $ruleErrors[] = RuleErrorBuilder::message(sprintf(self::ERROR_MESSAGE, $onceImplementedInterface))
->file($interfaceReflection->getFileName())
+ ->identifier(RuleIdentifier::NO_SINGLE_INTERFACE_IMPLEMENTER)
->build();
}
- return $errorMessages;
- }
-
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-class SomeClass implements SomeInterface
-{
-}
-
-interface SomeInterface
-{
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-class SomeClass implements SomeInterface
-{
-}
-
-class AnotherClass implements SomeInterface
-{
-}
-
-interface SomeInterface
-{
-}
-CODE_SAMPLE
- ),
- ]);
+ return $ruleErrors;
}
/**
diff --git a/src/Rules/PHPUnit/NoTestMocksRule.php b/src/Rules/PHPUnit/NoTestMocksRule.php
index a07cca16..77dfb89e 100644
--- a/src/Rules/PHPUnit/NoTestMocksRule.php
+++ b/src/Rules/PHPUnit/NoTestMocksRule.php
@@ -11,14 +11,12 @@
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\ObjectType;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
/**
* @implements Rule
*/
-final class NoTestMocksRule implements Rule, DocumentedRuleInterface
+final class NoTestMocksRule implements Rule
{
/**
* @api
@@ -69,38 +67,9 @@ public function processNode(Node $node, Scope $scope): array
$errorMessage = sprintf(self::ERROR_MESSAGE, $mockedObjectType->getClassName());
- return [RuleErrorBuilder::message($errorMessage)->build()];
- }
-
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-use PHPUnit\Framework\TestCase;
-
-final class SkipApiMock extends TestCase
-{
- public function test()
- {
- $someTypeMock = $this->createMock(SomeType::class);
- }
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-use PHPUnit\Framework\TestCase;
-
-final class SkipApiMock extends TestCase
-{
- public function test()
- {
- $someTypeMock = new class() implements SomeType {};
- }
-}
-CODE_SAMPLE
- ),
- ]);
+ return [RuleErrorBuilder::message($errorMessage)
+ ->identifier(RuleIdentifier::NO_TEST_MOCKS)
+ ->build()];
}
private function resolveMockedObjectType(MethodCall $methodCall, Scope $scope): ?ObjectType
diff --git a/src/Rules/PreferredClassRule.php b/src/Rules/PreferredClassRule.php
index 635fb1b3..2abe24d6 100644
--- a/src/Rules/PreferredClassRule.php
+++ b/src/Rules/PreferredClassRule.php
@@ -14,18 +14,15 @@
use PHPStan\Analyser\Scope;
use PHPStan\Node\InClassNode;
use PHPStan\Reflection\ClassReflection;
+use PHPStan\Rules\IdentifierRuleError;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
-use SplFileInfo;
-use Symplify\RuleDocGenerator\Contract\ConfigurableRuleInterface;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
/**
- * @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\PreferredClassRule\PreferredClassRuleTest
*/
-final class PreferredClassRule extends AbstractSymplifyRule implements ConfigurableRuleInterface
+final class PreferredClassRule extends AbstractSymplifyRule
{
/**
* @var string
@@ -65,41 +62,8 @@ public function process(Node $node, Scope $scope): array
return $this->processClassName($node->toString());
}
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new ConfiguredCodeSample(
- <<<'CODE_SAMPLE'
-class SomeClass
-{
- public function run()
- {
- return new SplFileInfo('...');
- }
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-class SomeClass
-{
- public function run()
- {
- return new CustomFileInfo('...');
- }
-}
-CODE_SAMPLE
- ,
- [
- 'oldToPreferredClasses' => [
- SplFileInfo::class => 'CustomFileInfo',
- ],
- ]
- ),
- ]);
- }
-
/**
- * @return string[]
+ * @return IdentifierRuleError[]
*/
private function processNew(New_ $new): array
{
@@ -112,7 +76,7 @@ private function processNew(New_ $new): array
}
/**
- * @return list
+ * @return list
*/
private function processClass(InClassNode $inClassNode): array
{
@@ -137,14 +101,16 @@ private function processClass(InClassNode $inClassNode): array
}
$errorMessage = sprintf(self::ERROR_MESSAGE, $oldClass, $prefferedClass);
- return [RuleErrorBuilder::message($errorMessage)->build()];
+ return [RuleErrorBuilder::message($errorMessage)
+ ->identifier(RuleIdentifier::PREFERRED_CLASS)
+ ->build()];
}
return [];
}
/**
- * @return list
+ * @return list
*/
private function processClassName(string $className): array
{
@@ -154,14 +120,18 @@ private function processClassName(string $className): array
}
$errorMessage = sprintf(self::ERROR_MESSAGE, $oldClass, $prefferedClass);
- return [RuleErrorBuilder::message($errorMessage)->build()];
+ $ruleError = RuleErrorBuilder::message($errorMessage)
+ ->identifier(RuleIdentifier::PREFERRED_CLASS)
+ ->build();
+
+ return [$ruleError];
}
return [];
}
/**
- * @return list
+ * @return list
*/
private function processExprWithClass(StaticCall|Instanceof_ $node): array
{
diff --git a/src/Rules/PreventParentMethodVisibilityOverrideRule.php b/src/Rules/PreventParentMethodVisibilityOverrideRule.php
index 7305c1c9..c8ec0798 100644
--- a/src/Rules/PreventParentMethodVisibilityOverrideRule.php
+++ b/src/Rules/PreventParentMethodVisibilityOverrideRule.php
@@ -12,15 +12,13 @@
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
/**
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\PreventParentMethodVisibilityOverrideRule\PreventParentMethodVisibilityOverrideRuleTest
*/
-final class PreventParentMethodVisibilityOverrideRule implements Rule, DocumentedRuleInterface
+final class PreventParentMethodVisibilityOverrideRule implements Rule
{
/**
* @var string
@@ -72,51 +70,15 @@ public function processNode(Node $node, Scope $scope): array
$methodVisibility = $this->resolveReflectionMethodVisibilityAsStrings($parentReflectionMethod);
$errorMessage = sprintf(self::ERROR_MESSAGE, $methodName, $methodVisibility);
- return [RuleErrorBuilder::message($errorMessage)->build()];
+
+ return [RuleErrorBuilder::message($errorMessage)
+ ->identifier(RuleIdentifier::PARENT_METHOD_VISIBILITY_OVERRIDE)
+ ->build()];
}
return [];
}
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-class SomeParentClass
-{
- public function run()
- {
- }
-}
-
-class SomeClass extends SomeParentClass
-{
- protected function run()
- {
- }
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-class SomeParentClass
-{
- public function run()
- {
- }
-}
-
-class SomeClass extends SomeParentClass
-{
- public function run()
- {
- }
-}
-CODE_SAMPLE
- ),
- ]);
- }
-
private function isClassMethodCompatibleWithParentReflectionMethod(
ClassMethod $classMethod,
ExtendedMethodReflection $extendedMethodReflection
diff --git a/src/Rules/Rector/NoClassReflectionStaticReflectionRule.php b/src/Rules/Rector/NoClassReflectionStaticReflectionRule.php
index 6dd3d030..0ed92c54 100644
--- a/src/Rules/Rector/NoClassReflectionStaticReflectionRule.php
+++ b/src/Rules/Rector/NoClassReflectionStaticReflectionRule.php
@@ -11,10 +11,11 @@
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use ReflectionClass;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
use Symplify\PHPStanRules\TypeAnalyzer\RectorAllowedAutoloadedTypeAnalyzer;
/**
- * @see \Rector\PHPStanRules\Tests\Rule\NoClassReflectionStaticReflectionRule\NoClassReflectionStaticReflectionRuleTest
+ * @see \Symplify\PHPStanRules\Tests\Rules\Rector\NoClassReflectionStaticReflectionRule\NoClassReflectionStaticReflectionRuleTest
*
* @implements Rule
*/
@@ -54,6 +55,8 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
- return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
+ return [RuleErrorBuilder::message(self::ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::RECTOR_NO_CLASS_REFLECTION_STATIC_REFLECTION)
+ ->build()];
}
}
diff --git a/src/Rules/Rector/NoInstanceOfStaticReflectionRule.php b/src/Rules/Rector/NoInstanceOfStaticReflectionRule.php
index e42e3b22..668370cd 100644
--- a/src/Rules/Rector/NoInstanceOfStaticReflectionRule.php
+++ b/src/Rules/Rector/NoInstanceOfStaticReflectionRule.php
@@ -14,6 +14,7 @@
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\Type;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
use Symplify\PHPStanRules\TypeAnalyzer\RectorAllowedAutoloadedTypeAnalyzer;
/**
@@ -53,7 +54,9 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
- return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
+ return [RuleErrorBuilder::message(self::ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::RECTOR_NO_INSTANCE_OF_STATIC_REFLECTION)
+ ->build()];
}
private function resolveExprStaticType(FuncCall|Instanceof_ $node, Scope $scope): ?Type
diff --git a/src/Rules/Rector/NoLeadingBackslashInNameRule.php b/src/Rules/Rector/NoLeadingBackslashInNameRule.php
index ead3c054..49010b2e 100644
--- a/src/Rules/Rector/NoLeadingBackslashInNameRule.php
+++ b/src/Rules/Rector/NoLeadingBackslashInNameRule.php
@@ -13,9 +13,10 @@
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\Constant\ConstantStringType;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
/**
- * @see \Rector\PHPStanRules\Tests\Rule\NoLeadingBackslashInNameRule\NoLeadingBackslashInNameRuleTest
+ * @see \Symplify\PHPStanRules\Tests\Rules\Rector\NoLeadingBackslashInNameRule\NoLeadingBackslashInNameRuleTest
*
* @implements Rule
*/
@@ -60,6 +61,8 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
- return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
+ return [RuleErrorBuilder::message(self::ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::PHP_PARSER_NO_LEADING_BACKSLASH_IN_NAME)
+ ->build()];
}
}
diff --git a/src/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule.php b/src/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule.php
index a1e9d835..39b55fb7 100644
--- a/src/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule.php
+++ b/src/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule.php
@@ -17,6 +17,7 @@
use Rector\Set\ValueObject\DowngradeSetList;
use Rector\Set\ValueObject\SetList;
use SplFileInfo;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
use Symplify\PHPStanRules\Exception\ShouldNotHappenException;
/**
@@ -65,7 +66,9 @@ public function processNode(Node $node, Scope $scope): array
}
$errorMessage = $this->createErrorMessage($configFilePath, $className);
- return [RuleErrorBuilder::message($errorMessage)->build()];
+ return [RuleErrorBuilder::message($errorMessage)
+ ->identifier(RuleIdentifier::RECTOR_UPGRADE_DOWNGRADE_REGISTERED_IN_SET)
+ ->build()];
}
private function resolveRelatedConfigFilePath(string $className): ?string
diff --git a/src/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule.php b/src/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule.php
index 5813d68f..c60de44d 100644
--- a/src/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule.php
+++ b/src/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule.php
@@ -12,9 +12,10 @@
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
/**
- * @see \Rector\PHPStanRules\Tests\Rule\PhpUpgradeImplementsMinPhpVersionInterfaceRule\PhpUpgradeImplementsMinPhpVersionInterfaceRuleTest
+ * @see \Symplify\PHPStanRules\Tests\Rules\Rector\PhpUpgradeImplementsMinPhpVersionInterfaceRule\PhpUpgradeImplementsMinPhpVersionInterfaceRuleTest
*
* @implements Rule
*/
@@ -64,6 +65,10 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
- return [RuleErrorBuilder::message(sprintf(self::ERROR_MESSAGE, $className))->build()];
+ $identifierRuleError = RuleErrorBuilder::message(sprintf(self::ERROR_MESSAGE, $className))
+ ->identifier(RuleIdentifier::RECTOR_PHP_RULE_IMPLEMENTS_MIN_VERSION)
+ ->build();
+
+ return [$identifierRuleError];
}
}
diff --git a/src/Rules/Rector/RequireAssertConfigureValueObjectRectorRule.php b/src/Rules/Rector/RequireAssertConfigureValueObjectRectorRule.php
deleted file mode 100644
index f11ea028..00000000
--- a/src/Rules/Rector/RequireAssertConfigureValueObjectRectorRule.php
+++ /dev/null
@@ -1,134 +0,0 @@
-
- */
-final class RequireAssertConfigureValueObjectRectorRule implements Rule
-{
- /**
- * @var string
- */
- public const ERROR_MESSAGE = 'Method configure() with passed value object must contain assert to verify passed type';
-
- private readonly NodeFinder $nodeFinder;
-
- public function __construct(
- ) {
- $this->nodeFinder = new NodeFinder();
- }
-
- public function getNodeType(): string
- {
- return ClassMethod::class;
- }
-
- /**
- * @param ClassMethod $node
- */
- public function processNode(Node $node, Scope $scope): array
- {
- $classReflection = $scope->getClassReflection();
- if (! $classReflection instanceof ClassReflection) {
- return [];
- }
-
- if (! $classReflection->isSubclassOf('Rector\Contract\Rector\ConfigurableRectorInterface')) {
- return [];
- }
-
- if (! $this->hasArrayObjectTypeParam($node, $classReflection)) {
- return [];
- }
-
- if ($this->hasAssertAllIsAOfStaticCall($node)) {
- return [];
- }
-
- return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
- }
-
- private function hasAssertAllIsAOfStaticCall(ClassMethod $classMethod): bool
- {
- /** @var StaticCall[] $staticCalls */
- $staticCalls = $this->nodeFinder->findInstanceOf($classMethod, StaticCall::class);
-
- foreach ($staticCalls as $staticCall) {
- if ($staticCall->class instanceof Name && $staticCall->class->toString() !== Assert::class) {
- continue;
- }
-
- if ($staticCall->name instanceof Identifier) {
- $methodName = $staticCall->name->toString();
- if (in_array($methodName, ['allIsAOf', 'allIsInstanceOf'], true)) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- private function hasArrayObjectTypeParam(ClassMethod $classMethod, ClassReflection $classReflection): bool
- {
- $methodName = $classMethod->name->toString();
- if (! $classReflection->hasMethod($methodName)) {
- return false;
- }
-
- $extendedMethodReflection = $classReflection->getNativeMethod($methodName);
- if (! $extendedMethodReflection instanceof PhpMethodReflection) {
- return false;
- }
-
- foreach ($extendedMethodReflection->getVariants() as $variant) {
- if (! $variant instanceof ExtendedFunctionVariant) {
- continue;
- }
-
- if ($variant->getParameters() === []) {
- continue;
- }
-
- $configurationParameterReflection = $variant->getParameters()[0];
- $phpDocType = $configurationParameterReflection->getPhpDocType();
- if (! $phpDocType instanceof ArrayType) {
- continue;
- }
-
- $itemArrayType = $phpDocType->getItemType();
- if (! $itemArrayType instanceof ArrayType) {
- continue;
- }
-
- if (! $itemArrayType->getItemType() instanceof TypeWithClassName) {
- continue;
- }
-
- return true;
- }
-
- return false;
- }
-}
diff --git a/src/Rules/RegexSuffixInRegexConstantRule.php b/src/Rules/RegexSuffixInRegexConstantRule.php
index 84a67583..cdd4134e 100644
--- a/src/Rules/RegexSuffixInRegexConstantRule.php
+++ b/src/Rules/RegexSuffixInRegexConstantRule.php
@@ -11,20 +11,18 @@
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\StaticCall;
use PHPStan\Analyser\Scope;
+use PHPStan\Rules\IdentifierRuleError;
use PHPStan\Rules\Rule;
-use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
use Symplify\PHPStanRules\NodeAnalyzer\RegexFuncCallAnalyzer;
use Symplify\PHPStanRules\NodeAnalyzer\RegexStaticCallAnalyzer;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\RegexSuffixInRegexConstantRule\RegexSuffixInRegexConstantRuleTest
*/
-final class RegexSuffixInRegexConstantRule implements Rule, DocumentedRuleInterface
+final class RegexSuffixInRegexConstantRule implements Rule
{
/**
* @var string
@@ -58,39 +56,8 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-class SomeClass
-{
- public const SOME_NAME = '#some\s+name#';
-
- public function run($value)
- {
- $somePath = preg_match(self::SOME_NAME, $value);
- }
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-class SomeClass
-{
- public const SOME_NAME_REGEX = '#some\s+name#';
-
- public function run($value)
- {
- $somePath = preg_match(self::SOME_NAME_REGEX, $value);
- }
-}
-CODE_SAMPLE
- ),
- ]);
- }
-
/**
- * @return list
+ * @return list
*/
private function processConstantName(Expr $expr): array
{
@@ -108,11 +75,13 @@ private function processConstantName(Expr $expr): array
}
$errorMessage = sprintf(self::ERROR_MESSAGE, $constantName);
- return [RuleErrorBuilder::message($errorMessage)->build()];
+ return [RuleErrorBuilder::message($errorMessage)
+ ->identifier(RuleIdentifier::REGEX_SUFFIX_IN_REGEX_CONSTANT)
+ ->build()];
}
/**
- * @return list
+ * @return list
*/
private function processStaticCall(StaticCall $staticCall): array
{
@@ -125,7 +94,7 @@ private function processStaticCall(StaticCall $staticCall): array
}
/**
- * @return list
+ * @return list
*/
private function processFuncCall(FuncCall $funcCall): array
{
diff --git a/src/Rules/RequireAttributeNameRule.php b/src/Rules/RequireAttributeNameRule.php
index 7c22a0bc..c9cf139a 100644
--- a/src/Rules/RequireAttributeNameRule.php
+++ b/src/Rules/RequireAttributeNameRule.php
@@ -11,15 +11,13 @@
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;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
/**
* @see \Symplify\PHPStanRules\Tests\Rules\RequireAttributeNameRule\RequireAttributeNameRuleTest
* @implements Rule
*/
-final class RequireAttributeNameRule implements Rule, DocumentedRuleInterface
+final class RequireAttributeNameRule implements Rule
{
/**
* @var string
@@ -31,37 +29,6 @@ public function getNodeType(): string
return AttributeGroup::class;
}
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-use Symfony\Component\Routing\Annotation\Route;
-
-class SomeController
-{
- #[Route("/path")]
- public function someAction()
- {
- }
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-use Symfony\Component\Routing\Annotation\Route;
-
-class SomeController
-{
- #[Route(path: "/path")]
- public function someAction()
- {
- }
-}
-CODE_SAMPLE
- ),
- ]);
- }
-
/**
* @param AttributeGroup $node
*/
@@ -86,6 +53,7 @@ public function processNode(Node $node, Scope $scope): array
}
$ruleErrors[] = RuleErrorBuilder::message(self::ERROR_MESSAGE)
+ ->identifier(RuleIdentifier::REQUIRE_ATTRIBUTE_NAME)
->line($attribute->getLine())
->build();
}
diff --git a/src/Rules/SeeAnnotationToTestRule.php b/src/Rules/SeeAnnotationToTestRule.php
index e26dabee..8c5d4c47 100644
--- a/src/Rules/SeeAnnotationToTestRule.php
+++ b/src/Rules/SeeAnnotationToTestRule.php
@@ -16,18 +16,15 @@
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPUnit\Framework\TestCase;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
use Symplify\PHPStanRules\PhpDoc\PhpDocResolver;
use Symplify\PHPStanRules\PhpDoc\SeePhpDocTagNodesFinder;
-use Symplify\RuleDocGenerator\Contract\ConfigurableRuleInterface;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\SeeAnnotationToTestRule\SeeAnnotationToTestRuleTest
*/
-final class SeeAnnotationToTestRule implements Rule, DocumentedRuleInterface, ConfigurableRuleInterface
+final class SeeAnnotationToTestRule implements Rule
{
/**
* @var string
@@ -66,13 +63,16 @@ public function processNode(Node $node, Scope $scope): array
$docComment = $node->getDocComment();
$errorMessage = sprintf(self::ERROR_MESSAGE, $classReflection->getName());
+
if (! $docComment instanceof Doc) {
- return [RuleErrorBuilder::message($errorMessage)->build()];
+ return [RuleErrorBuilder::message($errorMessage)
+ ->identifier(RuleIdentifier::SEE_ANNOTATION_TO_TEST)
+ ->build()];
}
$resolvedPhpDocBlock = $this->phpDocResolver->resolve($scope, $classReflection, $docComment);
- // skip deprectaed
+ // skip deprecated
$deprecatedTags = $resolvedPhpDocBlock->getDeprecatedTag();
if ($deprecatedTags instanceof DeprecatedTag) {
return [];
@@ -83,33 +83,9 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
- return [RuleErrorBuilder::message($errorMessage)->build()];
- }
-
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new ConfiguredCodeSample(
- <<<'CODE_SAMPLE'
-class SomeClass extends Rule
-{
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-/**
- * @see SomeClassTest
- */
-class SomeClass extends Rule
-{
-}
-CODE_SAMPLE
- ,
- [
- 'requiredSeeTypes' => ['Rule'],
- ]
- ),
- ]);
+ return [RuleErrorBuilder::message($errorMessage)
+ ->identifier(RuleIdentifier::SEE_ANNOTATION_TO_TEST)
+ ->build()];
}
private function shouldSkipClassReflection(ClassReflection $classReflection): bool
diff --git a/src/Rules/UppercaseConstantRule.php b/src/Rules/UppercaseConstantRule.php
index dec22f38..aa99d6e9 100644
--- a/src/Rules/UppercaseConstantRule.php
+++ b/src/Rules/UppercaseConstantRule.php
@@ -9,15 +9,13 @@
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;
+use Symplify\PHPStanRules\Enum\RuleIdentifier;
/**
* @implements Rule
* @see \Symplify\PHPStanRules\Tests\Rules\UppercaseConstantRule\UppercaseConstantRuleTest
*/
-final class UppercaseConstantRule implements Rule, DocumentedRuleInterface
+final class UppercaseConstantRule implements Rule
{
/**
* @var string
@@ -41,30 +39,11 @@ public function processNode(Node $node, Scope $scope): array
}
$errorMessage = sprintf(self::ERROR_MESSAGE, $constantName);
- return [RuleErrorBuilder::message($errorMessage)->build()];
+ return [RuleErrorBuilder::message($errorMessage)
+ ->identifier(RuleIdentifier::UPPERCASE_CONSTANT)
+ ->build()];
}
return [];
}
-
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-final class SomeClass
-{
- public const some = 'value';
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-final class SomeClass
-{
- public const SOME = 'value';
-}
-CODE_SAMPLE
- ),
- ]);
- }
}
diff --git a/src/Symfony/Rules/RequireInvokableControllerRule.php b/src/Symfony/Rules/RequireInvokableControllerRule.php
index 156a9915..561f4260 100644
--- a/src/Symfony/Rules/RequireInvokableControllerRule.php
+++ b/src/Symfony/Rules/RequireInvokableControllerRule.php
@@ -13,14 +13,11 @@
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symplify\PHPStanRules\Enum\MethodName;
use Symplify\PHPStanRules\Symfony\NodeAnalyzer\SymfonyControllerAnalyzer;
-use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Symplify\PHPStanRules\Tests\Symfony\Rules\RequireInvokableControllerRule\RequireInvokableControllerRuleTest
*/
-final class RequireInvokableControllerRule implements Rule, DocumentedRuleInterface
+final class RequireInvokableControllerRule implements Rule
{
/**
* @var string
@@ -72,37 +69,4 @@ public function processNode(Node $node, Scope $scope): array
return $ruleErrors;
}
-
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition(self::ERROR_MESSAGE, [
- new CodeSample(
- <<<'CODE_SAMPLE'
-use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
-use Symfony\Component\Routing\Annotation\Route;
-
-final class SomeController extends AbstractController
-{
- #[Route()]
- public function someMethod()
- {
- }
-}
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
-use Symfony\Component\Routing\Annotation\Route;
-
-final class SomeController extends AbstractController
-{
- #[Route()]
- public function __invoke()
- {
- }
-}
-CODE_SAMPLE
- ),
- ]);
- }
}
diff --git a/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/Fixture/MissingConfigureWithAssert.php b/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/Fixture/MissingConfigureWithAssert.php
deleted file mode 100644
index 3cd894bd..00000000
--- a/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/Fixture/MissingConfigureWithAssert.php
+++ /dev/null
@@ -1,42 +0,0 @@
- $configuration
- */
- public function configure(array $configuration): void
- {
- $valueObjects = $configuration[self::SOME_KEY] ?? [];
- }
-
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition('...', []);
- }
-
- public function getNodeTypes(): array
- {
- return [];
- }
-
- public function refactor(Node $node)
- {
- return null;
- }
-}
diff --git a/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/Fixture/SkipConfigureWithAssert.php b/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/Fixture/SkipConfigureWithAssert.php
deleted file mode 100644
index d69f7de4..00000000
--- a/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/Fixture/SkipConfigureWithAssert.php
+++ /dev/null
@@ -1,26 +0,0 @@
- $configuration
- */
- public function configure(array $configuration): void
- {
- $valueObjects = $configuration[self::SOME_KEY] ?? [];
- Assert::allIsAOf($valueObjects, SomeValueObject::class);
- }
-}
diff --git a/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/Fixture/SkipConfigureWithAssertInstanceof.php b/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/Fixture/SkipConfigureWithAssertInstanceof.php
deleted file mode 100644
index 8bf96a38..00000000
--- a/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/Fixture/SkipConfigureWithAssertInstanceof.php
+++ /dev/null
@@ -1,26 +0,0 @@
- $configuration
- */
- public function configure(array $configuration): void
- {
- $valueObjects = $configuration[self::SOME_KEY] ?? [];
- Assert::allIsInstanceOf($valueObjects, SomeValueObject::class);
- }
-}
diff --git a/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/Fixture/SkipNoArray.php b/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/Fixture/SkipNoArray.php
deleted file mode 100644
index 1956196a..00000000
--- a/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/Fixture/SkipNoArray.php
+++ /dev/null
@@ -1,23 +0,0 @@
- $configuration
- */
- public function configure(array $configuration): void
- {
- $valueObjects = $configuration[self::SOME_KEY] ?? [];
- }
-}
diff --git a/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/RequireAssertConfigureValueObjectRectorRuleTest.php b/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/RequireAssertConfigureValueObjectRectorRuleTest.php
deleted file mode 100644
index 12bfee2e..00000000
--- a/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/RequireAssertConfigureValueObjectRectorRuleTest.php
+++ /dev/null
@@ -1,47 +0,0 @@
-markTestIncomplete('Skip this test because Rector is not installed');
- }
-
- $this->analyse([$filePath], $expectedErrorsWithLines);
- }
-
- public static function provideData(): Iterator
- {
- yield [__DIR__ . '/Fixture/MissingConfigureWithAssert.php', [[RequireAssertConfigureValueObjectRectorRule::ERROR_MESSAGE, 23]]];
-
- yield [__DIR__ . '/Fixture/SkipConfigureWithAssert.php', []];
- yield [__DIR__ . '/Fixture/SkipConfigureWithAssertInstanceof.php', []];
- yield [__DIR__ . '/Fixture/SkipNoArray.php', []];
- }
-
- public static function getAdditionalConfigFiles(): array
- {
- return [__DIR__ . '/config/configured_rule.neon'];
- }
-
- protected function getRule(): Rule
- {
- return self::getContainer()->getByType(RequireAssertConfigureValueObjectRectorRule::class);
- }
-}
diff --git a/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/Source/SomeValueObject.php b/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/Source/SomeValueObject.php
deleted file mode 100644
index 55efb473..00000000
--- a/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/Source/SomeValueObject.php
+++ /dev/null
@@ -1,9 +0,0 @@
-