Passed
Branch master (3daac1)
by Vincent
07:53
created

FieldSetViewTrait   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 88.24%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 13
c 1
b 0
f 0
dl 0
loc 66
ccs 15
cts 17
cp 0.8824
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetSet() 0 3 1
A getIterator() 0 3 1
A offsetUnset() 0 3 1
A offsetGet() 0 3 1
A hasError() 0 13 4
A offsetExists() 0 3 1
1
<?php
2
3
namespace Bdf\Form\View;
4
5
use ArrayIterator;
6
use BadMethodCallException;
7
8
/**
9
 * Implements @see FieldSetViewInterface
10
 */
11
trait FieldSetViewTrait
12
{
13
    /**
14
     * @var array<string, ElementViewInterface>
15
     */
16
    private $elements = [];
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function offsetExists($offset): bool
22
    {
23
        return isset($this->elements[$offset]);
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 6
    public function offsetGet($offset)
30
    {
31 6
        return $this->elements[$offset];
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 2
    public function offsetSet($offset, $value)
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

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

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

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

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...
38
    {
39 2
        throw new BadMethodCallException('FormView is read only');
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 2
    public function offsetUnset($offset)
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

45
    public function offsetUnset(/** @scrutinizer ignore-unused */ $offset)

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...
46
    {
47 2
        throw new BadMethodCallException('FormView is read only');
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 27
    public function hasError(): bool
54
    {
55 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

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