diff --git a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php index 01eb6e67b..d163845ee 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php @@ -298,7 +298,6 @@ class ReturnTypeAnalyzer $project_analyzer, $inferred_return_type, $source, - $function_like_analyzer, ($project_analyzer->only_replace_php_types_with_non_docblock_types || $unsafe_return_type) && $inferred_return_type->from_docblock, @@ -336,7 +335,6 @@ class ReturnTypeAnalyzer $project_analyzer, $inferred_return_type, $source, - $function_like_analyzer, $compatible_method_ids || !$did_explicitly_return || (($project_analyzer->only_replace_php_types_with_non_docblock_types @@ -407,7 +405,6 @@ class ReturnTypeAnalyzer $project_analyzer, Type::getVoid(), $source, - $function_like_analyzer, $compatible_method_ids || (($project_analyzer->only_replace_php_types_with_non_docblock_types || $unsafe_return_type) @@ -505,7 +502,6 @@ class ReturnTypeAnalyzer $project_analyzer, $inferred_return_type, $source, - $function_like_analyzer, ($project_analyzer->only_replace_php_types_with_non_docblock_types || $unsafe_return_type) && $inferred_return_type->from_docblock, @@ -547,7 +543,6 @@ class ReturnTypeAnalyzer $project_analyzer, $inferred_return_type, $source, - $function_like_analyzer, $compatible_method_ids || (($project_analyzer->only_replace_php_types_with_non_docblock_types || $unsafe_return_type) @@ -607,7 +602,6 @@ class ReturnTypeAnalyzer $project_analyzer, $inferred_return_type, $source, - $function_like_analyzer, ($project_analyzer->only_replace_php_types_with_non_docblock_types || $unsafe_return_type) && $inferred_return_type->from_docblock, @@ -644,7 +638,6 @@ class ReturnTypeAnalyzer $project_analyzer, $inferred_return_type, $source, - $function_like_analyzer, ($project_analyzer->only_replace_php_types_with_non_docblock_types || $unsafe_return_type) && $inferred_return_type->from_docblock, @@ -821,8 +814,7 @@ class ReturnTypeAnalyzer $function, $project_analyzer, $storage->signature_return_type, - $function_like_analyzer->getSource(), - $function_like_analyzer + $function_like_analyzer->getSource() ); return null; @@ -853,14 +845,12 @@ class ReturnTypeAnalyzer ProjectAnalyzer $project_analyzer, Type\Union $inferred_return_type, StatementsSource $source, - FunctionLikeAnalyzer $function_like_analyzer, $docblock_only = false, FunctionLikeStorage $function_like_storage = null ) { $manipulator = FunctionDocblockManipulator::getForFunction( $project_analyzer, $source->getFilePath(), - $function_like_analyzer->getId(), $function ); diff --git a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php index 54337684d..8547e1370 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php @@ -589,7 +589,6 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer $manipulator = FunctionDocblockManipulator::getForFunction( $project_analyzer, $this->source->getFilePath(), - $this->getId(), $this->function ); @@ -1501,7 +1500,6 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer $manipulator = FunctionDocblockManipulator::getForFunction( $project_analyzer, $this->source->getFilePath(), - $this->getId(), $this->function ); diff --git a/src/Psalm/Internal/Codebase/Analyzer.php b/src/Psalm/Internal/Codebase/Analyzer.php index a68407955..1f9887da9 100644 --- a/src/Psalm/Internal/Codebase/Analyzer.php +++ b/src/Psalm/Internal/Codebase/Analyzer.php @@ -59,7 +59,8 @@ use function array_values; * possible_method_param_types: array>, * taint_data: ?\Psalm\Internal\Codebase\Taint, * unused_suppressions: array>, - * used_suppressions: array> + * used_suppressions: array>, + * manipulators: array>, * } */ @@ -466,6 +467,7 @@ class Analyzer 'taint_data' => $codebase->taint, 'unused_suppressions' => $codebase->track_unused_suppressions ? IssueBuffer::getUnusedSuppressions() : [], 'used_suppressions' => $codebase->track_unused_suppressions ? IssueBuffer::getUsedSuppressions() : [], + 'manipulators' => FunctionDocblockManipulator::getManipulators(), ]; // @codingStandardsIgnoreEnd }, @@ -530,6 +532,8 @@ class Analyzer $pool_data['class_property_locations'] ); + FunctionDocblockManipulator::addManipulators($pool_data['manipulators']); + $this->analyzed_methods = array_merge($pool_data['analyzed_methods'], $this->analyzed_methods); foreach ($pool_data['mixed_counts'] as $file_path => list($mixed_count, $nonmixed_count)) { diff --git a/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php b/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php index 781448a06..4a649b3f5 100644 --- a/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php +++ b/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php @@ -28,15 +28,12 @@ use function reset; */ class FunctionDocblockManipulator { - /** @var array> */ - private static $manipulators = []; - /** * Manipulators ordered by line number * * @var array> */ - private static $ordered_manipulators = []; + private static $manipulators = []; /** @var Closure|Function_|ClassMethod|ArrowFunction */ private $stmt; @@ -97,7 +94,6 @@ class FunctionDocblockManipulator /** * @param string $file_path - * @param string $function_id * @param Closure|Function_|ClassMethod|ArrowFunction $stmt * * @return self @@ -105,16 +101,14 @@ class FunctionDocblockManipulator public static function getForFunction( ProjectAnalyzer $project_analyzer, $file_path, - $function_id, FunctionLike $stmt ) { - if (isset(self::$manipulators[$file_path][$function_id])) { - return self::$manipulators[$file_path][$function_id]; + if (isset(self::$manipulators[$file_path][$stmt->getLine()])) { + return self::$manipulators[$file_path][$stmt->getLine()]; } $manipulator - = self::$manipulators[$file_path][$function_id] - = self::$ordered_manipulators[$file_path][$stmt->getLine()] + = self::$manipulators[$file_path][$stmt->getLine()] = new self($file_path, $stmt, $project_analyzer); return $manipulator; @@ -415,7 +409,7 @@ class FunctionDocblockManipulator $file_manipulations = []; - foreach (self::$ordered_manipulators[$file_path] as $manipulator) { + foreach (self::$manipulators[$file_path] as $manipulator) { if ($manipulator->new_php_return_type) { if ($manipulator->return_typehint_start && $manipulator->return_typehint_end) { $file_manipulations[$manipulator->return_typehint_start] = new FileManipulation( @@ -504,6 +498,21 @@ class FunctionDocblockManipulator public static function clearCache() { self::$manipulators = []; - self::$ordered_manipulators = []; + } + + /** + * @param array> $manipulators + */ + public static function addManipulators(array $manipulators) : void + { + self::$manipulators = array_merge($manipulators, self::$manipulators); + } + + /** + * @return array> + */ + public static function getManipulators() + { + return self::$manipulators; } }