FieldSetViewTrait::getIterator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Bdf\Form\View;
4
5
use ArrayIterator;
6
use BadMethodCallException;
7
use Iterator;
8
9
/**
10
 * Implements @see FieldSetViewInterface
11
 *
12
 * @psalm-require-implements FieldSetViewInterface
13
 */
14
trait FieldSetViewTrait
15
{
16
    /**
17
     * @var array<string, ElementViewInterface>
18
     */
19
    private $elements = [];
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function offsetExists($offset): bool
25
    {
26
        return isset($this->elements[$offset]);
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 7
    public function offsetGet($offset): ElementViewInterface
33
    {
34 7
        return $this->elements[$offset];
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 2
    public function offsetSet($offset, $value): void
0 ignored issues
show
Unused Code introduced by
The parameter $offset is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

40
    public function offsetSet(/** @scrutinizer ignore-unused */ $offset, $value): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

40
    public function offsetSet($offset, /** @scrutinizer ignore-unused */ $value): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
41
    {
42 2
        throw new BadMethodCallException('FormView is read only');
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 2
    public function offsetUnset($offset): void
0 ignored issues
show
Unused Code introduced by
The parameter $offset is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

48
    public function offsetUnset(/** @scrutinizer ignore-unused */ $offset): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
    {
50 2
        throw new BadMethodCallException('FormView is read only');
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 27
    public function hasError(): bool
57
    {
58 27
        if ($this->error() !== null) {
0 ignored issues
show
Bug introduced by
It seems like error() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
        if ($this->/** @scrutinizer ignore-call */ error() !== null) {
Loading history...
59 11
            return true;
60
        }
61
62 16
        foreach ($this->elements as $element) {
63 15
            if ($element->hasError()) {
64 4
                return true;
65
            }
66
        }
67
68 13
        return false;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     *
74
     * @return Iterator<string, ElementViewInterface>
75
     * @psalm-suppress ImplementedReturnTypeMismatch
76
     */
77 9
    public function getIterator(): Iterator
78
    {
79 9
        return new ArrayIterator($this->elements);
80
    }
81
}
82