mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 12:24:49 +01:00
Simplify calling of replacer methods
This commit is contained in:
parent
67d319657a
commit
2b152d5d97
@ -25,7 +25,7 @@
|
|||||||
<exclude-pattern>tests/fixtures/</exclude-pattern>
|
<exclude-pattern>tests/fixtures/</exclude-pattern>
|
||||||
<rule ref="Generic.Files.LineLength">
|
<rule ref="Generic.Files.LineLength">
|
||||||
<exclude-pattern>tests</exclude-pattern>
|
<exclude-pattern>tests</exclude-pattern>
|
||||||
<exclude-pattern>src/Psalm/Internal/Type/UnionTemplateHandler.php</exclude-pattern>
|
<exclude-pattern>src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php</exclude-pattern>
|
||||||
</rule>
|
</rule>
|
||||||
|
|
||||||
<rule ref="PSR2.Namespaces.UseDeclaration">
|
<rule ref="PSR2.Namespaces.UseDeclaration">
|
||||||
|
@ -7,7 +7,7 @@ use Psalm\DocComment;
|
|||||||
use Psalm\Exception\DocblockParseException;
|
use Psalm\Exception\DocblockParseException;
|
||||||
use Psalm\Internal\Analyzer\Statements\Expression\Call\ClassTemplateParamCollector;
|
use Psalm\Internal\Analyzer\Statements\Expression\Call\ClassTemplateParamCollector;
|
||||||
use Psalm\Internal\FileManipulation\PropertyDocblockManipulator;
|
use Psalm\Internal\FileManipulation\PropertyDocblockManipulator;
|
||||||
use Psalm\Internal\Type\UnionTemplateHandler;
|
use Psalm\Internal\Type\TemplateStandinTypeReplacer;
|
||||||
use Psalm\Internal\Type\Comparator\UnionTypeComparator;
|
use Psalm\Internal\Type\Comparator\UnionTypeComparator;
|
||||||
use Psalm\Codebase;
|
use Psalm\Codebase;
|
||||||
use Psalm\CodeLocation;
|
use Psalm\CodeLocation;
|
||||||
@ -1080,7 +1080,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ($class_template_params) {
|
if ($class_template_params) {
|
||||||
$fleshed_out_type = UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
$fleshed_out_type = TemplateStandinTypeReplacer::replace(
|
||||||
$fleshed_out_type,
|
$fleshed_out_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -2081,7 +2081,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
$return_type = UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
$return_type = TemplateStandinTypeReplacer::replace(
|
||||||
$return_type,
|
$return_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -2228,7 +2228,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
$template_type_copy = UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
$template_type_copy = TemplateStandinTypeReplacer::replace(
|
||||||
$template_type_copy,
|
$template_type_copy,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
|
@ -813,7 +813,7 @@ class ReturnTypeAnalyzer
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
$fleshed_out_return_type = \Psalm\Internal\Type\UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
$fleshed_out_return_type = \Psalm\Internal\Type\TemplateStandinTypeReplacer::replace(
|
||||||
$fleshed_out_return_type,
|
$fleshed_out_return_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
|
@ -1069,7 +1069,7 @@ class MethodComparator
|
|||||||
|
|
||||||
$template_result = new \Psalm\Internal\Type\TemplateResult([], $template_types);
|
$template_result = new \Psalm\Internal\Type\TemplateResult([], $template_types);
|
||||||
|
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$templated_type,
|
$templated_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
|
@ -522,7 +522,7 @@ class ArrayAssignmentAnalyzer
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$current_type,
|
$current_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
|
@ -17,7 +17,7 @@ use Psalm\Internal\Codebase\TaintFlowGraph;
|
|||||||
use Psalm\Internal\MethodIdentifier;
|
use Psalm\Internal\MethodIdentifier;
|
||||||
use Psalm\Internal\Type\TemplateBound;
|
use Psalm\Internal\Type\TemplateBound;
|
||||||
use Psalm\Internal\Type\TemplateResult;
|
use Psalm\Internal\Type\TemplateResult;
|
||||||
use Psalm\Internal\Type\UnionTemplateHandler;
|
use Psalm\Internal\Type\TemplateStandinTypeReplacer;
|
||||||
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
|
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
|
||||||
use Psalm\CodeLocation;
|
use Psalm\CodeLocation;
|
||||||
use Psalm\Context;
|
use Psalm\Context;
|
||||||
@ -237,7 +237,7 @@ class ArgumentAnalyzer
|
|||||||
|
|
||||||
$arg_value_type = $statements_analyzer->node_data->getType($arg->value);
|
$arg_value_type = $statements_analyzer->node_data->getType($arg->value);
|
||||||
|
|
||||||
$param_type = UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
$param_type = TemplateStandinTypeReplacer::replace(
|
||||||
$param_type,
|
$param_type,
|
||||||
$empty_template_result,
|
$empty_template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -247,7 +247,7 @@ class ArgumentAnalyzer
|
|||||||
$context->self ?: 'fn-' . $context->calling_function_id
|
$context->self ?: 'fn-' . $context->calling_function_id
|
||||||
);
|
);
|
||||||
|
|
||||||
$arg_type = UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
$arg_type = TemplateStandinTypeReplacer::replace(
|
||||||
$arg_type,
|
$arg_type,
|
||||||
$empty_template_result,
|
$empty_template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -294,7 +294,7 @@ class ArgumentAnalyzer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$param_type = UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
$param_type = TemplateStandinTypeReplacer::replace(
|
||||||
$param_type,
|
$param_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
|
@ -16,7 +16,7 @@ use Psalm\Internal\Stubs\Generator\StubsGenerator;
|
|||||||
use Psalm\Internal\Type\Comparator\UnionTypeComparator;
|
use Psalm\Internal\Type\Comparator\UnionTypeComparator;
|
||||||
use Psalm\Internal\MethodIdentifier;
|
use Psalm\Internal\MethodIdentifier;
|
||||||
use Psalm\Internal\Type\TemplateResult;
|
use Psalm\Internal\Type\TemplateResult;
|
||||||
use Psalm\Internal\Type\UnionTemplateHandler;
|
use Psalm\Internal\Type\TemplateStandinTypeReplacer;
|
||||||
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
|
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
|
||||||
use Psalm\CodeLocation;
|
use Psalm\CodeLocation;
|
||||||
use Psalm\Context;
|
use Psalm\Context;
|
||||||
@ -255,7 +255,7 @@ class ArgumentsAnalyzer
|
|||||||
|
|
||||||
$existing_type = $statements_analyzer->node_data->getType($arg->value);
|
$existing_type = $statements_analyzer->node_data->getType($arg->value);
|
||||||
|
|
||||||
\Psalm\Internal\Type\UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
\Psalm\Internal\Type\TemplateStandinTypeReplacer::replace(
|
||||||
$generic_param_type,
|
$generic_param_type,
|
||||||
$replace_template_result,
|
$replace_template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -337,7 +337,7 @@ class ArgumentsAnalyzer
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
$replaced_type = \Psalm\Internal\Type\UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
$replaced_type = \Psalm\Internal\Type\TemplateStandinTypeReplacer::replace(
|
||||||
$replaced_type,
|
$replaced_type,
|
||||||
$replace_template_result,
|
$replace_template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -348,7 +348,7 @@ class ArgumentsAnalyzer
|
|||||||
'fn-' . ($context->calling_method_id ?: $context->calling_function_id)
|
'fn-' . ($context->calling_method_id ?: $context->calling_function_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$replaced_type,
|
$replaced_type,
|
||||||
$replace_template_result,
|
$replace_template_result,
|
||||||
$codebase
|
$codebase
|
||||||
@ -610,7 +610,7 @@ class ArgumentsAnalyzer
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
TemplateStandinTypeReplacer::replace(
|
||||||
$function_param->type,
|
$function_param->type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -896,7 +896,7 @@ class ArgumentsAnalyzer
|
|||||||
&& !$param->is_variadic
|
&& !$param->is_variadic
|
||||||
&& $template_result
|
&& $template_result
|
||||||
) {
|
) {
|
||||||
UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
TemplateStandinTypeReplacer::replace(
|
||||||
$param->type,
|
$param->type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -992,7 +992,7 @@ class ArgumentsAnalyzer
|
|||||||
if ($template_result && $by_ref_type) {
|
if ($template_result && $by_ref_type) {
|
||||||
$original_by_ref_type = clone $by_ref_type;
|
$original_by_ref_type = clone $by_ref_type;
|
||||||
|
|
||||||
$by_ref_type = UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
$by_ref_type = TemplateStandinTypeReplacer::replace(
|
||||||
clone $by_ref_type,
|
clone $by_ref_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -1003,7 +1003,7 @@ class ArgumentsAnalyzer
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ($template_result->upper_bounds) {
|
if ($template_result->upper_bounds) {
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$original_by_ref_type,
|
$original_by_ref_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
@ -1016,7 +1016,7 @@ class ArgumentsAnalyzer
|
|||||||
if ($template_result && $by_ref_out_type) {
|
if ($template_result && $by_ref_out_type) {
|
||||||
$original_by_ref_out_type = clone $by_ref_out_type;
|
$original_by_ref_out_type = clone $by_ref_out_type;
|
||||||
|
|
||||||
$by_ref_out_type = UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
$by_ref_out_type = TemplateStandinTypeReplacer::replace(
|
||||||
clone $by_ref_out_type,
|
clone $by_ref_out_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -1027,7 +1027,7 @@ class ArgumentsAnalyzer
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ($template_result->upper_bounds) {
|
if ($template_result->upper_bounds) {
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$original_by_ref_out_type,
|
$original_by_ref_out_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
|
@ -10,7 +10,7 @@ use Psalm\Internal\Analyzer\Statements\Expression\ExpressionIdentifier;
|
|||||||
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
||||||
use Psalm\Internal\Codebase\InternalCallMapHandler;
|
use Psalm\Internal\Codebase\InternalCallMapHandler;
|
||||||
use Psalm\Internal\Type\TypeCombiner;
|
use Psalm\Internal\Type\TypeCombiner;
|
||||||
use Psalm\Internal\Type\UnionTemplateHandler;
|
use Psalm\Internal\Type\TemplateStandinTypeReplacer;
|
||||||
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
|
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
|
||||||
use Psalm\Internal\Type\Comparator\UnionTypeComparator;
|
use Psalm\Internal\Type\Comparator\UnionTypeComparator;
|
||||||
use Psalm\CodeLocation;
|
use Psalm\CodeLocation;
|
||||||
@ -831,7 +831,7 @@ class ArrayFunctionArgumentsAnalyzer
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$closure_param_type = UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
$closure_param_type = TemplateStandinTypeReplacer::replace(
|
||||||
$closure_param_type,
|
$closure_param_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
|
@ -105,7 +105,7 @@ class FunctionCallReturnTypeFetcher
|
|||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$return_type,
|
$return_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
@ -496,7 +496,7 @@ class FunctionCallReturnTypeFetcher
|
|||||||
foreach ($function_storage->conditionally_removed_taints as $conditionally_removed_taint) {
|
foreach ($function_storage->conditionally_removed_taints as $conditionally_removed_taint) {
|
||||||
$conditionally_removed_taint = clone $conditionally_removed_taint;
|
$conditionally_removed_taint = clone $conditionally_removed_taint;
|
||||||
|
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$conditionally_removed_taint,
|
$conditionally_removed_taint,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
|
@ -462,7 +462,7 @@ class MethodCallReturnTypeFetcher
|
|||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$return_type_candidate,
|
$return_type_candidate,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
|
@ -281,7 +281,7 @@ class StaticCallAnalyzer extends CallAnalyzer
|
|||||||
foreach ($method_storage->conditionally_removed_taints as $conditionally_removed_taint) {
|
foreach ($method_storage->conditionally_removed_taints as $conditionally_removed_taint) {
|
||||||
$conditionally_removed_taint = clone $conditionally_removed_taint;
|
$conditionally_removed_taint = clone $conditionally_removed_taint;
|
||||||
|
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$conditionally_removed_taint,
|
$conditionally_removed_taint,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
|
@ -283,7 +283,7 @@ class ExistingAtomicStaticCallAnalyzer
|
|||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$return_type_candidate,
|
$return_type_candidate,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
|
@ -1330,7 +1330,7 @@ class ArrayFetchAnalyzer
|
|||||||
|
|
||||||
$expected_value_param_get = clone $type->value_param;
|
$expected_value_param_get = clone $type->value_param;
|
||||||
|
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$expected_value_param_get,
|
$expected_value_param_get,
|
||||||
$template_result_get,
|
$template_result_get,
|
||||||
$codebase
|
$codebase
|
||||||
@ -1339,7 +1339,7 @@ class ArrayFetchAnalyzer
|
|||||||
if ($replacement_type) {
|
if ($replacement_type) {
|
||||||
$expected_value_param_set = clone $type->value_param;
|
$expected_value_param_set = clone $type->value_param;
|
||||||
|
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$replacement_type,
|
$replacement_type,
|
||||||
$template_result_set,
|
$template_result_set,
|
||||||
$codebase
|
$codebase
|
||||||
|
@ -752,7 +752,7 @@ class AtomicPropertyFetchAnalyzer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$class_property_type,
|
$class_property_type,
|
||||||
new TemplateResult([], $template_types),
|
new TemplateResult([], $template_types),
|
||||||
$codebase
|
$codebase
|
||||||
|
@ -269,7 +269,7 @@ class ReturnAnalyzer
|
|||||||
|
|
||||||
$local_return_type = clone $local_return_type;
|
$local_return_type = clone $local_return_type;
|
||||||
|
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$local_return_type,
|
$local_return_type,
|
||||||
new TemplateResult([], $found_generic_params),
|
new TemplateResult([], $found_generic_params),
|
||||||
$codebase
|
$codebase
|
||||||
|
@ -833,7 +833,7 @@ class AssertionReconciler extends \Psalm\Type\Reconciler
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ($template_type_map) {
|
if ($template_type_map) {
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$new_param,
|
$new_param,
|
||||||
new TemplateResult([], $template_type_map),
|
new TemplateResult([], $template_type_map),
|
||||||
$codebase
|
$codebase
|
||||||
@ -882,7 +882,7 @@ class AssertionReconciler extends \Psalm\Type\Reconciler
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ($template_type_map) {
|
if ($template_type_map) {
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$new_param,
|
$new_param,
|
||||||
new TemplateResult([], $template_type_map),
|
new TemplateResult([], $template_type_map),
|
||||||
$codebase
|
$codebase
|
||||||
|
@ -74,7 +74,7 @@ class GenericTypeComparator
|
|||||||
|
|
||||||
$container_type_params_covariant = [];
|
$container_type_params_covariant = [];
|
||||||
|
|
||||||
$input_type_params = \Psalm\Internal\Type\UnionTemplateHandler::getMappedGenericTypeParams(
|
$input_type_params = \Psalm\Internal\Type\TemplateStandinTypeReplacer::getMappedGenericTypeParams(
|
||||||
$codebase,
|
$codebase,
|
||||||
$input_type_part,
|
$input_type_part,
|
||||||
$container_type_part,
|
$container_type_part,
|
||||||
|
@ -43,7 +43,7 @@ class TemplateInferredTypeReplacer
|
|||||||
/**
|
/**
|
||||||
* This replaces template types in unions with the inferred types they should be
|
* This replaces template types in unions with the inferred types they should be
|
||||||
*/
|
*/
|
||||||
public static function replaceTemplateTypesWithArgTypes(
|
public static function replace(
|
||||||
Union $union,
|
Union $union,
|
||||||
TemplateResult $template_result,
|
TemplateResult $template_result,
|
||||||
?Codebase $codebase
|
?Codebase $codebase
|
||||||
@ -62,7 +62,7 @@ class TemplateInferredTypeReplacer
|
|||||||
if ($atomic_type instanceof Atomic\TTemplateParam) {
|
if ($atomic_type instanceof Atomic\TTemplateParam) {
|
||||||
$template_type = null;
|
$template_type = null;
|
||||||
|
|
||||||
$traversed_type = \Psalm\Internal\Type\UnionTemplateHandler::getRootTemplateType(
|
$traversed_type = \Psalm\Internal\Type\TemplateStandinTypeReplacer::getRootTemplateType(
|
||||||
$inferred_upper_bounds,
|
$inferred_upper_bounds,
|
||||||
$atomic_type->param_name,
|
$atomic_type->param_name,
|
||||||
$atomic_type->defining_class
|
$atomic_type->defining_class
|
||||||
@ -234,7 +234,7 @@ class TemplateInferredTypeReplacer
|
|||||||
$atomic_type = clone $atomic_type;
|
$atomic_type = clone $atomic_type;
|
||||||
|
|
||||||
if ($template_type) {
|
if ($template_type) {
|
||||||
self::replaceTemplateTypesWithArgTypes(
|
self::replace(
|
||||||
$atomic_type->as_type,
|
$atomic_type->as_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
@ -250,7 +250,7 @@ class TemplateInferredTypeReplacer
|
|||||||
$atomic_type->conditional_type
|
$atomic_type->conditional_type
|
||||||
)) {
|
)) {
|
||||||
$class_template_type = clone $atomic_type->if_type;
|
$class_template_type = clone $atomic_type->if_type;
|
||||||
self::replaceTemplateTypesWithArgTypes(
|
self::replace(
|
||||||
$class_template_type,
|
$class_template_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
@ -267,7 +267,7 @@ class TemplateInferredTypeReplacer
|
|||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
$class_template_type = clone $atomic_type->else_type;
|
$class_template_type = clone $atomic_type->else_type;
|
||||||
self::replaceTemplateTypesWithArgTypes(
|
self::replace(
|
||||||
$class_template_type,
|
$class_template_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
@ -276,13 +276,13 @@ class TemplateInferredTypeReplacer
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$class_template_type) {
|
if (!$class_template_type) {
|
||||||
self::replaceTemplateTypesWithArgTypes(
|
self::replace(
|
||||||
$atomic_type->if_type,
|
$atomic_type->if_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
);
|
);
|
||||||
|
|
||||||
self::replaceTemplateTypesWithArgTypes(
|
self::replace(
|
||||||
$atomic_type->else_type,
|
$atomic_type->else_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
|
@ -16,12 +16,12 @@ use function is_string;
|
|||||||
use function strpos;
|
use function strpos;
|
||||||
use function substr;
|
use function substr;
|
||||||
|
|
||||||
class UnionTemplateHandler
|
class TemplateStandinTypeReplacer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* This replaces template types in unions with standins (normally the template as type)
|
* This replaces template types in unions with standins (normally the template as type)
|
||||||
*/
|
*/
|
||||||
public static function replaceTemplateTypesWithStandins(
|
public static function replace(
|
||||||
Union $union_type,
|
Union $union_type,
|
||||||
TemplateResult $template_result,
|
TemplateResult $template_result,
|
||||||
?Codebase $codebase,
|
?Codebase $codebase,
|
||||||
@ -469,7 +469,7 @@ class UnionTemplateHandler
|
|||||||
|
|
||||||
if ($atomic_type->extra_types) {
|
if ($atomic_type->extra_types) {
|
||||||
foreach ($atomic_type->extra_types as $extra_type) {
|
foreach ($atomic_type->extra_types as $extra_type) {
|
||||||
$extra_type = self::replaceTemplateTypesWithStandins(
|
$extra_type = self::replace(
|
||||||
new \Psalm\Type\Union([$extra_type]),
|
new \Psalm\Type\Union([$extra_type]),
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -518,7 +518,7 @@ class UnionTemplateHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($depth < 10) {
|
if ($depth < 10) {
|
||||||
$replacement_type = self::replaceTemplateTypesWithStandins(
|
$replacement_type = self::replace(
|
||||||
$replacement_type,
|
$replacement_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -600,7 +600,7 @@ class UnionTemplateHandler
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$atomic_type->as = self::replaceTemplateTypesWithStandins(
|
$atomic_type->as = self::replace(
|
||||||
$atomic_type->as,
|
$atomic_type->as,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -979,7 +979,7 @@ class UnionTemplateHandler
|
|||||||
|
|
||||||
$new_input_param = clone $new_input_param;
|
$new_input_param = clone $new_input_param;
|
||||||
|
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$new_input_param,
|
$new_input_param,
|
||||||
new TemplateResult([], $replacement_templates),
|
new TemplateResult([], $replacement_templates),
|
||||||
$codebase
|
$codebase
|
@ -7,7 +7,7 @@ use function implode;
|
|||||||
use Psalm\Codebase;
|
use Psalm\Codebase;
|
||||||
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
||||||
use Psalm\Internal\Type\TemplateResult;
|
use Psalm\Internal\Type\TemplateResult;
|
||||||
use Psalm\Internal\Type\UnionTemplateHandler;
|
use Psalm\Internal\Type\TemplateStandinTypeReplacer;
|
||||||
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
|
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
|
||||||
use Psalm\Storage\FunctionLikeParameter;
|
use Psalm\Storage\FunctionLikeParameter;
|
||||||
use Psalm\Type\Atomic;
|
use Psalm\Type\Atomic;
|
||||||
@ -206,7 +206,7 @@ trait CallableTrait
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$param->type = UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
$param->type = TemplateStandinTypeReplacer::replace(
|
||||||
$param->type,
|
$param->type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -226,7 +226,7 @@ trait CallableTrait
|
|||||||
&& $callable->return_type
|
&& $callable->return_type
|
||||||
&& $input_type->return_type
|
&& $input_type->return_type
|
||||||
) {
|
) {
|
||||||
$callable->return_type = UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
$callable->return_type = TemplateStandinTypeReplacer::replace(
|
||||||
$callable->return_type,
|
$callable->return_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -253,7 +253,7 @@ trait CallableTrait
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$param->type,
|
$param->type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
@ -262,7 +262,7 @@ trait CallableTrait
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->return_type) {
|
if ($this->return_type) {
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$this->return_type,
|
$this->return_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
|
@ -6,7 +6,7 @@ use function implode;
|
|||||||
use Psalm\Codebase;
|
use Psalm\Codebase;
|
||||||
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
||||||
use Psalm\Internal\Type\TemplateResult;
|
use Psalm\Internal\Type\TemplateResult;
|
||||||
use Psalm\Internal\Type\UnionTemplateHandler;
|
use Psalm\Internal\Type\TemplateStandinTypeReplacer;
|
||||||
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
|
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
|
||||||
use Psalm\Type;
|
use Psalm\Type;
|
||||||
use Psalm\Type\Atomic;
|
use Psalm\Type\Atomic;
|
||||||
@ -169,7 +169,7 @@ trait GenericTrait
|
|||||||
&& ($this instanceof Atomic\TGenericObject || $this instanceof Atomic\TIterable)
|
&& ($this instanceof Atomic\TGenericObject || $this instanceof Atomic\TIterable)
|
||||||
&& $codebase
|
&& $codebase
|
||||||
) {
|
) {
|
||||||
$input_object_type_params = UnionTemplateHandler::getMappedGenericTypeParams(
|
$input_object_type_params = TemplateStandinTypeReplacer::getMappedGenericTypeParams(
|
||||||
$codebase,
|
$codebase,
|
||||||
$input_type,
|
$input_type,
|
||||||
$this
|
$this
|
||||||
@ -202,7 +202,7 @@ trait GenericTrait
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @psalm-suppress PropertyTypeCoercion */
|
/** @psalm-suppress PropertyTypeCoercion */
|
||||||
$atomic->type_params[$offset] = UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
$atomic->type_params[$offset] = TemplateStandinTypeReplacer::replace(
|
||||||
$type_param,
|
$type_param,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -225,7 +225,7 @@ trait GenericTrait
|
|||||||
?Codebase $codebase
|
?Codebase $codebase
|
||||||
) : void {
|
) : void {
|
||||||
foreach ($this->type_params as $offset => $type_param) {
|
foreach ($this->type_params as $offset => $type_param) {
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$type_param,
|
$type_param,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
|
@ -4,7 +4,7 @@ namespace Psalm\Type\Atomic;
|
|||||||
use Psalm\Codebase;
|
use Psalm\Codebase;
|
||||||
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
||||||
use Psalm\Internal\Type\TemplateResult;
|
use Psalm\Internal\Type\TemplateResult;
|
||||||
use Psalm\Internal\Type\UnionTemplateHandler;
|
use Psalm\Internal\Type\TemplateStandinTypeReplacer;
|
||||||
use Psalm\Type\Atomic;
|
use Psalm\Type\Atomic;
|
||||||
use function preg_quote;
|
use function preg_quote;
|
||||||
use function preg_replace;
|
use function preg_replace;
|
||||||
@ -132,7 +132,7 @@ class TClassString extends TString
|
|||||||
$input_object_type = new TObject();
|
$input_object_type = new TObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
$as_type = UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
$as_type = TemplateStandinTypeReplacer::replace(
|
||||||
new \Psalm\Type\Union([$class_string->as_type]),
|
new \Psalm\Type\Union([$class_string->as_type]),
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
|
@ -5,7 +5,7 @@ use function get_class;
|
|||||||
use Psalm\Codebase;
|
use Psalm\Codebase;
|
||||||
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
||||||
use Psalm\Internal\Type\TemplateResult;
|
use Psalm\Internal\Type\TemplateResult;
|
||||||
use Psalm\Internal\Type\UnionTemplateHandler;
|
use Psalm\Internal\Type\TemplateStandinTypeReplacer;
|
||||||
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
|
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
|
||||||
use Psalm\Type;
|
use Psalm\Type;
|
||||||
use Psalm\Type\Atomic;
|
use Psalm\Type\Atomic;
|
||||||
@ -171,7 +171,7 @@ class TClassStringMap extends \Psalm\Type\Atomic
|
|||||||
$input_type_param = clone $input_type->type_param;
|
$input_type_param = clone $input_type->type_param;
|
||||||
}
|
}
|
||||||
|
|
||||||
$value_param = UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
$value_param = TemplateStandinTypeReplacer::replace(
|
||||||
$type_param,
|
$type_param,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -197,7 +197,7 @@ class TClassStringMap extends \Psalm\Type\Atomic
|
|||||||
TemplateResult $template_result,
|
TemplateResult $template_result,
|
||||||
?Codebase $codebase
|
?Codebase $codebase
|
||||||
) : void {
|
) : void {
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$this->value_param,
|
$this->value_param,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
|
@ -134,7 +134,7 @@ class TConditional extends \Psalm\Type\Atomic
|
|||||||
TemplateResult $template_result,
|
TemplateResult $template_result,
|
||||||
?Codebase $codebase
|
?Codebase $codebase
|
||||||
) : void {
|
) : void {
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$this->conditional_type,
|
$this->conditional_type,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
|
@ -12,7 +12,7 @@ use Psalm\Codebase;
|
|||||||
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
||||||
use Psalm\Internal\Type\TypeCombiner;
|
use Psalm\Internal\Type\TypeCombiner;
|
||||||
use Psalm\Internal\Type\TemplateResult;
|
use Psalm\Internal\Type\TemplateResult;
|
||||||
use Psalm\Internal\Type\UnionTemplateHandler;
|
use Psalm\Internal\Type\TemplateStandinTypeReplacer;
|
||||||
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
|
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
|
||||||
use Psalm\Type;
|
use Psalm\Type;
|
||||||
use Psalm\Type\Atomic;
|
use Psalm\Type\Atomic;
|
||||||
@ -330,7 +330,7 @@ class TKeyedArray extends \Psalm\Type\Atomic
|
|||||||
$input_type_param = $input_type->properties[$offset];
|
$input_type_param = $input_type->properties[$offset];
|
||||||
}
|
}
|
||||||
|
|
||||||
$object_like->properties[$offset] = UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
$object_like->properties[$offset] = TemplateStandinTypeReplacer::replace(
|
||||||
$property,
|
$property,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -353,7 +353,7 @@ class TKeyedArray extends \Psalm\Type\Atomic
|
|||||||
?Codebase $codebase
|
?Codebase $codebase
|
||||||
) : void {
|
) : void {
|
||||||
foreach ($this->properties as $property) {
|
foreach ($this->properties as $property) {
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$property,
|
$property,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
|
@ -5,7 +5,7 @@ use function get_class;
|
|||||||
use Psalm\Codebase;
|
use Psalm\Codebase;
|
||||||
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
||||||
use Psalm\Internal\Type\TemplateResult;
|
use Psalm\Internal\Type\TemplateResult;
|
||||||
use Psalm\Internal\Type\UnionTemplateHandler;
|
use Psalm\Internal\Type\TemplateStandinTypeReplacer;
|
||||||
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
|
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
|
||||||
use Psalm\Type;
|
use Psalm\Type;
|
||||||
use Psalm\Type\Atomic;
|
use Psalm\Type\Atomic;
|
||||||
@ -141,7 +141,7 @@ class TList extends \Psalm\Type\Atomic
|
|||||||
$input_type_param = clone $input_type->type_param;
|
$input_type_param = clone $input_type->type_param;
|
||||||
}
|
}
|
||||||
|
|
||||||
$type_param = UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
$type_param = TemplateStandinTypeReplacer::replace(
|
||||||
$type_param,
|
$type_param,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -167,7 +167,7 @@ class TList extends \Psalm\Type\Atomic
|
|||||||
TemplateResult $template_result,
|
TemplateResult $template_result,
|
||||||
?Codebase $codebase
|
?Codebase $codebase
|
||||||
) : void {
|
) : void {
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$this->type_param,
|
$this->type_param,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
|
@ -10,7 +10,7 @@ use Psalm\Type\Atomic;
|
|||||||
use Psalm\Type\Union;
|
use Psalm\Type\Union;
|
||||||
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
||||||
use Psalm\Internal\Type\TemplateResult;
|
use Psalm\Internal\Type\TemplateResult;
|
||||||
use Psalm\Internal\Type\UnionTemplateHandler;
|
use Psalm\Internal\Type\TemplateStandinTypeReplacer;
|
||||||
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
|
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
|
||||||
use function array_merge;
|
use function array_merge;
|
||||||
use function array_values;
|
use function array_values;
|
||||||
@ -236,7 +236,7 @@ class TObjectWithProperties extends TObject
|
|||||||
$input_type_param = $input_type->properties[$offset];
|
$input_type_param = $input_type->properties[$offset];
|
||||||
}
|
}
|
||||||
|
|
||||||
$object_like->properties[$offset] = UnionTemplateHandler::replaceTemplateTypesWithStandins(
|
$object_like->properties[$offset] = TemplateStandinTypeReplacer::replace(
|
||||||
$property,
|
$property,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -259,7 +259,7 @@ class TObjectWithProperties extends TObject
|
|||||||
?Codebase $codebase
|
?Codebase $codebase
|
||||||
) : void {
|
) : void {
|
||||||
foreach ($this->properties as $property) {
|
foreach ($this->properties as $property) {
|
||||||
TemplateInferredTypeReplacer::replaceTemplateTypesWithArgTypes(
|
TemplateInferredTypeReplacer::replace(
|
||||||
$property,
|
$property,
|
||||||
$template_result,
|
$template_result,
|
||||||
$codebase
|
$codebase
|
||||||
|
Loading…
Reference in New Issue
Block a user