Skip to content

Commit

Permalink
Use verbosity level value() when the parameter type contains callable
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Aug 17, 2019
1 parent 47a5cd2 commit b343bbf
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Rules/FunctionCallParametersCheck.php
Expand Up @@ -156,7 +156,7 @@ public function check(
&& !$this->ruleLevelHelper->accepts($parameterType, $argumentValueType, $scope->isDeclareStrictTypes())
&& ($secondAccepts === null || !$secondAccepts)
) {
$verbosityLevel = $parameterType->isCallable()->yes() || count(TypeUtils::getConstantArrays($parameterType)) > 0
$verbosityLevel = TypeUtils::containsCallable($parameterType) || count(TypeUtils::getConstantArrays($parameterType)) > 0
? VerbosityLevel::value()
: VerbosityLevel::typeOnly();
$errors[] = sprintf(
Expand Down
17 changes: 17 additions & 0 deletions src/Type/TypeUtils.php
Expand Up @@ -242,4 +242,21 @@ public static function getAccessoryTypes(Type $type): array
return self::map(AccessoryType::class, $type, true, false);
}

public static function containsCallable(Type $type): bool
{
if ($type->isCallable()->yes()) {
return true;
}

if ($type instanceof UnionType) {
foreach ($type->getTypes() as $innerType) {
if ($innerType->isCallable()->yes()) {
return true;
}
}
}

return false;
}

}
Expand Up @@ -39,6 +39,10 @@ public function testCallToFunctionWithIncorrectParameters(): void
'Parameter #1 $foo of function IncorrectCallToFunction\bar expects int, string given.',
14,
],
[
'Parameter #1 $error_handler of function set_error_handler expects (callable(int, string, string, int, array): bool)|null, Closure(mixed, mixed, mixed, mixed): void given.',
16,
],
]);
}

Expand Down
Expand Up @@ -12,3 +12,7 @@
];
$keys = array_keys($array);
bar($keys[0]);

set_error_handler(function ($errno, $errstr, $errfile, $errline): void {
// ...
});

0 comments on commit b343bbf

Please sign in to comment.