diff --git a/lib/Extension/ClassMover/Application/Finder/FileFinder.php b/lib/Extension/ClassMover/Application/Finder/FileFinder.php index a62f289c7..4a8e62210 100644 --- a/lib/Extension/ClassMover/Application/Finder/FileFinder.php +++ b/lib/Extension/ClassMover/Application/Finder/FileFinder.php @@ -41,8 +41,8 @@ public function filesFor(Filesystem $filesystem, ReflectionClassLike $reflection // we have public members or a non-class, we need to search the // whole tree, but we can discount any files which do not contain // the member name string. - return $this->allPhpFiles($filesystem)->filter(function (SplFileInfo $file) use ($memberName) { - return preg_match('{' . $memberName . '}', file_get_contents($file->getPathname())); + return $this->allPhpFiles($filesystem)->filter(function (SplFileInfo $file) use ($memberName): bool { + return preg_match('{' . $memberName . '}', file_get_contents($file->getPathname())) === 1; }); } @@ -57,12 +57,14 @@ public function filesFor(Filesystem $filesystem, ReflectionClassLike $reflection return $this->pathsFromReflectionClass($reflection, $private); } - private function pathsFromReflectionClass(ReflectionClass $reflection, bool $private) + private function pathsFromReflectionClass(ReflectionClass $reflection, bool $private): FileList { $path = $reflection->sourceCode()->uri()?->path(); if (!$path) { - throw new RuntimeException('Source has no path associated with it'); + throw new RuntimeException( + sprintf('Source class "%s" has no path associated with it', $reflection->name()), + ); } $filePaths = [ $path ]; @@ -78,35 +80,61 @@ private function pathsFromReflectionClass(ReflectionClass $reflection, bool $pri return FileList::fromFilePaths($filePaths); } - private function allPhpFiles(Filesystem $filesystem) + private function allPhpFiles(Filesystem $filesystem): FileList { - $filePaths = $filesystem->fileList()->existing()->phpFiles(); - return $filePaths; + return $filesystem->fileList()->existing()->phpFiles(); } - private function parentFilePaths(ReflectionClass $reflection, $filePaths) + /** + * @param array $filePaths + * + * @return array + */ + private function parentFilePaths(ReflectionClass $reflection, array $filePaths): array { $context = $reflection->parent(); while ($context) { - $filePaths[] = $context->sourceCode()->uri()?->path(); + $path = $context->sourceCode()->uri()?->path(); + if ($path === null) { + continue; + } + $filePaths[] = $path; $context = $context->parent(); } return $filePaths; } - private function traitFilePaths(ReflectionClass $reflection, $filePaths) + /** + * @param array $filePaths + * + * @return array + */ + private function traitFilePaths(ReflectionClass $reflection, array $filePaths): array { foreach ($reflection->traits() as $trait) { - $filePaths[] = $trait->sourceCode()->uri()?->path(); + $path = $trait->sourceCode()->uri()?->path(); + if ($path === null) { + continue; + } + $filePaths[] = $path; } return $filePaths; } - private function interfaceFilePaths(ReflectionClass $reflection, $filePaths) + /** + * @param array $filePaths + * + * @return array + */ + private function interfaceFilePaths(ReflectionClass $reflection, array $filePaths): array { foreach ($reflection->interfaces() as $interface) { - $filePaths[] = $interface->sourceCode()->uri()?->path(); + $path = $interface->sourceCode()->uri()?->path(); + if ($path === null) { + continue; + } + $filePaths[] = $path; } return $filePaths; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 41a723716..b025e7879 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1295,46 +1295,6 @@ parameters: count: 1 path: lib/Extension/ClassMover/Application/ClassReferences.php - - - message: "#^Method Phpactor\\\\Extension\\\\ClassMover\\\\Application\\\\Finder\\\\FileFinder\\:\\:allPhpFiles\\(\\) has no return type specified\\.$#" - count: 1 - path: lib/Extension/ClassMover/Application/Finder/FileFinder.php - - - - message: "#^Method Phpactor\\\\Extension\\\\ClassMover\\\\Application\\\\Finder\\\\FileFinder\\:\\:interfaceFilePaths\\(\\) has no return type specified\\.$#" - count: 1 - path: lib/Extension/ClassMover/Application/Finder/FileFinder.php - - - - message: "#^Method Phpactor\\\\Extension\\\\ClassMover\\\\Application\\\\Finder\\\\FileFinder\\:\\:interfaceFilePaths\\(\\) has parameter \\$filePaths with no type specified\\.$#" - count: 1 - path: lib/Extension/ClassMover/Application/Finder/FileFinder.php - - - - message: "#^Method Phpactor\\\\Extension\\\\ClassMover\\\\Application\\\\Finder\\\\FileFinder\\:\\:parentFilePaths\\(\\) has no return type specified\\.$#" - count: 1 - path: lib/Extension/ClassMover/Application/Finder/FileFinder.php - - - - message: "#^Method Phpactor\\\\Extension\\\\ClassMover\\\\Application\\\\Finder\\\\FileFinder\\:\\:parentFilePaths\\(\\) has parameter \\$filePaths with no type specified\\.$#" - count: 1 - path: lib/Extension/ClassMover/Application/Finder/FileFinder.php - - - - message: "#^Method Phpactor\\\\Extension\\\\ClassMover\\\\Application\\\\Finder\\\\FileFinder\\:\\:pathsFromReflectionClass\\(\\) has no return type specified\\.$#" - count: 1 - path: lib/Extension/ClassMover/Application/Finder/FileFinder.php - - - - message: "#^Method Phpactor\\\\Extension\\\\ClassMover\\\\Application\\\\Finder\\\\FileFinder\\:\\:traitFilePaths\\(\\) has no return type specified\\.$#" - count: 1 - path: lib/Extension/ClassMover/Application/Finder/FileFinder.php - - - - message: "#^Method Phpactor\\\\Extension\\\\ClassMover\\\\Application\\\\Finder\\\\FileFinder\\:\\:traitFilePaths\\(\\) has parameter \\$filePaths with no type specified\\.$#" - count: 1 - path: lib/Extension/ClassMover/Application/Finder/FileFinder.php - - message: "#^Parameter \\#2 \\$subject of function preg_match expects string, string\\|false given\\.$#" count: 1