| Total Complexity | 11 |
| Total Lines | 54 |
| Duplicated Lines | 0 % |
| Coverage | 95.45% |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 10 | class DeleteAsset |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Removes an asset completely. |
||
| 14 | * |
||
| 15 | * @param $ids |
||
| 16 | 5 | */ |
|
| 17 | public function delete($ids): void |
||
| 18 | 5 | { |
|
| 19 | 2 | if (is_array($ids)) { |
|
| 20 | 2 | foreach ($ids as $id) { |
|
| 21 | self::remove($id); |
||
|
|
|||
| 22 | } |
||
| 23 | 4 | } else { |
|
| 24 | 1 | if (! $ids) { |
|
| 25 | return; |
||
| 26 | 3 | } |
|
| 27 | self::remove($ids); |
||
| 28 | 4 | } |
|
| 29 | } |
||
| 30 | 5 | ||
| 31 | public function remove($id) |
||
| 32 | 5 | { |
|
| 33 | 1 | if (! $id) { |
|
| 34 | return false; |
||
| 35 | } |
||
| 36 | 4 | ||
| 37 | if (! $asset = Asset::find($id)) { |
||
| 38 | return false; |
||
| 39 | } |
||
| 40 | 4 | ||
| 41 | 4 | $media = $asset->media; |
|
| 42 | 4 | ||
| 43 | 4 | /** @var Media $file */ |
|
| 44 | foreach ($media as $file) { |
||
| 45 | |||
| 46 | $file_path = $file->getPath(); |
||
| 47 | 3 | ||
| 48 | 3 | if (! is_file($file_path) || ! is_writable($file_path)) { |
|
| 49 | throw new FileNotAccessibleException(); |
||
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | $asset->delete(); |
||
| 54 | } |
||
| 55 | 1 | ||
| 56 | /** |
||
| 57 | 1 | * Removes all assets completely. |
|
| 58 | 1 | * |
|
| 59 | * @param $ids |
||
| 60 | */ |
||
| 61 | public function deleteAll(HasAsset $model): void |
||
| 64 | } |
||
| 65 | } |
||
| 66 |