1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\AdminBundle\Admin; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Thomas Rabaix <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
final class FieldDescriptionCollection implements \ArrayAccess, \Countable |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var FieldDescriptionInterface[] |
23
|
|
|
*/ |
24
|
|
|
private $elements = []; |
25
|
|
|
|
26
|
|
|
public function add(FieldDescriptionInterface $fieldDescription): void |
27
|
|
|
{ |
28
|
|
|
$this->elements[$fieldDescription->getName()] = $fieldDescription; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function getElements(): array |
32
|
|
|
{ |
33
|
|
|
return $this->elements; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function has(string $name): bool |
37
|
|
|
{ |
38
|
|
|
return \array_key_exists($name, $this->elements); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @throws \InvalidArgumentException |
43
|
|
|
*/ |
44
|
|
|
public function get(string $name): FieldDescriptionInterface |
45
|
|
|
{ |
46
|
|
|
if ($this->has($name)) { |
47
|
|
|
return $this->elements[$name]; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
throw new \InvalidArgumentException(sprintf('Element "%s" does not exist.', $name)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function remove(string $name): void |
54
|
|
|
{ |
55
|
|
|
if ($this->has($name)) { |
56
|
|
|
unset($this->elements[$name]); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function offsetExists($offset): bool |
61
|
|
|
{ |
62
|
|
|
return $this->has($offset); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function offsetGet($offset): FieldDescriptionInterface |
66
|
|
|
{ |
67
|
|
|
return $this->get($offset); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function offsetSet($offset, $value): void |
71
|
|
|
{ |
72
|
|
|
throw new \RuntimeException('Cannot set value, use add'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function offsetUnset($offset): void |
76
|
|
|
{ |
77
|
|
|
$this->remove($offset); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function count(): int |
81
|
|
|
{ |
82
|
|
|
return \count($this->elements); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function reorder(array $keys): void |
86
|
|
|
{ |
87
|
|
|
if ($this->has('batch')) { |
88
|
|
|
array_unshift($keys, 'batch'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$this->elements = array_merge(array_flip($keys), $this->elements); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..