diff --git a/config/static-rules.neon b/config/static-rules.neon index 8f254f14..9618f7e1 100644 --- a/config/static-rules.neon +++ b/config/static-rules.neon @@ -8,7 +8,6 @@ rules: - Symplify\PHPStanRules\Rules\PreventParentMethodVisibilityOverrideRule # paths - - Symplify\PHPStanRules\Rules\NoMissingDirPathRule - Symplify\PHPStanRules\Rules\NoReferenceRule - Symplify\PHPStanRules\Rules\NoNullableArrayPropertyRule diff --git a/src/NodeVisitor/FlatConcatFindingNodeVisitor.php b/src/NodeVisitor/FlatConcatFindingNodeVisitor.php deleted file mode 100644 index 3271c703..00000000 --- a/src/NodeVisitor/FlatConcatFindingNodeVisitor.php +++ /dev/null @@ -1,63 +0,0 @@ -foundNodes = []; - return null; - } - - public function enterNode(Node $node): int|Node|null - { - if ($this->fileCheckingFuncCallAnalyzer->isFileExistCheck($node)) { - return NodeTraverser::DONT_TRAVERSE_CHILDREN; - } - - if (! $node instanceof Concat) { - return null; - } - - if ($node->left instanceof Concat) { - return NodeTraverser::DONT_TRAVERSE_CHILDREN; - } - - if ($node->right instanceof Concat) { - return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; - } - - $this->foundNodes[] = $node; - return null; - } - - /** - * @return Concat[] - */ - public function getFoundNodes(): array - { - return $this->foundNodes; - } -} diff --git a/src/Rules/NoMissingDirPathRule.php b/src/Rules/NoMissingDirPathRule.php deleted file mode 100644 index acf8ef63..00000000 --- a/src/Rules/NoMissingDirPathRule.php +++ /dev/null @@ -1,144 +0,0 @@ - - */ - public function getNodeType(): string - { - return InClassNode::class; - } - - /** - * @param InClassNode $node - * @return RuleError[] - */ - public function processNode(Node $node, Scope $scope): array - { - $classLike = $node->getOriginalNode(); - - $classReflection = $scope->getClassReflection(); - if (! $classReflection instanceof ClassReflection) { - return []; - } - - // test fixture can exist or not, better skip this case to avoid false positives - if ($classReflection->isSubclassOf(TestCase::class)) { - return []; - } - - // mimics node finding visitors of NodeFinder with ability to stop traversing deeper - $nodeTraverser = new NodeTraverser(); - $flatConcatFindingNodeVisitor = new FlatConcatFindingNodeVisitor(new FileCheckingFuncCallAnalyzer()); - - $nodeTraverser->addVisitor($flatConcatFindingNodeVisitor); - $nodeTraverser->traverse($classLike->stmts); - - $concats = $flatConcatFindingNodeVisitor->getFoundNodes(); - $errorMessages = []; - - foreach ($concats as $concat) { - if (! $concat->left instanceof Dir) { - return []; - } - - if (! $concat->right instanceof String_) { - return []; - } - - $string = $concat->right; - $relativeDirPath = $string->value; - - if ($this->shouldSkip($relativeDirPath)) { - continue; - } - - $realDirectory = dirname($scope->getFile()); - $fileRealPath = $realDirectory . $relativeDirPath; - - if (file_exists($fileRealPath)) { - continue; - } - - $errorMessages[] = RuleErrorBuilder::message(sprintf(self::ERROR_MESSAGE, $relativeDirPath)) - ->line($concat->getLine()) - ->build(); - } - - return $errorMessages; - } - - public function getRuleDefinition(): RuleDefinition - { - return new RuleDefinition(self::ERROR_MESSAGE, [ - new CodeSample( - <<<'CODE_SAMPLE' -$filePath = __DIR__ . '/missing_location.txt'; -CODE_SAMPLE - , - <<<'CODE_SAMPLE' -$filePath = __DIR__ . '/existing_location.txt'; -CODE_SAMPLE - ), - ]); - } - - private function shouldSkip(string $relativeDirPath): bool - { - // is vendor autolaod? it yet to be exist - if (Strings::match($relativeDirPath, self::VENDOR_REGEX)) { - return true; - } - - if (\str_contains($relativeDirPath, '*')) { - return true; - } - - $bracketMatches = Strings::match($relativeDirPath, self::BRACKET_PATH_REGEX); - return $bracketMatches !== null; - } -} diff --git a/tests/Rules/NoMissingDirPathRule/Fixture/FileMissing.php b/tests/Rules/NoMissingDirPathRule/Fixture/FileMissing.php deleted file mode 100644 index 6910d282..00000000 --- a/tests/Rules/NoMissingDirPathRule/Fixture/FileMissing.php +++ /dev/null @@ -1,13 +0,0 @@ -assertFileExists(__DIR__ . '/../PotentialFile.php'); - $this->assertFileNotExists(__DIR__ . '/../../PotentialFile.php'); - - if (method_exists($this, 'assertFileDoesNotExist')) { - $this->assertFileDoesNotExist(__DIR__ . '/temp/file.php'); - } else { - $this->assertFileNotExists(__DIR__ . '/temp/file.php'); - } - - $possibleFile = __DIR__ . '/Whatever'; - } -} diff --git a/tests/Rules/NoMissingDirPathRule/Fixture/SkipBracketPathFromSymfonyConfigImport.php b/tests/Rules/NoMissingDirPathRule/Fixture/SkipBracketPathFromSymfonyConfigImport.php deleted file mode 100644 index f3bede11..00000000 --- a/tests/Rules/NoMissingDirPathRule/Fixture/SkipBracketPathFromSymfonyConfigImport.php +++ /dev/null @@ -1,13 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - $message = sprintf(NoMissingDirPathRule::ERROR_MESSAGE, '/not_here.php'); - yield [__DIR__ . '/Fixture/FileMissing.php', [[$message, 11]]]; - - yield [__DIR__ . '/Fixture/SkipBracketPathFromSymfonyConfigImport.php', []]; - yield [__DIR__ . '/Fixture/SkipConcat.php', []]; - yield [__DIR__ . '/Fixture/SkipVendorAutoload.php', []]; - yield [__DIR__ . '/Fixture/SkipVendorAutoload.php', []]; - yield [__DIR__ . '/Fixture/SkipAssertMethod.php', []]; - yield [__DIR__ . '/Fixture/SkipFnMatch.php', []]; - yield [__DIR__ . '/Fixture/SkipFileExistsFuncCall.php', []]; - yield [__DIR__ . '/Fixture/SkipFileExistsFuncCallOneLayerAbove.php', []]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(NoMissingDirPathRule::class); - } -} diff --git a/tests/Rules/NoMissingDirPathRule/config/configured_rule.neon b/tests/Rules/NoMissingDirPathRule/config/configured_rule.neon deleted file mode 100644 index fa682f0c..00000000 --- a/tests/Rules/NoMissingDirPathRule/config/configured_rule.neon +++ /dev/null @@ -1,5 +0,0 @@ -includes: - - ../../../config/included_services.neon - -rules: - - Symplify\PHPStanRules\Rules\NoMissingDirPathRule