1 | <?php |
||
28 | class EntityCollection extends AbstractList implements |
||
29 | EntityCollectionInterface |
||
30 | { |
||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $type; |
||
35 | |||
36 | /** |
||
37 | * @var RepositoryInterface |
||
38 | */ |
||
39 | protected $repository; |
||
40 | |||
41 | /** |
||
42 | * @var EntityInterface|null |
||
43 | */ |
||
44 | protected $parentEntity; |
||
45 | |||
46 | /** |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $cid; |
||
50 | |||
51 | /** |
||
52 | * Emitter methods |
||
53 | */ |
||
54 | use EmitterAwareTrait; |
||
55 | |||
56 | /** |
||
57 | * Creates the collection for entity type with provided data |
||
58 | * |
||
59 | * @param string $entityType |
||
60 | * @param array|\Traversable $data |
||
61 | */ |
||
62 | 34 | public function __construct($entityType, $data = []) |
|
67 | |||
68 | /** |
||
69 | * Offset to set |
||
70 | * |
||
71 | * @link http://php.net/manual/en/arrayaccess.offsetset.php |
||
72 | * |
||
73 | * @param mixed $offset The offset to assign the value to. |
||
74 | * @param mixed $value The value to set. |
||
75 | */ |
||
76 | 2 | public function offsetSet($offset, $value) |
|
80 | |||
81 | /** |
||
82 | * Adds an entity to the collection |
||
83 | * |
||
84 | * This method adds an entity to the collection by accepting the entity |
||
85 | * itself or the entity id value |
||
86 | * |
||
87 | * @param EntityInterface|integer $entity |
||
88 | * |
||
89 | * @throws EntityNotFoundException If the provided id is does not |
||
90 | * references an existing entity. |
||
91 | * @throws InvalidArgumentException If the entity is not from |
||
92 | * the provided entity type |
||
93 | * |
||
94 | * @return self |
||
95 | */ |
||
96 | 12 | public function add($entity) |
|
103 | |||
104 | /** |
||
105 | * Adds an entity to the collection |
||
106 | * |
||
107 | * @param EntityInterface $entity |
||
108 | * @throws InvalidArgumentException If the entity is not from |
||
109 | * the provided entity type |
||
110 | * |
||
111 | * @return self |
||
112 | */ |
||
113 | 10 | public function addEntity(EntityInterface $entity) |
|
125 | |||
126 | /** |
||
127 | * Adds an entity by entity id |
||
128 | * |
||
129 | * @param mixed $entityId |
||
130 | * |
||
131 | * @throws EntityNotFoundException If the provided id is does not |
||
132 | * references an existing entity. |
||
133 | * @throws InvalidArgumentException If the entity is not from |
||
134 | * the provided entity type |
||
135 | * |
||
136 | * @return self |
||
137 | */ |
||
138 | 4 | public function addEntityWithId($entityId) |
|
149 | |||
150 | /** |
||
151 | * Gets entity repository for this collection |
||
152 | * |
||
153 | * @return RepositoryInterface |
||
154 | */ |
||
155 | 6 | public function getRepository() |
|
162 | |||
163 | /** |
||
164 | * Set repository for this entity collection |
||
165 | * |
||
166 | * @param RepositoryInterface $repository |
||
167 | * |
||
168 | * @return self|$this|EntityCollection |
||
169 | */ |
||
170 | 6 | public function setRepository(RepositoryInterface $repository) |
|
175 | |||
176 | /** |
||
177 | * Get the parent entity if this collection is a relation in other entity |
||
178 | * |
||
179 | * @return null|EntityInterface |
||
180 | */ |
||
181 | 2 | public function parentEntity() |
|
185 | |||
186 | /** |
||
187 | * Set the parent entity if this collection is a relation in other entity |
||
188 | * |
||
189 | * @param EntityInterface $entity |
||
190 | * |
||
191 | * @return self |
||
192 | */ |
||
193 | 4 | public function setParentEntity(EntityInterface $entity) |
|
198 | |||
199 | /** |
||
200 | * Gets the cache id used for this collection |
||
201 | * |
||
202 | * @return string |
||
203 | */ |
||
204 | public function getId() |
||
208 | |||
209 | /** |
||
210 | * Sets the cache id used for this collection |
||
211 | * |
||
212 | * @param string $collectionId |
||
213 | * |
||
214 | * @return self |
||
215 | */ |
||
216 | 4 | public function setId($collectionId) |
|
221 | |||
222 | /** |
||
223 | * Removes the element at the given index, and returns it. |
||
224 | * |
||
225 | * @param integer|EntityInterface $index |
||
226 | * |
||
227 | * @return EntityInterface|null |
||
228 | */ |
||
229 | public function remove($index) |
||
237 | |||
238 | /** |
||
239 | * Iterates over the collection to remove an entity if found |
||
240 | * |
||
241 | * @param EntityInterface|null $entity |
||
242 | * @return EntityInterface |
||
243 | */ |
||
244 | protected function findAndRemove(EntityInterface $entity = null) |
||
270 | } |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.