@@ 257-274 (lines=18) @@ | ||
254 | * @param AbstractModel $model The model to push. |
|
255 | * @return self |
|
256 | */ |
|
257 | public function push(AbstractModel $model) |
|
258 | { |
|
259 | $this->validateAdd($model); |
|
260 | if (true === $this->willAdd($model)) { |
|
261 | return $this; |
|
262 | } |
|
263 | if (true === $this->willRemove($model)) { |
|
264 | $this->evict('removed', $model); |
|
265 | $this->set('models', $model); |
|
266 | return $this; |
|
267 | } |
|
268 | if (true === $this->hasOriginal($model)) { |
|
269 | return $this; |
|
270 | } |
|
271 | $this->set('added', $model); |
|
272 | $this->set('models', $model); |
|
273 | return $this; |
|
274 | } |
|
275 | ||
276 | /** |
|
277 | * Removes a model from the collection. |
|
@@ 282-300 (lines=19) @@ | ||
279 | * @param AbstractModel $model The model to remove. |
|
280 | * @return self |
|
281 | */ |
|
282 | public function remove(AbstractModel $model) |
|
283 | { |
|
284 | $this->validateAdd($model); |
|
285 | if (true === $this->willRemove($model)) { |
|
286 | return $this; |
|
287 | } |
|
288 | ||
289 | if (true === $this->willAdd($model)) { |
|
290 | $this->evict('added', $model); |
|
291 | $this->evict('models', $model); |
|
292 | return $this; |
|
293 | } |
|
294 | ||
295 | if (true === $this->hasOriginal($model)) { |
|
296 | $this->evict('models', $model); |
|
297 | $this->set('removed', $model); |
|
298 | } |
|
299 | return $this; |
|
300 | } |
|
301 | ||
302 | /** |
|
303 | * {@inheritDoc} |