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