1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Allow function manipulators to work in threaded mode

This commit is contained in:
Brown 2020-08-23 18:05:48 -04:00 committed by Daniil Gentili
parent 07843d4768
commit ee41560590
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
4 changed files with 27 additions and 26 deletions

View File

@ -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
);

View File

@ -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
);

View File

@ -59,7 +59,8 @@ use function array_values;
* possible_method_param_types: array<string, array<int, \Psalm\Type\Union>>,
* taint_data: ?\Psalm\Internal\Codebase\Taint,
* unused_suppressions: array<string, array<int, int>>,
* used_suppressions: array<string, array<int, bool>>
* used_suppressions: array<string, array<int, bool>>,
* manipulators: array<string, array<int, FunctionDocblockManipulator>>,
* }
*/
@ -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)) {

View File

@ -28,15 +28,12 @@ use function reset;
*/
class FunctionDocblockManipulator
{
/** @var array<string, array<string, FunctionDocblockManipulator>> */
private static $manipulators = [];
/**
* Manipulators ordered by line number
*
* @var array<string, array<int, FunctionDocblockManipulator>>
*/
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<string, array<int, FunctionDocblockManipulator>> $manipulators
*/
public static function addManipulators(array $manipulators) : void
{
self::$manipulators = array_merge($manipulators, self::$manipulators);
}
/**
* @return array<string, array<int, FunctionDocblockManipulator>>
*/
public static function getManipulators()
{
return self::$manipulators;
}
}