b2pweb /
bdf-form
| 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
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
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
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
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
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
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 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.