| Total Complexity | 8 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 3 | Features | 1 |
| 1 | <?php |
||
| 11 | trait MediaOperationsTraits |
||
| 12 | { |
||
| 13 | /** @inheritDoc |
||
| 14 | */ |
||
| 15 | public function filter(callable $callback = null) |
||
| 16 | { |
||
| 17 | $filtered = parent::filter($callback); |
||
| 18 | $filtered->rehydrateFromSibling($this); |
||
| 19 | return $filtered; |
||
| 20 | } |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @param string $key |
||
| 24 | */ |
||
| 25 | public function deleteMediaByKey($key) |
||
| 26 | { |
||
| 27 | $this->get($key)->delete(); |
||
|
|
|||
| 28 | $this->unset($key); |
||
| 29 | } |
||
| 30 | |||
| 31 | public function delete() |
||
| 32 | { |
||
| 33 | foreach ($this as $key => $file) { |
||
| 34 | /* @var Media $file */ |
||
| 35 | $file->delete(); |
||
| 36 | $this->unset($key); |
||
| 37 | } |
||
| 38 | if (isset($file)) { |
||
| 39 | $directory = dirname($file->getPath()); |
||
| 40 | $this->deleteDirIfEmpty($directory); |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param $directory |
||
| 46 | */ |
||
| 47 | protected function deleteDirIfEmpty($directory) |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param static $sibling |
||
| 57 | */ |
||
| 58 | protected function rehydrateFromSibling($sibling) |
||
| 65 |