1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Del\Form\Collection; |
||
6 | |||
7 | use Del\Form\Field\FieldInterface; |
||
8 | |||
9 | class FieldCollection extends AbstractCollection implements CollectionInterface |
||
10 | { |
||
11 | /** |
||
12 | * @param $name |
||
13 | * @return FieldInterface|null |
||
14 | */ |
||
15 | 5 | public function findByName($name) |
|
16 | { |
||
17 | 5 | $this->rewind(); |
|
18 | 5 | while ($this->valid()) { |
|
19 | /** @var FieldInterface $field */ |
||
20 | 4 | $field = $this->current(); |
|
21 | 4 | if ($field->getName() == $name) { |
|
22 | 4 | return $field; |
|
23 | } |
||
24 | 2 | $this->next(); |
|
25 | } |
||
26 | 1 | $this->rewind(); |
|
27 | 1 | return null; |
|
28 | } |
||
29 | |||
30 | /** |
||
31 | * @param $name |
||
32 | * @return bool |
||
33 | */ |
||
34 | 1 | public function removeByName($name): bool |
|
35 | { |
||
36 | 1 | $this->rewind(); |
|
37 | |||
38 | 1 | while ($this->valid()) { |
|
39 | 1 | $field = $this->current(); |
|
40 | |||
41 | 1 | if ($field->getName() == $name) { |
|
42 | 1 | $key = $this->key(); |
|
43 | 1 | $this->offsetUnset($key); |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
44 | 1 | $this->rewind(); |
|
45 | |||
46 | 1 | return true; |
|
47 | } |
||
48 | 1 | $this->next(); |
|
49 | } |
||
50 | |||
51 | 1 | $this->rewind(); |
|
52 | |||
53 | 1 | return false; |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * @return FieldInterface |
||
58 | */ |
||
59 | 57 | public function current(): FieldInterface |
|
60 | { |
||
61 | 57 | return parent::current(); |
|
62 | } |
||
63 | } |
||
64 |