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