diff --git a/config/static-rules.neon b/config/static-rules.neon index 11f0b06a..5fc2bbb8 100644 --- a/config/static-rules.neon +++ b/config/static-rules.neon @@ -30,7 +30,6 @@ rules: - Symplify\PHPStanRules\Rules\NoDefaultExceptionRule - Symplify\PHPStanRules\Rules\NoParentMethodCallOnNoOverrideProcessRule - Symplify\PHPStanRules\Rules\RequireThisOnParentMethodCallRule - - Symplify\PHPStanRules\Rules\RequireThisCallOnLocalMethodRule - Symplify\PHPStanRules\Rules\ForbiddenMultipleClassLikeInOneFileRule # comlexity diff --git a/docs/rules_overview.md b/docs/rules_overview.md index a590de4f..49888ce5 100644 --- a/docs/rules_overview.md +++ b/docs/rules_overview.md @@ -1,4 +1,4 @@ -# 88 Rules Overview +# 87 Rules Overview ## AnnotateRegexClassConstWithRegexLinkRule @@ -2922,48 +2922,6 @@ final class IssueControl extends Control
-## RequireThisCallOnLocalMethodRule - -Use "$this->()" instead of "self::()" to call local method - -- class: [`Symplify\PHPStanRules\Rules\RequireThisCallOnLocalMethodRule`](../src/Rules/RequireThisCallOnLocalMethodRule.php) - -```php -class SomeClass -{ - public function run() - { - self::execute(); - } - - private function execute() - { - } -} -``` - -:x: - -
- -```php -class SomeClass -{ - public function run() - { - $this->execute(); - } - - private function execute() - { - } -} -``` - -:+1: - -
- ## RequireThisOnParentMethodCallRule Use "$this->()" instead of "parent::()" unless in the same named method diff --git a/src/Rules/RequireThisCallOnLocalMethodRule.php b/src/Rules/RequireThisCallOnLocalMethodRule.php deleted file mode 100644 index 837c056e..00000000 --- a/src/Rules/RequireThisCallOnLocalMethodRule.php +++ /dev/null @@ -1,133 +0,0 @@ - - */ -final class RequireThisCallOnLocalMethodRule implements Rule, DocumentedRuleInterface -{ - /** - * @var string - */ - public const ERROR_MESSAGE = 'Use "$this->()" instead of "self::()" to call local method'; - - public function __construct( - private readonly NodeFinder $nodeFinder - ) { - } - - /** - * @return class-string - */ - public function getNodeType(): string - { - return InClassNode::class; - } - - /** - * @param InClassNode $node - * @return RuleError[] - */ - public function processNode(Node $node, Scope $scope): array - { - $classLike = $node->getOriginalNode(); - if (! $classLike instanceof Class_) { - return []; - } - - $errorMessages = []; - - /** @var StaticCall[] $staticCalls */ - $staticCalls = $this->nodeFinder->findInstanceOf($classLike, StaticCall::class); - foreach ($staticCalls as $staticCall) { - if (! $staticCall->class instanceof Name) { - continue; - } - - $staticCallClass = $staticCall->class->toString(); - if ($staticCallClass !== 'self') { - continue; - } - - $classMethod = $this->getClassMethodInCurrentClass($staticCall, $classLike); - if (! $classMethod instanceof ClassMethod) { - continue; - } - - if ($classMethod->isStatic()) { - continue; - } - - $errorMessages[] = RuleErrorBuilder::message(self::ERROR_MESSAGE) - ->line($staticCall->getLine()) - ->build(); - } - - return $errorMessages; - } - - public function getRuleDefinition(): RuleDefinition - { - return new RuleDefinition(self::ERROR_MESSAGE, [ - new CodeSample( - <<<'CODE_SAMPLE' -class SomeClass -{ - public function run() - { - self::execute(); - } - - private function execute() - { - } -} -CODE_SAMPLE - , - <<<'CODE_SAMPLE' -class SomeClass -{ - public function run() - { - $this->execute(); - } - - private function execute() - { - } -} -CODE_SAMPLE - ), - ]); - } - - private function getClassMethodInCurrentClass(StaticCall $staticCall, Class_ $class): ?ClassMethod - { - if (! $staticCall->name instanceof Identifier) { - return null; - } - - $staticCallName = $staticCall->name->toString(); - return $class->getMethod($staticCallName); - } -} diff --git a/tests/Rules/RequireThisCallOnLocalMethodRule/Fixture/CallLocalMethod.php b/tests/Rules/RequireThisCallOnLocalMethodRule/Fixture/CallLocalMethod.php deleted file mode 100644 index b9d31d2a..00000000 --- a/tests/Rules/RequireThisCallOnLocalMethodRule/Fixture/CallLocalMethod.php +++ /dev/null @@ -1,17 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/SkipCallParentMethodStatically.php', []]; - yield [__DIR__ . '/Fixture/SkipCallLocalStaticMethod.php', []]; - yield [__DIR__ . '/Fixture/CallLocalMethod.php', [[RequireThisCallOnLocalMethodRule::ERROR_MESSAGE, 11]]]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(RequireThisCallOnLocalMethodRule::class); - } -} diff --git a/tests/Rules/RequireThisCallOnLocalMethodRule/config/configured_rule.neon b/tests/Rules/RequireThisCallOnLocalMethodRule/config/configured_rule.neon deleted file mode 100644 index 1ca55fc7..00000000 --- a/tests/Rules/RequireThisCallOnLocalMethodRule/config/configured_rule.neon +++ /dev/null @@ -1,5 +0,0 @@ -includes: - - ../../../config/included_services.neon - -rules: - - Symplify\PHPStanRules\Rules\RequireThisCallOnLocalMethodRule