Skip to content

Commit

Permalink
Split checks out into separate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed May 20, 2019
1 parent 2f4c528 commit 93b6617
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"phpunit/phpunit": "^6.0 || ^7.0 || ^8.0",
"vimeo/psalm": "^3.2.9 || dev-master",
"composer/semver": "^1.4",
"ocramius/package-versions": "^1.2"
"ocramius/package-versions": "^1.3"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.3.1",
Expand Down
33 changes: 25 additions & 8 deletions hooks/TestCaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,38 @@ public static function afterStatementAnalysis(
// TODO: this may get implemented in a future Psalm version, remove it then
$provider_return_type = self::unionizeIterables($codebase, $provider_return_type);

$type_coerced = false;

if (!self::isTypeContainedByType(
$codebase,
$provider_return_type->type_params[0],
$expected_provider_return_type->type_params[0]
) || !self::isTypeContainedByType(
)) {
if ($provider_return_type->type_params[0]->hasMixed()
|| $provider_return_type->type_params[0]->hasArrayKey()
) {
IssueBuffer::accepts(new Issue\MixedInferredReturnType(
'Providers must return ' . $expected_provider_return_type->getId()
. ', possibly different ' . $provider_return_type_string . ' provided',
$provider_return_type_location
));
} else {
IssueBuffer::accepts(new Issue\InvalidReturnType(
'Providers must return ' . $expected_provider_return_type->getId()
. ', ' . $provider_return_type_string . ' provided',
$provider_return_type_location
));
}
continue;
}

if (!self::isTypeContainedByType(
$codebase,
$provider_return_type->type_params[1],
$expected_provider_return_type->type_params[1]
)) {
if ($provider_return_type->type_params[0]->hasMixed()
|| $provider_return_type->type_params[1]->hasMixed()) {
IssueBuffer::accepts(new Issue\InvalidReturnType(
if ($provider_return_type->type_params[1]->hasMixed()) {
IssueBuffer::accepts(new Issue\MixedInferredReturnType(
'Providers must return ' . $expected_provider_return_type->getId()
. ', possibly different ' . $provider_return_type_string . ' provided',
$provider_return_type_location
Expand All @@ -240,9 +260,6 @@ public static function afterStatementAnalysis(
}

$checkParam =
/**
* @return void
*/
function (
Type\Union $potential_argument_type,
Type\Union $param_type,
Expand All @@ -254,7 +271,7 @@ function (
$provider_method_id,
$provider_return_type_string,
$provider_docblock_location
) {
) : void {
$param_type = clone $param_type;
if ($is_optional) {
$param_type->possibly_undefined = true;
Expand Down

0 comments on commit 93b6617

Please sign in to comment.