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:
parent
07843d4768
commit
ee41560590
@ -298,7 +298,6 @@ class ReturnTypeAnalyzer
|
|||||||
$project_analyzer,
|
$project_analyzer,
|
||||||
$inferred_return_type,
|
$inferred_return_type,
|
||||||
$source,
|
$source,
|
||||||
$function_like_analyzer,
|
|
||||||
($project_analyzer->only_replace_php_types_with_non_docblock_types
|
($project_analyzer->only_replace_php_types_with_non_docblock_types
|
||||||
|| $unsafe_return_type)
|
|| $unsafe_return_type)
|
||||||
&& $inferred_return_type->from_docblock,
|
&& $inferred_return_type->from_docblock,
|
||||||
@ -336,7 +335,6 @@ class ReturnTypeAnalyzer
|
|||||||
$project_analyzer,
|
$project_analyzer,
|
||||||
$inferred_return_type,
|
$inferred_return_type,
|
||||||
$source,
|
$source,
|
||||||
$function_like_analyzer,
|
|
||||||
$compatible_method_ids
|
$compatible_method_ids
|
||||||
|| !$did_explicitly_return
|
|| !$did_explicitly_return
|
||||||
|| (($project_analyzer->only_replace_php_types_with_non_docblock_types
|
|| (($project_analyzer->only_replace_php_types_with_non_docblock_types
|
||||||
@ -407,7 +405,6 @@ class ReturnTypeAnalyzer
|
|||||||
$project_analyzer,
|
$project_analyzer,
|
||||||
Type::getVoid(),
|
Type::getVoid(),
|
||||||
$source,
|
$source,
|
||||||
$function_like_analyzer,
|
|
||||||
$compatible_method_ids
|
$compatible_method_ids
|
||||||
|| (($project_analyzer->only_replace_php_types_with_non_docblock_types
|
|| (($project_analyzer->only_replace_php_types_with_non_docblock_types
|
||||||
|| $unsafe_return_type)
|
|| $unsafe_return_type)
|
||||||
@ -505,7 +502,6 @@ class ReturnTypeAnalyzer
|
|||||||
$project_analyzer,
|
$project_analyzer,
|
||||||
$inferred_return_type,
|
$inferred_return_type,
|
||||||
$source,
|
$source,
|
||||||
$function_like_analyzer,
|
|
||||||
($project_analyzer->only_replace_php_types_with_non_docblock_types
|
($project_analyzer->only_replace_php_types_with_non_docblock_types
|
||||||
|| $unsafe_return_type)
|
|| $unsafe_return_type)
|
||||||
&& $inferred_return_type->from_docblock,
|
&& $inferred_return_type->from_docblock,
|
||||||
@ -547,7 +543,6 @@ class ReturnTypeAnalyzer
|
|||||||
$project_analyzer,
|
$project_analyzer,
|
||||||
$inferred_return_type,
|
$inferred_return_type,
|
||||||
$source,
|
$source,
|
||||||
$function_like_analyzer,
|
|
||||||
$compatible_method_ids
|
$compatible_method_ids
|
||||||
|| (($project_analyzer->only_replace_php_types_with_non_docblock_types
|
|| (($project_analyzer->only_replace_php_types_with_non_docblock_types
|
||||||
|| $unsafe_return_type)
|
|| $unsafe_return_type)
|
||||||
@ -607,7 +602,6 @@ class ReturnTypeAnalyzer
|
|||||||
$project_analyzer,
|
$project_analyzer,
|
||||||
$inferred_return_type,
|
$inferred_return_type,
|
||||||
$source,
|
$source,
|
||||||
$function_like_analyzer,
|
|
||||||
($project_analyzer->only_replace_php_types_with_non_docblock_types
|
($project_analyzer->only_replace_php_types_with_non_docblock_types
|
||||||
|| $unsafe_return_type)
|
|| $unsafe_return_type)
|
||||||
&& $inferred_return_type->from_docblock,
|
&& $inferred_return_type->from_docblock,
|
||||||
@ -644,7 +638,6 @@ class ReturnTypeAnalyzer
|
|||||||
$project_analyzer,
|
$project_analyzer,
|
||||||
$inferred_return_type,
|
$inferred_return_type,
|
||||||
$source,
|
$source,
|
||||||
$function_like_analyzer,
|
|
||||||
($project_analyzer->only_replace_php_types_with_non_docblock_types
|
($project_analyzer->only_replace_php_types_with_non_docblock_types
|
||||||
|| $unsafe_return_type)
|
|| $unsafe_return_type)
|
||||||
&& $inferred_return_type->from_docblock,
|
&& $inferred_return_type->from_docblock,
|
||||||
@ -821,8 +814,7 @@ class ReturnTypeAnalyzer
|
|||||||
$function,
|
$function,
|
||||||
$project_analyzer,
|
$project_analyzer,
|
||||||
$storage->signature_return_type,
|
$storage->signature_return_type,
|
||||||
$function_like_analyzer->getSource(),
|
$function_like_analyzer->getSource()
|
||||||
$function_like_analyzer
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -853,14 +845,12 @@ class ReturnTypeAnalyzer
|
|||||||
ProjectAnalyzer $project_analyzer,
|
ProjectAnalyzer $project_analyzer,
|
||||||
Type\Union $inferred_return_type,
|
Type\Union $inferred_return_type,
|
||||||
StatementsSource $source,
|
StatementsSource $source,
|
||||||
FunctionLikeAnalyzer $function_like_analyzer,
|
|
||||||
$docblock_only = false,
|
$docblock_only = false,
|
||||||
FunctionLikeStorage $function_like_storage = null
|
FunctionLikeStorage $function_like_storage = null
|
||||||
) {
|
) {
|
||||||
$manipulator = FunctionDocblockManipulator::getForFunction(
|
$manipulator = FunctionDocblockManipulator::getForFunction(
|
||||||
$project_analyzer,
|
$project_analyzer,
|
||||||
$source->getFilePath(),
|
$source->getFilePath(),
|
||||||
$function_like_analyzer->getId(),
|
|
||||||
$function
|
$function
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -589,7 +589,6 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
|
|||||||
$manipulator = FunctionDocblockManipulator::getForFunction(
|
$manipulator = FunctionDocblockManipulator::getForFunction(
|
||||||
$project_analyzer,
|
$project_analyzer,
|
||||||
$this->source->getFilePath(),
|
$this->source->getFilePath(),
|
||||||
$this->getId(),
|
|
||||||
$this->function
|
$this->function
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1501,7 +1500,6 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
|
|||||||
$manipulator = FunctionDocblockManipulator::getForFunction(
|
$manipulator = FunctionDocblockManipulator::getForFunction(
|
||||||
$project_analyzer,
|
$project_analyzer,
|
||||||
$this->source->getFilePath(),
|
$this->source->getFilePath(),
|
||||||
$this->getId(),
|
|
||||||
$this->function
|
$this->function
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -59,7 +59,8 @@ use function array_values;
|
|||||||
* possible_method_param_types: array<string, array<int, \Psalm\Type\Union>>,
|
* possible_method_param_types: array<string, array<int, \Psalm\Type\Union>>,
|
||||||
* taint_data: ?\Psalm\Internal\Codebase\Taint,
|
* taint_data: ?\Psalm\Internal\Codebase\Taint,
|
||||||
* unused_suppressions: array<string, array<int, int>>,
|
* 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,
|
'taint_data' => $codebase->taint,
|
||||||
'unused_suppressions' => $codebase->track_unused_suppressions ? IssueBuffer::getUnusedSuppressions() : [],
|
'unused_suppressions' => $codebase->track_unused_suppressions ? IssueBuffer::getUnusedSuppressions() : [],
|
||||||
'used_suppressions' => $codebase->track_unused_suppressions ? IssueBuffer::getUsedSuppressions() : [],
|
'used_suppressions' => $codebase->track_unused_suppressions ? IssueBuffer::getUsedSuppressions() : [],
|
||||||
|
'manipulators' => FunctionDocblockManipulator::getManipulators(),
|
||||||
];
|
];
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
},
|
},
|
||||||
@ -530,6 +532,8 @@ class Analyzer
|
|||||||
$pool_data['class_property_locations']
|
$pool_data['class_property_locations']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
FunctionDocblockManipulator::addManipulators($pool_data['manipulators']);
|
||||||
|
|
||||||
$this->analyzed_methods = array_merge($pool_data['analyzed_methods'], $this->analyzed_methods);
|
$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)) {
|
foreach ($pool_data['mixed_counts'] as $file_path => list($mixed_count, $nonmixed_count)) {
|
||||||
|
@ -28,15 +28,12 @@ use function reset;
|
|||||||
*/
|
*/
|
||||||
class FunctionDocblockManipulator
|
class FunctionDocblockManipulator
|
||||||
{
|
{
|
||||||
/** @var array<string, array<string, FunctionDocblockManipulator>> */
|
|
||||||
private static $manipulators = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manipulators ordered by line number
|
* Manipulators ordered by line number
|
||||||
*
|
*
|
||||||
* @var array<string, array<int, FunctionDocblockManipulator>>
|
* @var array<string, array<int, FunctionDocblockManipulator>>
|
||||||
*/
|
*/
|
||||||
private static $ordered_manipulators = [];
|
private static $manipulators = [];
|
||||||
|
|
||||||
/** @var Closure|Function_|ClassMethod|ArrowFunction */
|
/** @var Closure|Function_|ClassMethod|ArrowFunction */
|
||||||
private $stmt;
|
private $stmt;
|
||||||
@ -97,7 +94,6 @@ class FunctionDocblockManipulator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $file_path
|
* @param string $file_path
|
||||||
* @param string $function_id
|
|
||||||
* @param Closure|Function_|ClassMethod|ArrowFunction $stmt
|
* @param Closure|Function_|ClassMethod|ArrowFunction $stmt
|
||||||
*
|
*
|
||||||
* @return self
|
* @return self
|
||||||
@ -105,16 +101,14 @@ class FunctionDocblockManipulator
|
|||||||
public static function getForFunction(
|
public static function getForFunction(
|
||||||
ProjectAnalyzer $project_analyzer,
|
ProjectAnalyzer $project_analyzer,
|
||||||
$file_path,
|
$file_path,
|
||||||
$function_id,
|
|
||||||
FunctionLike $stmt
|
FunctionLike $stmt
|
||||||
) {
|
) {
|
||||||
if (isset(self::$manipulators[$file_path][$function_id])) {
|
if (isset(self::$manipulators[$file_path][$stmt->getLine()])) {
|
||||||
return self::$manipulators[$file_path][$function_id];
|
return self::$manipulators[$file_path][$stmt->getLine()];
|
||||||
}
|
}
|
||||||
|
|
||||||
$manipulator
|
$manipulator
|
||||||
= self::$manipulators[$file_path][$function_id]
|
= self::$manipulators[$file_path][$stmt->getLine()]
|
||||||
= self::$ordered_manipulators[$file_path][$stmt->getLine()]
|
|
||||||
= new self($file_path, $stmt, $project_analyzer);
|
= new self($file_path, $stmt, $project_analyzer);
|
||||||
|
|
||||||
return $manipulator;
|
return $manipulator;
|
||||||
@ -415,7 +409,7 @@ class FunctionDocblockManipulator
|
|||||||
|
|
||||||
$file_manipulations = [];
|
$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->new_php_return_type) {
|
||||||
if ($manipulator->return_typehint_start && $manipulator->return_typehint_end) {
|
if ($manipulator->return_typehint_start && $manipulator->return_typehint_end) {
|
||||||
$file_manipulations[$manipulator->return_typehint_start] = new FileManipulation(
|
$file_manipulations[$manipulator->return_typehint_start] = new FileManipulation(
|
||||||
@ -504,6 +498,21 @@ class FunctionDocblockManipulator
|
|||||||
public static function clearCache()
|
public static function clearCache()
|
||||||
{
|
{
|
||||||
self::$manipulators = [];
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user