Total Complexity | 10 |
Total Lines | 62 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
12 | final class TabCollection |
||
13 | { |
||
14 | use SortableElementsTrait; |
||
15 | |||
16 | /** |
||
17 | * @var Tab[] |
||
18 | */ |
||
19 | private $tabs = []; |
||
20 | |||
21 | private function __construct() |
||
22 | { |
||
23 | } |
||
24 | |||
25 | public static function create(): self |
||
26 | { |
||
27 | return new self(); |
||
28 | } |
||
29 | |||
30 | public function add(Tab $tab): void |
||
31 | { |
||
32 | if ($this->has($tab->getName())) { |
||
33 | throw new \InvalidArgumentException(sprintf( |
||
34 | 'Tab "%s" already in collection.', |
||
35 | $tab->getName() |
||
36 | )); |
||
37 | } |
||
38 | |||
39 | $this->tabs[$tab->getName()] = $tab; |
||
40 | } |
||
41 | |||
42 | public function has(string $name): bool |
||
43 | { |
||
44 | return isset($this->tabs[$name]); |
||
45 | } |
||
46 | |||
47 | public function get(string $name): Tab |
||
48 | { |
||
49 | if (!$this->has($name)) { |
||
50 | throw new \InvalidArgumentException(sprintf( |
||
51 | 'Tab "%s" not found in collection.', |
||
52 | $name |
||
53 | )); |
||
54 | } |
||
55 | |||
56 | return $this->tabs[$name]; |
||
57 | } |
||
58 | |||
59 | public function isEmpty(): bool |
||
62 | } |
||
63 | |||
64 | public function render(FormMapper $formMapper): void |
||
65 | { |
||
74 | } |
||
75 | } |
||
76 | } |