Skip to content
Permalink
Browse files

Use object instead of by-ref params

  • Loading branch information...
muglug committed Jul 10, 2019
1 parent d424cb3 commit 1ae9ea5fed81ed33464949ce57b034ffe8879d71
@@ -231,10 +231,7 @@ public static function verifyReturnType(
$inferred_return_type,
Type::getString(),
$inferred_return_type->ignore_nullable_issues,
$inferred_return_type->ignore_falsable_issues,
$has_scalar_match,
$type_coerced,
$type_coerced_from_mixed
$inferred_return_type->ignore_falsable_issues
)
) {
if (IssueBuffer::accepts(
@@ -413,19 +410,19 @@ public static function verifyReturnType(
return null;
}
$union_comparison_results = new \Psalm\Internal\Analyzer\TypeComparisonResult();
if (!TypeAnalyzer::isContainedBy(
$codebase,
$inferred_return_type,
$declared_return_type,
true,
true,
$has_scalar_match,
$type_coerced,
$type_coerced_from_mixed
$union_comparison_results
)) {
// is the declared return type more specific than the inferred one?
if ($type_coerced) {
if ($type_coerced_from_mixed) {
if ($union_comparison_results->type_coerced) {
if ($union_comparison_results->type_coerced_from_mixed) {
if (IssueBuffer::accepts(
new MixedReturnTypeCoercion(
'The declared return type \'' . $declared_return_type->getId() . '\' for '
@@ -617,16 +617,16 @@ function (FunctionLikeParameter $p) {
}
if ($signature_type) {
$union_comparison_result = new TypeComparisonResult();
if (!TypeAnalyzer::isContainedBy(
$codebase,
$param_type,
$signature_type,
false,
false,
$has_scalar_match,
$type_coerced,
$type_coerced_from_mixed
) && !$type_coerced_from_mixed
$union_comparison_result
) && !$union_comparison_result->type_coerced_from_mixed
) {
if ($codebase->alter_code
&& isset($project_analyzer->getIssuesToFix()['MismatchingDocblockParamType'])
@@ -676,11 +676,7 @@ function (FunctionLikeParameter $p) {
$param_type,
false,
false,
$has_scalar_match,
$type_coerced,
$type_coerced_from_mixed,
$to_string_cast,
$type_coerced_from_scalar,
null,
true
)
) {
@@ -701,18 +701,18 @@ public static function compareMethods(
$guide_method_storage_return_type = Type::getNull();
}
$union_comparison_results = new TypeComparisonResult();
if (!TypeAnalyzer::isContainedBy(
$codebase,
$implementer_method_storage_return_type,
$guide_method_storage_return_type,
false,
false,
$has_scalar_match,
$type_coerced,
$type_coerced_from_mixed
$union_comparison_results
)) {
// is the declared return type more specific than the inferred one?
if ($type_coerced) {
if ($union_comparison_results->type_coerced) {
if (IssueBuffer::accepts(
new LessSpecificImplementedReturnType(
'The return type \'' . $guide_method_storage_return_type->getId()
@@ -914,18 +914,18 @@ public static function compareMethods(
);
}
$union_comparison_results = new TypeComparisonResult();
if (!TypeAnalyzer::isContainedBy(
$codebase,
$guide_method_storage_param_type,
$implementer_method_storage_param_type,
!$guide_classlike_storage->user_defined,
!$guide_classlike_storage->user_defined,
$has_scalar_match,
$type_coerced,
$type_coerced_from_mixed
$union_comparison_results
)) {
// is the declared return type more specific than the inferred one?
if ($type_coerced) {
if ($union_comparison_results->type_coerced) {
if ($guide_classlike_storage->user_defined) {
if (IssueBuffer::accepts(
new MoreSpecificImplementedParamType(
@@ -732,20 +732,19 @@ public static function analyzeInstance(
continue;
}
$union_comparison_results = new \Psalm\Internal\Analyzer\TypeComparisonResult();
$type_match_found = TypeAnalyzer::isContainedBy(
$codebase,
$assignment_value_type,
$class_property_type,
true,
true,
$has_scalar_match,
$type_coerced,
$type_coerced_from_mixed,
$to_string_cast
$union_comparison_results
);
if ($type_coerced) {
if ($type_coerced_from_mixed) {
if ($union_comparison_results->type_coerced) {
if ($union_comparison_results->type_coerced_from_mixed) {
if (IssueBuffer::accepts(
new MixedPropertyTypeCoercion(
$var_id . ' expects \'' . $class_property_type->getId() . '\', '
@@ -780,7 +779,7 @@ public static function analyzeInstance(
}
}
if ($to_string_cast) {
if ($union_comparison_results->to_string_cast) {
if (IssueBuffer::accepts(
new ImplicitToStringCast(
$var_id . ' expects \'' . $class_property_type . '\', '
@@ -797,7 +796,7 @@ public static function analyzeInstance(
}
}
if (!$type_match_found && !$type_coerced) {
if (!$type_match_found && !$union_comparison_results->type_coerced) {
if (TypeAnalyzer::canBeContainedBy(
$codebase,
$assignment_value_type,
@@ -1067,20 +1066,19 @@ public static function analyzeStatic(
$class_storage->parent_class
);
$union_comparison_results = new \Psalm\Internal\Analyzer\TypeComparisonResult();
$type_match_found = TypeAnalyzer::isContainedBy(
$codebase,
$assignment_value_type,
$class_property_type,
true,
true,
$has_scalar_match,
$type_coerced,
$type_coerced_from_mixed,
$to_string_cast
$union_comparison_results
);
if ($type_coerced) {
if ($type_coerced_from_mixed) {
if ($union_comparison_results->type_coerced) {
if ($union_comparison_results->type_coerced_from_mixed) {
if (IssueBuffer::accepts(
new MixedPropertyTypeCoercion(
$var_id . ' expects \'' . $class_property_type . '\', '
@@ -1115,7 +1113,7 @@ public static function analyzeStatic(
}
}
if ($to_string_cast) {
if ($union_comparison_results->to_string_cast) {
if (IssueBuffer::accepts(
new ImplicitToStringCast(
$var_id . ' expects \'' . $class_property_type . '\', '
@@ -1132,7 +1130,7 @@ public static function analyzeStatic(
}
}
if (!$type_match_found && !$type_coerced) {
if (!$type_match_found && !$union_comparison_results->type_coerced) {
if (TypeAnalyzer::canBeContainedBy($codebase, $assignment_value_type, $class_property_type)) {
if (IssueBuffer::accepts(
new PossiblyInvalidPropertyAssignmentValue(
@@ -1337,12 +1337,12 @@ public static function analyzeConcatOp(
$left_type_match = true;
$right_type_match = true;
$left_has_scalar_match = false;
$right_has_scalar_match = false;
$has_valid_left_operand = false;
$has_valid_right_operand = false;
$left_comparison_result = new \Psalm\Internal\Analyzer\TypeComparisonResult();
$right_comparison_result = new \Psalm\Internal\Analyzer\TypeComparisonResult();
foreach ($left_type->getTypes() as $left_type_part) {
if ($left_type_part instanceof Type\Atomic\TTemplateParam) {
if (IssueBuffer::accepts(
@@ -1368,17 +1368,14 @@ public static function analyzeConcatOp(
new Type\Atomic\TString,
false,
false,
$left_has_scalar_match,
$left_type_coerced,
$left_type_coerced_from_mixed,
$left_to_string_cast
$left_comparison_result
);
$left_type_match = $left_type_match && $left_type_part_match;
$has_valid_left_operand = $has_valid_left_operand || $left_type_part_match;
if ($left_to_string_cast && $config->strict_binary_operands) {
if ($left_comparison_result->to_string_cast && $config->strict_binary_operands) {
if (IssueBuffer::accepts(
new ImplicitToStringCast(
'Left side of concat op expects string, '
@@ -1417,17 +1414,14 @@ public static function analyzeConcatOp(
new Type\Atomic\TString,
false,
false,
$right_has_scalar_match,
$right_type_coerced,
$right_type_coerced_from_mixed,
$right_to_string_cast
$right_comparison_result
);
$right_type_match = $right_type_match && $right_type_part_match;
$has_valid_right_operand = $has_valid_right_operand || $right_type_part_match;
if ($right_to_string_cast && $config->strict_binary_operands) {
if ($right_comparison_result->to_string_cast && $config->strict_binary_operands) {
if (IssueBuffer::accepts(
new ImplicitToStringCast(
'Right side of concat op expects string, '
@@ -1441,7 +1435,9 @@ public static function analyzeConcatOp(
}
}
if (!$left_type_match && (!$left_has_scalar_match || $config->strict_binary_operands)) {
if (!$left_type_match
&& (!$left_comparison_result->scalar_type_match_found || $config->strict_binary_operands)
) {
if ($has_valid_left_operand) {
if (IssueBuffer::accepts(
new PossiblyInvalidOperand(
@@ -1465,7 +1461,9 @@ public static function analyzeConcatOp(
}
}
if (!$right_type_match && (!$right_has_scalar_match || $config->strict_binary_operands)) {
if (!$right_type_match
&& (!$right_comparison_result->scalar_type_match_found || $config->strict_binary_operands)
) {
if ($has_valid_right_operand) {
if (IssueBuffer::accepts(
new PossiblyInvalidOperand(
@@ -1578,20 +1578,19 @@ private static function checkMagicGetterOrSetterProperty(
$class_storage->parent_class
);
$union_comparison_results = new \Psalm\Internal\Analyzer\TypeComparisonResult();
$type_match_found = TypeAnalyzer::isContainedBy(
$codebase,
$second_arg_type,
$pseudo_set_type,
$second_arg_type->ignore_nullable_issues,
$second_arg_type->ignore_falsable_issues,
$has_scalar_match,
$type_coerced,
$type_coerced_from_mixed,
$to_string_cast
$union_comparison_results
);
if ($type_coerced) {
if ($type_coerced_from_mixed) {
if ($union_comparison_results->type_coerced) {
if ($union_comparison_results->type_coerced_from_mixed) {
if (IssueBuffer::accepts(
new MixedPropertyTypeCoercion(
$prop_name . ' expects \'' . $pseudo_set_type . '\', '
@@ -1618,7 +1617,7 @@ private static function checkMagicGetterOrSetterProperty(
}
}
if (!$type_match_found && !$type_coerced_from_mixed) {
if (!$type_match_found && !$union_comparison_results->type_coerced_from_mixed) {
if (TypeAnalyzer::canBeContainedBy(
$codebase,
$second_arg_type,

0 comments on commit 1ae9ea5

Please sign in to comment.
You can’t perform that action at this time.