From caeb9cdaf443da7fd6150cddfd4c4ac5ef4f5d60 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 19 May 2023 10:44:44 +0200 Subject: [PATCH] Remove ForbiddenTestsNamespaceOutsideTestsDirectoryRule as overly detailed --- docs/rules_overview.md | 36 +------ src/Location/DirectoryChecker.php | 14 --- ...estsNamespaceOutsideTestsDirectoryRule.php | 95 ------------------- ...estsNamespaceInsideTestsDirectoryClass.php | 10 -- ...NamespaceOutsideTestsDirectoryRuleTest.php | 44 --------- .../config/configured_rule.neon | 5 - 6 files changed, 1 insertion(+), 203 deletions(-) delete mode 100644 src/Rules/ForbiddenTestsNamespaceOutsideTestsDirectoryRule.php delete mode 100644 tests/Rules/ForbiddenTestsNamespaceOutsideTestsDirectoryRule/Fixture/tests/SkipTestsNamespaceInsideTestsDirectoryClass.php delete mode 100644 tests/Rules/ForbiddenTestsNamespaceOutsideTestsDirectoryRule/ForbiddenTestsNamespaceOutsideTestsDirectoryRuleTest.php delete mode 100644 tests/Rules/ForbiddenTestsNamespaceOutsideTestsDirectoryRule/config/configured_rule.neon diff --git a/docs/rules_overview.md b/docs/rules_overview.md index e9a00346..15d24442 100644 --- a/docs/rules_overview.md +++ b/docs/rules_overview.md @@ -1,4 +1,4 @@ -# 83 Rules Overview +# 82 Rules Overview ## AnnotateRegexClassConstWithRegexLinkRule @@ -849,40 +849,6 @@ $message = sprintf('%s', $firstValue, $secondValue);
-## ForbiddenTestsNamespaceOutsideTestsDirectoryRule - -"Tests" namespace can be only in "/tests" directory - -- class: [`Symplify\PHPStanRules\Rules\ForbiddenTestsNamespaceOutsideTestsDirectoryRule`](../src/Rules/ForbiddenTestsNamespaceOutsideTestsDirectoryRule.php) - -```php -// file path: "src/SomeClass.php" - -namespace App\Tests; - -class SomeClass -{ -} -``` - -:x: - -
- -```php -// file path: "tests/SomeClass.php" - -namespace App\Tests; - -class SomeClass -{ -} -``` - -:+1: - -
- ## ForbiddenThisArgumentRule `$this` as argument is not allowed. Refactor method to service composition diff --git a/src/Location/DirectoryChecker.php b/src/Location/DirectoryChecker.php index e5235d7f..9fda237b 100644 --- a/src/Location/DirectoryChecker.php +++ b/src/Location/DirectoryChecker.php @@ -8,20 +8,6 @@ final class DirectoryChecker { - /** - * @param string[] $directoryNames - */ - public function isInDirectoryNames(Scope $scope, array $directoryNames): bool - { - foreach ($directoryNames as $directoryName) { - if ($this->isInDirectoryNamed($scope, $directoryName)) { - return true; - } - } - - return false; - } - public function isInDirectoryNamed(Scope $scope, string $directoryName): bool { $normalized = $this->normalizePath($directoryName); diff --git a/src/Rules/ForbiddenTestsNamespaceOutsideTestsDirectoryRule.php b/src/Rules/ForbiddenTestsNamespaceOutsideTestsDirectoryRule.php deleted file mode 100644 index a421a758..00000000 --- a/src/Rules/ForbiddenTestsNamespaceOutsideTestsDirectoryRule.php +++ /dev/null @@ -1,95 +0,0 @@ - - */ - public function getNodeType(): string - { - return Namespace_::class; - } - - /** - * @param Namespace_ $node - * @return string[] - */ - public function processNode(Node $node, Scope $scope): array - { - if (! $node->name instanceof Name) { - return []; - } - - $matches = Strings::match($node->name->toString(), Regex::TESTS_PART_REGEX); - if ($matches === null) { - return []; - } - - if ($this->directoryChecker->isInDirectoryNames($scope, ['tests', 'rules-tests', 'packages-tests'])) { - return []; - } - - return [self::ERROR_MESSAGE]; - } - - public function getRuleDefinition(): RuleDefinition - { - return new RuleDefinition(self::DESCRIPTION, [ - new CodeSample( - <<<'CODE_SAMPLE' -// file path: "src/SomeClass.php" - -namespace App\Tests; - -class SomeClass -{ -} -CODE_SAMPLE - , - <<<'CODE_SAMPLE' -// file path: "tests/SomeClass.php" - -namespace App\Tests; - -class SomeClass -{ -} -CODE_SAMPLE - ), - ]); - } -} diff --git a/tests/Rules/ForbiddenTestsNamespaceOutsideTestsDirectoryRule/Fixture/tests/SkipTestsNamespaceInsideTestsDirectoryClass.php b/tests/Rules/ForbiddenTestsNamespaceOutsideTestsDirectoryRule/Fixture/tests/SkipTestsNamespaceInsideTestsDirectoryClass.php deleted file mode 100644 index f634ab45..00000000 --- a/tests/Rules/ForbiddenTestsNamespaceOutsideTestsDirectoryRule/Fixture/tests/SkipTestsNamespaceInsideTestsDirectoryClass.php +++ /dev/null @@ -1,10 +0,0 @@ -analyse([$filePath], $expectedErrorsWithLines); - } - - /** - * @return Iterator> - */ - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/tests/SkipTestsNamespaceInsideTestsDirectoryClass.php', []]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(ForbiddenTestsNamespaceOutsideTestsDirectoryRule::class); - } -} diff --git a/tests/Rules/ForbiddenTestsNamespaceOutsideTestsDirectoryRule/config/configured_rule.neon b/tests/Rules/ForbiddenTestsNamespaceOutsideTestsDirectoryRule/config/configured_rule.neon deleted file mode 100644 index b4a4244b..00000000 --- a/tests/Rules/ForbiddenTestsNamespaceOutsideTestsDirectoryRule/config/configured_rule.neon +++ /dev/null @@ -1,5 +0,0 @@ -includes: - - ../../../config/included_services.neon - -rules: - - Symplify\PHPStanRules\Rules\ForbiddenTestsNamespaceOutsideTestsDirectoryRule