diff --git a/docs/rules_overview.md b/docs/rules_overview.md index 24ebb267..e9a00346 100644 --- a/docs/rules_overview.md +++ b/docs/rules_overview.md @@ -1,4 +1,4 @@ -# 84 Rules Overview +# 83 Rules Overview ## AnnotateRegexClassConstWithRegexLinkRule @@ -720,45 +720,6 @@ return strlen('name');
-## ForbiddenNestedCallInAssertMethodCallRule - -Decouple method call in assert to standalone line to make test core more readable - -- class: [`Symplify\PHPStanRules\Rules\ForbiddenNestedCallInAssertMethodCallRule`](../src/Rules/ForbiddenNestedCallInAssertMethodCallRule.php) - -```php -use PHPUnit\Framework\TestCase; - -final class SomeClass extends TestCase -{ - public function test() - { - $this->assertSame('oooo', $this->someMethodCall()); - } -} -``` - -:x: - -
- -```php -use PHPUnit\Framework\TestCase; - -final class SomeClass extends TestCase -{ - public function test() - { - $result = $this->someMethodCall(); - $this->assertSame('oooo', $result); - } -} -``` - -:+1: - -
- ## ForbiddenNodeRule "%s" is forbidden to use diff --git a/src/Rules/ForbiddenNestedCallInAssertMethodCallRule.php b/src/Rules/ForbiddenNestedCallInAssertMethodCallRule.php deleted file mode 100644 index eda0b39b..00000000 --- a/src/Rules/ForbiddenNestedCallInAssertMethodCallRule.php +++ /dev/null @@ -1,111 +0,0 @@ - - */ - public function getNodeType(): string - { - return MethodCall::class; - } - - /** - * @param MethodCall $node - * @return string[] - */ - public function processNode(Node $node, Scope $scope): array - { - if (! $node->name instanceof Identifier) { - return []; - } - - $methodName = $node->name->toString(); - if ($this->shouldSkipMethodName($methodName, $node)) { - return []; - } - - $argMethodCall = $this->nodeFinder->findFirstInstanceOf($node->getArgs()[1], MethodCall::class); - if (! $argMethodCall instanceof MethodCall) { - return []; - } - - if ($argMethodCall->getArgs() === []) { - return []; - } - - return [self::ERROR_MESSAGE]; - } - - public function getRuleDefinition(): RuleDefinition - { - return new RuleDefinition(self::ERROR_MESSAGE, [ - new CodeSample( - <<<'CODE_SAMPLE' -use PHPUnit\Framework\TestCase; - -final class SomeClass extends TestCase -{ - public function test() - { - $this->assertSame('oooo', $this->someMethodCall()); - } -} -CODE_SAMPLE - , - <<<'CODE_SAMPLE' -use PHPUnit\Framework\TestCase; - -final class SomeClass extends TestCase -{ - public function test() - { - $result = $this->someMethodCall(); - $this->assertSame('oooo', $result); - } -} -CODE_SAMPLE - ), - ]); - } - - private function shouldSkipMethodName(string $methodName, MethodCall $methodCall): bool - { - if (! \str_starts_with($methodName, 'assert')) { - return true; - } - - if (in_array($methodName, ['assertTrue', 'assertFalse'], true)) { - return true; - } - - return count($methodCall->getArgs()) <= 1; - } -} diff --git a/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/Fixture/NestedAssertMethodCall.php b/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/Fixture/NestedAssertMethodCall.php deleted file mode 100644 index efe43bbe..00000000 --- a/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/Fixture/NestedAssertMethodCall.php +++ /dev/null @@ -1,16 +0,0 @@ -assertSame('...', $values->run(1000)); - } -} diff --git a/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/Fixture/SkipAssertNothing.php b/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/Fixture/SkipAssertNothing.php deleted file mode 100644 index b27cfc14..00000000 --- a/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/Fixture/SkipAssertNothing.php +++ /dev/null @@ -1,13 +0,0 @@ -assertNothing(); - } -} diff --git a/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/Fixture/SkipAssertTrue.php b/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/Fixture/SkipAssertTrue.php deleted file mode 100644 index 266de36e..00000000 --- a/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/Fixture/SkipAssertTrue.php +++ /dev/null @@ -1,16 +0,0 @@ -assertTrue($values->run(1000)); - } -} diff --git a/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/Fixture/SkipCleanAssert.php b/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/Fixture/SkipCleanAssert.php deleted file mode 100644 index b6196647..00000000 --- a/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/Fixture/SkipCleanAssert.php +++ /dev/null @@ -1,14 +0,0 @@ -assertSame('...', $values); - } -} diff --git a/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/Fixture/SkipSimpleGetter.php b/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/Fixture/SkipSimpleGetter.php deleted file mode 100644 index e24ece5f..00000000 --- a/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/Fixture/SkipSimpleGetter.php +++ /dev/null @@ -1,16 +0,0 @@ -assertSame('...', $values->run()); - } -} diff --git a/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/ForbiddenNestedCallInAssertMethodCallRuleTest.php b/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/ForbiddenNestedCallInAssertMethodCallRuleTest.php deleted file mode 100644 index 7148ded0..00000000 --- a/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/ForbiddenNestedCallInAssertMethodCallRuleTest.php +++ /dev/null @@ -1,48 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/SkipAssertNothing.php', []]; - yield [__DIR__ . '/Fixture/SkipCleanAssert.php', []]; - yield [__DIR__ . '/Fixture/SkipSimpleGetter.php', []]; - yield [__DIR__ . '/Fixture/SkipAssertTrue.php', []]; - - yield [__DIR__ . '/Fixture/NestedAssertMethodCall.php', [ - [ForbiddenNestedCallInAssertMethodCallRule::ERROR_MESSAGE, 14], - ]]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(ForbiddenNestedCallInAssertMethodCallRule::class); - } -} diff --git a/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/Source/AnyOtherObject.php b/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/Source/AnyOtherObject.php deleted file mode 100644 index 6be9584f..00000000 --- a/tests/Rules/ForbiddenNestedCallInAssertMethodCallRule/Source/AnyOtherObject.php +++ /dev/null @@ -1,12 +0,0 @@ -