From b333751ac8f009c019c9e621cbcfc89faacc42f0 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 19 May 2023 10:27:27 +0200 Subject: [PATCH] Remove RequireThisCallOnLocalMethodRule, as not practical --- config/static-rules.neon | 1 - docs/rules_overview.md | 44 +----- .../RequireThisCallOnLocalMethodRule.php | 133 ------------------ .../Fixture/CallLocalMethod.php | 17 --- .../Fixture/ParentClass.php | 18 --- .../Fixture/SkipCallLocalStaticMethod.php | 17 --- .../SkipCallParentMethodStatically.php | 14 -- .../RequireThisCallOnLocalMethodRuleTest.php | 43 ------ .../config/configured_rule.neon | 5 - 9 files changed, 1 insertion(+), 291 deletions(-) delete mode 100644 src/Rules/RequireThisCallOnLocalMethodRule.php delete mode 100644 tests/Rules/RequireThisCallOnLocalMethodRule/Fixture/CallLocalMethod.php delete mode 100644 tests/Rules/RequireThisCallOnLocalMethodRule/Fixture/ParentClass.php delete mode 100644 tests/Rules/RequireThisCallOnLocalMethodRule/Fixture/SkipCallLocalStaticMethod.php delete mode 100644 tests/Rules/RequireThisCallOnLocalMethodRule/Fixture/SkipCallParentMethodStatically.php delete mode 100644 tests/Rules/RequireThisCallOnLocalMethodRule/RequireThisCallOnLocalMethodRuleTest.php delete mode 100644 tests/Rules/RequireThisCallOnLocalMethodRule/config/configured_rule.neon diff --git a/config/static-rules.neon b/config/static-rules.neon index 86aa0241..5766a68c 100644 --- a/config/static-rules.neon +++ b/config/static-rules.neon @@ -29,7 +29,6 @@ rules: # explicit naming - Symplify\PHPStanRules\Rules\NoDefaultExceptionRule - Symplify\PHPStanRules\Rules\NoParentMethodCallOnNoOverrideProcessRule - - Symplify\PHPStanRules\Rules\RequireThisCallOnLocalMethodRule - Symplify\PHPStanRules\Rules\ForbiddenMultipleClassLikeInOneFileRule # comlexity diff --git a/docs/rules_overview.md b/docs/rules_overview.md index 2909e050..6d9ad243 100644 --- a/docs/rules_overview.md +++ b/docs/rules_overview.md @@ -1,4 +1,4 @@ -# 87 Rules Overview +# 86 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: - -
- ## RequireUniqueEnumConstantRule Enum constants "%s" are duplicated. Make them unique instead 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