| Total Complexity | 8 |
| Total Lines | 68 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | final class PropertyCollection implements IteratorAggregate |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * Array of [@see Property] objects |
||
| 25 | * |
||
| 26 | * @var Property[] |
||
| 27 | */ |
||
| 28 | private $elements = []; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param Property $property |
||
| 32 | * @return void |
||
| 33 | */ |
||
| 34 | 8 | public function add(Property $property): void |
|
| 35 | { |
||
| 36 | 8 | $this->elements[$property->getSerializedName()] = $property; |
|
| 37 | 8 | } |
|
| 38 | |||
| 39 | /** |
||
| 40 | * Get [@see Property] by property name |
||
| 41 | * |
||
| 42 | * @param string $propertyName |
||
| 43 | * @return Property|null |
||
| 44 | */ |
||
| 45 | 2 | public function getByName(string $propertyName): ?Property |
|
| 46 | { |
||
| 47 | 2 | foreach ($this->elements as $property) { |
|
| 48 | 1 | if ($property->getName() === $propertyName) { |
|
| 49 | 1 | return $property; |
|
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | 1 | return null; |
|
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Get [@see Property] by serialized name |
||
| 58 | * |
||
| 59 | * @param string $name |
||
| 60 | * @return Property|null |
||
| 61 | */ |
||
| 62 | 5 | public function getBySerializedName(string $name): ?Property |
|
| 63 | { |
||
| 64 | 5 | if (!isset($this->elements[$name])) { |
|
| 65 | 4 | return null; |
|
| 66 | } |
||
| 67 | |||
| 68 | 2 | return $this->elements[$name]; |
|
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Array of Property objects |
||
| 73 | * |
||
| 74 | * @return Property[] |
||
| 75 | */ |
||
| 76 | 3 | public function toArray(): array |
|
| 77 | { |
||
| 78 | 3 | return \array_values($this->elements); |
|
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Retrieve an external iterator |
||
| 83 | * |
||
| 84 | * @return ArrayIterator |
||
| 85 | */ |
||
| 86 | 1 | public function getIterator(): ArrayIterator |
|
| 89 | } |
||
| 90 | } |
||
| 91 |