diff --git a/bin/rector.php b/bin/rector.php index d68ff9e851d..d09d40fc444 100755 --- a/bin/rector.php +++ b/bin/rector.php @@ -106,11 +106,8 @@ public function loadIfExistsAndNotLoadedYet(string $filePath): void return; } + /** @var string $realPath always string after file_exists() check */ $realPath = realpath($filePath); - if (! is_string($realPath)) { - return; - } - $this->alreadyLoadedAutoloadFiles[] = $realPath; require_once $filePath; diff --git a/packages/Caching/Detector/ChangedFilesDetector.php b/packages/Caching/Detector/ChangedFilesDetector.php index a49557d1c97..691216ffb1b 100644 --- a/packages/Caching/Detector/ChangedFilesDetector.php +++ b/packages/Caching/Detector/ChangedFilesDetector.php @@ -85,6 +85,7 @@ public function setFirstResolvedConfigFileInfo(string $filePath): void private function resolvePath(string $filePath): string { + /** @var string|false $realPath */ $realPath = realpath($filePath); if ($realPath === false) { diff --git a/packages/Config/RectorConfig.php b/packages/Config/RectorConfig.php index 1233a4ce06a..f27d1be36f8 100644 --- a/packages/Config/RectorConfig.php +++ b/packages/Config/RectorConfig.php @@ -373,10 +373,12 @@ private function isRuleNoLongerExists(mixed $skipRule): bool is_string($skipRule) // not regex path && ! str_contains($skipRule, '*') - // not realpath - && realpath($skipRule) === false // a Rector end && str_ends_with($skipRule, 'Rector') + // not directory + && ! is_dir($skipRule) + // not file + && ! is_file($skipRule) // class not exists && ! class_exists($skipRule); } diff --git a/packages/Skipper/FileSystem/FnMatchPathNormalizer.php b/packages/Skipper/FileSystem/FnMatchPathNormalizer.php index 88d78d2a314..98f1737bc5f 100644 --- a/packages/Skipper/FileSystem/FnMatchPathNormalizer.php +++ b/packages/Skipper/FileSystem/FnMatchPathNormalizer.php @@ -16,6 +16,7 @@ public function normalizeForFnmatch(string $path): string } if (\str_contains($path, '..')) { + /** @var string|false $path */ $path = realpath($path); if ($path === false) { return ''; diff --git a/packages/Skipper/RealpathMatcher.php b/packages/Skipper/RealpathMatcher.php index 476a6f59d68..5f50e12b989 100644 --- a/packages/Skipper/RealpathMatcher.php +++ b/packages/Skipper/RealpathMatcher.php @@ -8,11 +8,13 @@ final class RealpathMatcher { public function match(string $matchingPath, string $filePath): bool { + /** @var string|false $realPathMatchingPath */ $realPathMatchingPath = realpath($matchingPath); if (! is_string($realPathMatchingPath)) { return false; } + /** @var string|false $realpathFilePath */ $realpathFilePath = realpath($filePath); if (! is_string($realpathFilePath)) { return false; diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromReturnNewRector/Fixture/fallback_from_param.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromReturnNewRector/Fixture/fallback_from_param.php.inc new file mode 100644 index 00000000000..ab4b0483d50 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromReturnNewRector/Fixture/fallback_from_param.php.inc @@ -0,0 +1,43 @@ + +----- + diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromReturnNewRector/Fixture/fallback_from_param_self.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromReturnNewRector/Fixture/fallback_from_param_self.php.inc new file mode 100644 index 00000000000..efebf7e45a3 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromReturnNewRector/Fixture/fallback_from_param_self.php.inc @@ -0,0 +1,39 @@ + +----- + diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromReturnNewRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromReturnNewRector.php index 7a2b90a1a14..d73b9c9d01e 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromReturnNewRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromReturnNewRector.php @@ -5,6 +5,7 @@ namespace Rector\TypeDeclaration\Rector\ClassMethod; use PhpParser\Node; +use PhpParser\Node\Expr; use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\New_; @@ -200,7 +201,17 @@ private function resolveReturnNewType(array $returns): ?array { $newTypes = []; foreach ($returns as $return) { + if (! $return->expr instanceof Expr) { + return null; + } + if (! $return->expr instanceof New_) { + $returnType = $this->nodeTypeResolver->getNativeType($return->expr); + if ($returnType instanceof ObjectType) { + $newTypes[] = $returnType; + continue; + } + return null; } diff --git a/src/Autoloading/BootstrapFilesIncluder.php b/src/Autoloading/BootstrapFilesIncluder.php index c81e973bcda..b908776a191 100644 --- a/src/Autoloading/BootstrapFilesIncluder.php +++ b/src/Autoloading/BootstrapFilesIncluder.php @@ -41,6 +41,7 @@ public function includeBootstrapFiles(): void private function requireRectorStubs(): void { + /** @var false|string $stubsRectorDirectory */ $stubsRectorDirectory = realpath(__DIR__ . '/../../stubs-rector'); if ($stubsRectorDirectory === false) { return; diff --git a/utils/Command/MissingInSetCommand.php b/utils/Command/MissingInSetCommand.php index b4d9ef34cbd..14b44aa9a49 100644 --- a/utils/Command/MissingInSetCommand.php +++ b/utils/Command/MissingInSetCommand.php @@ -141,7 +141,9 @@ static function (string $rectorClass): bool { $hasError = true; $this->symfonyStyle->title('We could not find there rules in configs'); - $setRealpath = (string) realpath($setFile); + /** @var string|false $setRealpath */ + $setRealpath = realpath($setFile); + $setRealpath = (string) $setRealpath; $relativeFilePath = Strings::after($setRealpath, getcwd() . '/'); $this->symfonyStyle->writeln(' * ' . $relativeFilePath);