|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Injector; |
|
6
|
|
|
|
|
7
|
|
|
use ReflectionNamedType; |
|
8
|
|
|
use ReflectionUnionType; |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
abstract class ArgumentException extends \InvalidArgumentException |
|
11
|
|
|
{ |
|
12
|
|
|
protected const EXCEPTION_MESSAGE = 'Something is wrong with argument "%s" when calling "%s"%s.'; |
|
13
|
|
|
|
|
14
|
33 |
|
public function __construct(\ReflectionFunctionAbstract $reflection, string $parameter) |
|
15
|
|
|
{ |
|
16
|
33 |
|
$function = $reflection->getName(); |
|
17
|
33 |
|
$class = $reflection->class ?? null; |
|
18
|
|
|
|
|
19
|
33 |
|
if ($class === null) { |
|
20
|
26 |
|
$method = $function; |
|
21
|
26 |
|
if (substr($method, -9) === '{closure}') { |
|
22
|
26 |
|
$method = $this->getClosureSignature($reflection); |
|
23
|
|
|
} |
|
24
|
|
|
} else { |
|
25
|
7 |
|
$method = "{$class}::{$function}"; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
33 |
|
$fileName = $reflection->getFileName(); |
|
29
|
33 |
|
$line = $reflection->getStartLine(); |
|
30
|
|
|
|
|
31
|
33 |
|
$fileAndLine = ''; |
|
32
|
33 |
|
if (!empty($fileName)) { |
|
33
|
23 |
|
$fileAndLine = " in \"$fileName\" at line $line"; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
33 |
|
parent::__construct(sprintf(static::EXCEPTION_MESSAGE, $parameter, $method, $fileAndLine)); |
|
37
|
33 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @phan-suppress PhanUndeclaredClassInstanceof, PhanUndeclaredClassMethod |
|
41
|
|
|
*/ |
|
42
|
14 |
|
private function getClosureSignature(\ReflectionFunctionAbstract $reflection): string |
|
43
|
|
|
{ |
|
44
|
14 |
|
$closureParameters = []; |
|
45
|
14 |
|
$append = static function (bool $condition, string $postfix) use (&$parameterString): void { |
|
46
|
13 |
|
if ($condition) { |
|
47
|
4 |
|
$parameterString .= $postfix; |
|
48
|
|
|
} |
|
49
|
14 |
|
}; |
|
50
|
14 |
|
foreach ($reflection->getParameters() as $parameter) { |
|
51
|
13 |
|
$parameterString = ''; |
|
52
|
13 |
|
$type = $parameter->getType(); |
|
53
|
13 |
|
if ($type instanceof ReflectionNamedType) { |
|
54
|
13 |
|
$append($parameter->allowsNull(), '?'); |
|
55
|
13 |
|
$parameterString .= $type->getName() . ' '; |
|
56
|
4 |
|
} elseif ($type instanceof ReflectionUnionType) { |
|
57
|
|
|
$parameterString .= implode('|', array_map( |
|
58
|
|
|
fn (ReflectionNamedType $r) => $r->getName(), |
|
59
|
|
|
$type->getTypes() |
|
|
|
|
|
|
60
|
|
|
)) . ' '; |
|
61
|
|
|
} |
|
62
|
13 |
|
$append($parameter->isPassedByReference(), '&'); |
|
63
|
13 |
|
$append($parameter->isVariadic(), '...'); |
|
64
|
13 |
|
$parameterString .= '$' . $parameter->name; |
|
65
|
13 |
|
if ($parameter->isDefaultValueAvailable()) { |
|
66
|
3 |
|
$parameterString .= ' = ' . var_export($parameter->getDefaultValue(), true); |
|
67
|
|
|
} |
|
68
|
13 |
|
$closureParameters[] = $parameterString; |
|
69
|
|
|
} |
|
70
|
14 |
|
return 'function (' . implode(', ', $closureParameters) . ')'; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths