1 | <?php |
||||||||
2 | |||||||||
3 | namespace ByTIC\MediaLibrary\Collections\Traits; |
||||||||
4 | |||||||||
5 | use ByTIC\MediaLibrary\Collections\Collection; |
||||||||
6 | use ByTIC\MediaLibrary\Media\Media; |
||||||||
7 | |||||||||
8 | /** |
||||||||
9 | * Trait MediaOperationsTraits. |
||||||||
10 | * |
||||||||
11 | * @method Media get($key) |
||||||||
12 | */ |
||||||||
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); |
|||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||||
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) |
||||||||
49 | { |
||||||||
50 | $contents = $this->getFilesystem()->listContents($directory); |
||||||||
0 ignored issues
–
show
It seems like
getFilesystem() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
51 | if (empty($contents)) { |
||||||||
52 | $this->getFilesystem()->deleteDir($directory); |
||||||||
53 | } |
||||||||
54 | } |
||||||||
55 | |||||||||
56 | /** |
||||||||
57 | * @param static $sibling |
||||||||
58 | */ |
||||||||
59 | 7 | protected function rehydrateFromSibling($sibling) |
|||||||
60 | { |
||||||||
61 | 7 | $this->setName($sibling->getName()); |
|||||||
0 ignored issues
–
show
It seems like
setName() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() It seems like
getName() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
62 | 7 | $this->setMediaRepository($sibling->getMediaRepository()); |
|||||||
0 ignored issues
–
show
It seems like
getMediaRepository() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() It seems like
setMediaRepository() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
63 | 7 | $this->setMediaType($sibling->getMediaType()); |
|||||||
0 ignored issues
–
show
It seems like
getMediaType() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() It seems like
setMediaType() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
64 | 7 | $this->setLoader($sibling->getLoader()); |
|||||||
0 ignored issues
–
show
It seems like
getLoader() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() It seems like
setLoader() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
65 | 7 | } |
|||||||
66 | } |
||||||||
67 |