Total Complexity | 14 |
Total Lines | 73 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
7 | class IdMetadata |
||
8 | { |
||
9 | /** |
||
10 | * @var PropertyMetadata[] |
||
11 | */ |
||
12 | private $ids = []; |
||
13 | |||
14 | public function append(PropertyMetadata $metadata) |
||
15 | { |
||
16 | $this->ids[] = $metadata; |
||
17 | } |
||
18 | |||
19 | public function getValue($object) |
||
20 | { |
||
21 | if (!$this->hasIds()) { |
||
22 | throw new \RuntimeException("transfer " . get_class($object) . " has no id mapping"); |
||
23 | } |
||
24 | |||
25 | if ($this->isMultiId()) { |
||
26 | $values = []; |
||
27 | |||
28 | foreach ($this->ids as $idMetadata) { |
||
29 | $value = $idMetadata->getValue($object); |
||
30 | |||
31 | if (!$value) { |
||
32 | continue; |
||
33 | } |
||
34 | |||
35 | $values[] = sprintf('%s=%s', $idMetadata->name, $idMetadata->getValue($object)); |
||
36 | } |
||
37 | |||
38 | return implode(';', $values); |
||
39 | } |
||
40 | |||
41 | return $this->ids[0]->getValue($object); |
||
42 | } |
||
43 | |||
44 | public function hasIds(): bool |
||
47 | } |
||
48 | |||
49 | public function getName() |
||
62 | } |
||
63 | |||
64 | public function isMultiId(): bool |
||
65 | { |
||
66 | return count($this->ids) > 1; |
||
67 | } |
||
68 | |||
69 | public function getType(): string |
||
80 | } |
||
81 | } |
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.