Skip to content

Commit

Permalink
Break out type expander into separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed May 11, 2020
1 parent 7dd1823 commit 5f4d162
Show file tree
Hide file tree
Showing 23 changed files with 606 additions and 563 deletions.
6 changes: 3 additions & 3 deletions src/Psalm/Internal/Analyzer/ClassAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ public function analyze(
&& $property_storage->type_location
&& $property_storage->type_location !== $property_storage->signature_type_location
) {
$replace_type = ExpressionAnalyzer::fleshOutType(
$replace_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$property_storage->type,
$this->getFQCLN(),
Expand Down Expand Up @@ -1027,7 +1027,7 @@ public static function addContextProperties(
$property_type_location = $property_storage->type_location;

$fleshed_out_type = !$property_type->isMixed()
? ExpressionAnalyzer::fleshOutType(
? \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$property_type,
$fq_class_name,
Expand Down Expand Up @@ -1086,7 +1086,7 @@ public static function addContextProperties(

if (isset($class_context->vars_in_scope['$this->' . $property_name])) {
$fleshed_out_type = !$property_type->isMixed()
? ExpressionAnalyzer::fleshOutType(
? \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$property_type,
$fq_class_name,
Expand Down
10 changes: 5 additions & 5 deletions src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public static function verifyReturnType(

$inferred_return_type = TypeAnalyzer::simplifyUnionType(
$codebase,
ExpressionAnalyzer::fleshOutType(
\Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$inferred_return_type,
$source->getFQCLN(),
Expand Down Expand Up @@ -375,7 +375,7 @@ public static function verifyReturnType(
}

// passing it through fleshOutTypes eradicates errant $ vars
$declared_return_type = ExpressionAnalyzer::fleshOutType(
$declared_return_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$return_type,
$self_fq_class_name,
Expand Down Expand Up @@ -719,7 +719,7 @@ public static function checkReturnType(
}
}

$fleshed_out_return_type = ExpressionAnalyzer::fleshOutType(
$fleshed_out_return_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$storage->return_type,
$classlike_storage ? $classlike_storage->name : null,
Expand All @@ -738,7 +738,7 @@ public static function checkReturnType(
return;
}

$fleshed_out_signature_type = ExpressionAnalyzer::fleshOutType(
$fleshed_out_signature_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$storage->signature_return_type,
$classlike_storage ? $classlike_storage->name : null,
Expand All @@ -760,7 +760,7 @@ public static function checkReturnType(
return;
}

$fleshed_out_return_type = ExpressionAnalyzer::fleshOutType(
$fleshed_out_return_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$storage->return_type,
$classlike_storage ? $classlike_storage->name : null,
Expand Down
14 changes: 7 additions & 7 deletions src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public function analyze(
);
} else { // Closure
if ($storage->return_type) {
$closure_return_type = ExpressionAnalyzer::fleshOutType(
$closure_return_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$storage->return_type,
$context->self,
Expand Down Expand Up @@ -958,7 +958,7 @@ private function processParams(
}

if ($signature_type) {
$signature_type = ExpressionAnalyzer::fleshOutType(
$signature_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$signature_type,
$context->self,
Expand All @@ -980,7 +980,7 @@ private function processParams(
$param_type = clone $function_param->type;
}

$param_type = ExpressionAnalyzer::fleshOutType(
$param_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$param_type,
$context->self,
Expand All @@ -1006,7 +1006,7 @@ private function processParams(
if (!$non_null_param_types && isset($implemented_docblock_param_types[$offset])) {
$param_type = clone $implemented_docblock_param_types[$offset];

$param_type = ExpressionAnalyzer::fleshOutType(
$param_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$param_type,
$context->self,
Expand Down Expand Up @@ -1301,7 +1301,7 @@ private function alterParams(
&& $storage->return_type_location
&& $storage->return_type_location !== $storage->signature_return_type_location
) {
$replace_type = ExpressionAnalyzer::fleshOutType(
$replace_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$storage->return_type,
$context->self,
Expand All @@ -1325,7 +1325,7 @@ private function alterParams(
&& $function_param->type_location !== $function_param->signature_type_location
&& $function_param->type_location->file_path === $this->getFilePath()
) {
$replace_type = ExpressionAnalyzer::fleshOutType(
$replace_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$function_param->type,
$context->self,
Expand Down Expand Up @@ -1766,7 +1766,7 @@ public function getLocalReturnType(Type\Union $storage_return_type, bool $final
return $this->local_return_type;
}

$this->local_return_type = ExpressionAnalyzer::fleshOutType(
$this->local_return_type = \Psalm\Internal\Type\UnionExpander::expand(
$this->codebase,
$storage_return_type,
$this->getFQCLN(),
Expand Down
16 changes: 8 additions & 8 deletions src/Psalm/Internal/Analyzer/MethodComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ private static function compareMethodSignatureParams(
array $suppressed_issues
) : void {
$guide_param_signature_type = $guide_param->signature_type
? ExpressionAnalyzer::fleshOutType(
? \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$guide_param->signature_type,
$guide_classlike_storage->is_trait && $guide_method_storage->abstract
Expand All @@ -436,7 +436,7 @@ private static function compareMethodSignatureParams(
)
: null;

$implementer_param_signature_type = ExpressionAnalyzer::fleshOutType(
$implementer_param_signature_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$implementer_param_signature_type,
$implementer_classlike_storage->name,
Expand Down Expand Up @@ -521,15 +521,15 @@ private static function compareMethodDocblockParams(
CodeLocation $code_location,
array $suppressed_issues
) : void {
$implementer_method_storage_param_type = ExpressionAnalyzer::fleshOutType(
$implementer_method_storage_param_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$implementer_param_type,
$implementer_classlike_storage->name,
$implementer_called_class_name,
$implementer_classlike_storage->parent_class
);

$guide_method_storage_param_type = ExpressionAnalyzer::fleshOutType(
$guide_method_storage_param_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$guide_param_type,
$guide_classlike_storage->is_trait && $guide_method_storage->abstract
Expand Down Expand Up @@ -676,7 +676,7 @@ private static function compareMethodSignatureReturnTypes(
CodeLocation $code_location,
array $suppressed_issues
) : void {
$guide_signature_return_type = ExpressionAnalyzer::fleshOutType(
$guide_signature_return_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$guide_signature_return_type,
$guide_classlike_storage->is_trait && $guide_method_storage->abstract
Expand All @@ -695,7 +695,7 @@ private static function compareMethodSignatureReturnTypes(
);

$implementer_signature_return_type = $implementer_method_storage->signature_return_type
? ExpressionAnalyzer::fleshOutType(
? \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$implementer_method_storage->signature_return_type,
$implementer_classlike_storage->is_trait
Expand Down Expand Up @@ -767,15 +767,15 @@ private static function compareMethodDocblockReturnTypes(
CodeLocation $code_location,
array $suppressed_issues
) : void {
$implementer_method_storage_return_type = ExpressionAnalyzer::fleshOutType(
$implementer_method_storage_return_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$implementer_return_type,
$implementer_classlike_storage->name,
$implementer_called_class_name,
$implementer_classlike_storage->parent_class
);

$guide_method_storage_return_type = ExpressionAnalyzer::fleshOutType(
$guide_method_storage_return_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$guide_return_type,
$guide_classlike_storage->is_trait
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static function analyze(
continue;
}

$comment_type = ExpressionAnalyzer::fleshOutType(
$comment_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$var_comment->type,
$context->self,
Expand Down Expand Up @@ -287,7 +287,7 @@ public static function analyze(
continue;
}

$comment_type = ExpressionAnalyzer::fleshOutType(
$comment_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$var_comment->type,
$context->self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static function analyzeInstance(
if ($class_property_type) {
$class_storage = $codebase->classlike_storage_provider->get($context->self);

$class_property_type = ExpressionAnalyzer::fleshOutType(
$class_property_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
clone $class_property_type,
$class_storage->name,
Expand Down Expand Up @@ -721,7 +721,7 @@ public static function analyzeInstance(
}
}
} else {
$class_property_type = ExpressionAnalyzer::fleshOutType(
$class_property_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
clone $class_property_type,
$fq_class_name,
Expand Down Expand Up @@ -1263,7 +1263,7 @@ public static function analyzeStatic(
return null;
}

$class_property_type = ExpressionAnalyzer::fleshOutType(
$class_property_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$class_property_type,
$fq_class_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static function analyze(
}

try {
$var_comment_type = ExpressionAnalyzer::fleshOutType(
$var_comment_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$var_comment->type,
$context->self,
Expand Down Expand Up @@ -744,7 +744,7 @@ public static function analyze(

try {
if ($var_comment->var_id === $list_var_id) {
$var_comment_type = ExpressionAnalyzer::fleshOutType(
$var_comment_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$var_comment->type,
$context->self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ private static function getMagicGetterOrSetterProperty(
$second_arg_type = $statements_analyzer->node_data->getType($stmt->args[1]->value);

if (isset($class_storage->pseudo_property_set_types['$' . $prop_name]) && $second_arg_type) {
$pseudo_set_type = ExpressionAnalyzer::fleshOutType(
$pseudo_set_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$class_storage->pseudo_property_set_types['$' . $prop_name],
$fq_class_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ private static function getFunctionCallReturnType(
$return_type = clone $function_storage->return_type;

if ($template_result->upper_bounds && $function_storage->template_types) {
$return_type = ExpressionAnalyzer::fleshOutType(
$return_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$return_type,
null,
Expand All @@ -951,7 +951,7 @@ private static function getFunctionCallReturnType(
);
}

$return_type = ExpressionAnalyzer::fleshOutType(
$return_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$return_type,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static function fetch(
$return_type_candidate->ignore_falsable_issues = true;
}

$return_type_candidate = ExpressionAnalyzer::fleshOutType(
$return_type_candidate = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$return_type_candidate,
$fq_class_name,
Expand Down Expand Up @@ -154,7 +154,7 @@ public static function fetch(
}

if ($template_result->upper_bounds) {
$return_type_candidate = ExpressionAnalyzer::fleshOutType(
$return_type_candidate = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$return_type_candidate,
null,
Expand All @@ -168,7 +168,7 @@ public static function fetch(
);
}

$return_type_candidate = ExpressionAnalyzer::fleshOutType(
$return_type_candidate = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$return_type_candidate,
$self_fq_class_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function handleMagicMethod(
if ($pseudo_method_storage->return_type) {
$return_type_candidate = clone $pseudo_method_storage->return_type;

$return_type_candidate = ExpressionAnalyzer::fleshOutType(
$return_type_candidate = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$return_type_candidate,
$fq_class_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ function (PhpParser\Node\Arg $arg) {
}

if ($template_result->upper_bounds) {
$return_type_candidate = ExpressionAnalyzer::fleshOutType(
$return_type_candidate = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$return_type_candidate,
null,
Expand All @@ -958,7 +958,7 @@ function (PhpParser\Node\Arg $arg) {
);
}

$return_type_candidate = ExpressionAnalyzer::fleshOutType(
$return_type_candidate = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$return_type_candidate,
$self_fq_class_name,
Expand Down Expand Up @@ -1316,7 +1316,7 @@ private static function checkPseudoMethod(
if ($pseudo_method_storage->return_type) {
$return_type_candidate = clone $pseudo_method_storage->return_type;

$return_type_candidate = ExpressionAnalyzer::fleshOutType(
$return_type_candidate = \Psalm\Internal\Type\UnionExpander::expand(
$statements_analyzer->getCodebase(),
$return_type_candidate,
$fq_class_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,7 @@ private static function checkFunctionLikeTypeMatches(
}
}

$fleshed_out_type = ExpressionAnalyzer::fleshOutType(
$fleshed_out_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$param_type,
$classlike_storage ? $classlike_storage->name : null,
Expand All @@ -1996,7 +1996,7 @@ private static function checkFunctionLikeTypeMatches(
);

$fleshed_out_signature_type = $function_param->signature_type
? ExpressionAnalyzer::fleshOutType(
? \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
$function_param->signature_type,
$classlike_storage ? $classlike_storage->name : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ public static function analyzeInstance(

$class_property_type = Type::getMixed();
} else {
$class_property_type = ExpressionAnalyzer::fleshOutType(
$class_property_type = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
clone $class_property_type,
$declaring_class_storage->name,
Expand Down Expand Up @@ -1345,7 +1345,7 @@ public static function analyzeStatic(

if ($var_id) {
if ($property->type) {
$context->vars_in_scope[$var_id] = ExpressionAnalyzer::fleshOutType(
$context->vars_in_scope[$var_id] = \Psalm\Internal\Type\UnionExpander::expand(
$codebase,
clone $property->type,
$class_storage->name,
Expand Down
Loading

0 comments on commit 5f4d162

Please sign in to comment.