|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BenTools\OpenCubes\Component\BreakDown; |
|
4
|
|
|
|
|
5
|
|
|
use BenTools\OpenCubes\Component\BreakDown\Model\Group; |
|
6
|
|
|
use BenTools\OpenCubes\Component\ComponentInterface; |
|
7
|
|
|
use Countable; |
|
8
|
|
|
use IteratorAggregate; |
|
9
|
|
|
use JsonSerializable; |
|
10
|
|
|
|
|
11
|
|
|
final class BreakDownComponent implements ComponentInterface, IteratorAggregate, Countable, JsonSerializable |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var Group[] |
|
15
|
|
|
*/ |
|
16
|
|
|
private $groups = []; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* BreakDownComponent constructor. |
|
20
|
|
|
* @param Group[] $appliedGroups |
|
|
|
|
|
|
21
|
|
|
* @param Group[] $groups |
|
22
|
|
|
*/ |
|
23
|
|
|
public function __construct(array $groups = []) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->groups = $groups; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @inheritDoc |
|
30
|
|
|
*/ |
|
31
|
|
|
public static function getName(): string |
|
32
|
|
|
{ |
|
33
|
|
|
return 'breakdown'; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param Group $group |
|
38
|
|
|
*/ |
|
39
|
|
|
public function add(Group $group): void |
|
40
|
|
|
{ |
|
41
|
|
|
$this->groups[] = $group; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param string $field |
|
46
|
|
|
* @return bool |
|
47
|
|
|
*/ |
|
48
|
|
|
public function has(string $field): bool |
|
49
|
|
|
{ |
|
50
|
|
|
foreach ($this->groups as $group) { |
|
51
|
|
|
if ($group->getField() === $field) { |
|
52
|
|
|
return true; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return false; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param string $field |
|
61
|
|
|
* @return Group |
|
62
|
|
|
* @throws \InvalidArgumentException |
|
63
|
|
|
*/ |
|
64
|
|
|
public function get(string $field): Group |
|
65
|
|
|
{ |
|
66
|
|
|
foreach ($this->groups as $group) { |
|
67
|
|
|
if ($group->getField() === $field) { |
|
68
|
|
|
return $group; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
throw new \InvalidArgumentException(sprintf('Group "%s" is not registered.', $field)); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return Group[] |
|
77
|
|
|
*/ |
|
78
|
|
|
public function all(): array |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->groups; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return Group[] |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getAppliedGroups(): array |
|
87
|
|
|
{ |
|
88
|
|
|
return array_values( |
|
89
|
|
|
array_filter( |
|
90
|
|
|
$this->groups, |
|
91
|
|
|
function (Group $group) { |
|
92
|
|
|
return $group->isApplied(); |
|
93
|
|
|
} |
|
94
|
|
|
) |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @return Group[] |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getIterator(): iterable |
|
102
|
|
|
{ |
|
103
|
|
|
return new \ArrayIterator($this->groups); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @inheritDoc |
|
108
|
|
|
*/ |
|
109
|
|
|
public function count(): int |
|
110
|
|
|
{ |
|
111
|
|
|
return count($this->groups); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @inheritDoc |
|
116
|
|
|
*/ |
|
117
|
|
|
public function jsonSerialize(): array |
|
118
|
|
|
{ |
|
119
|
|
|
return [ |
|
120
|
|
|
'groups' => $this->groups, |
|
121
|
|
|
]; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.