Total Complexity | 6 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
21 | final class Merge implements Constructor |
||
22 | { |
||
23 | /** |
||
24 | * {@inheritdoc} |
||
25 | */ |
||
26 | 13 | public static function fromString(Str $value): Constructor |
|
27 | { |
||
28 | 13 | if ((string) $value !== 'merge') { |
|
29 | 8 | throw new ValueNotSupported((string) $value); |
|
30 | } |
||
31 | |||
32 | 5 | return new self; |
|
33 | } |
||
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | 3 | public function __invoke(...$arguments): object |
|
39 | { |
||
40 | try { |
||
41 | 3 | $arguments = Stream::of(SetInterface::class, ...$arguments); |
|
42 | 2 | } catch (InvalidArgumentException $e) { |
|
43 | 2 | $arguments = Stream::of(MapInterface::class, ...$arguments); |
|
44 | } |
||
45 | |||
46 | return $arguments |
||
47 | 2 | ->drop(1) |
|
48 | 2 | ->reduce( |
|
49 | 2 | $arguments->first(), |
|
50 | 2 | static function($structure, $element) { |
|
51 | 2 | return $structure->merge($element); |
|
52 | 2 | } |
|
53 | ); |
||
54 | } |
||
55 | |||
56 | 1 | public function compile(CompiledArgument ...$arguments): CompiledConstructor |
|
57 | { |
||
58 | 1 | return new CompiledMerge(...$arguments); |
|
2 ignored issues
–
show
|
|||
59 | } |
||
60 | |||
61 | 1 | public function __toString(): string |
|
64 | } |
||
65 | } |
||
66 |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.