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