1 | <?php |
||||||
2 | |||||||
3 | namespace ByTIC\MediaLibrary\Collections\Traits; |
||||||
4 | |||||||
5 | use ByTIC\MediaLibrary\PathGenerator\PathGeneratorFactory; |
||||||
6 | use Nip\Filesystem\FileDisk; |
||||||
7 | |||||||
8 | /** |
||||||
9 | * Trait HasFilesystemTrait. |
||||||
10 | */ |
||||||
11 | trait HasFilesystemTrait |
||||||
12 | { |
||||||
13 | protected $filesystem; |
||||||
14 | |||||||
15 | /** |
||||||
16 | * @return FileDisk |
||||||
17 | */ |
||||||
18 | 7 | public function getFilesystem() |
|||||
19 | { |
||||||
20 | 7 | if ($this->filesystem == null) { |
|||||
21 | 7 | $this->initFilesystem(); |
|||||
22 | } |
||||||
23 | |||||||
24 | 7 | return $this->filesystem; |
|||||
25 | } |
||||||
26 | |||||||
27 | /** |
||||||
28 | * @param mixed $filesystem |
||||||
29 | */ |
||||||
30 | 7 | public function setFilesystem($filesystem) |
|||||
31 | { |
||||||
32 | 7 | $this->filesystem = $filesystem; |
|||||
33 | 7 | } |
|||||
34 | |||||||
35 | /** |
||||||
36 | * @return mixed |
||||||
37 | */ |
||||||
38 | 7 | public function getBasePathForMedia() |
|||||
39 | { |
||||||
40 | 7 | $method = 'getBasePathForMedia'; |
|||||
41 | 7 | $manager = $this->getRecord()->getManager(); |
|||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
42 | |||||||
43 | 7 | $media = $this->newMedia(); |
|||||
0 ignored issues
–
show
It seems like
newMedia() 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
![]() |
|||||||
44 | |||||||
45 | 7 | if (method_exists($manager, $method)) { |
|||||
46 | $path = $manager->$method($media); |
||||||
47 | if (!empty($path)) { |
||||||
48 | return $path; |
||||||
49 | } |
||||||
50 | } |
||||||
51 | |||||||
52 | 7 | return PathGeneratorFactory::create()::$method($media); |
|||||
53 | } |
||||||
54 | |||||||
55 | 7 | /** |
|||||
56 | * @return string |
||||||
57 | 7 | */ |
|||||
58 | 7 | public function getMediaFilesystemDiskName() |
|||||
59 | { |
||||||
60 | return $this->getRecord()->getMediaFilesystemDiskName($this->getName()); |
||||||
0 ignored issues
–
show
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
![]() |
|||||||
61 | } |
||||||
62 | |||||||
63 | 7 | protected function initFilesystem() |
|||||
64 | { |
||||||
65 | 7 | $this->setFilesystem($this->generateFilesystem()); |
|||||
66 | } |
||||||
67 | |||||||
68 | /** |
||||||
69 | * @return FileDisk |
||||||
70 | */ |
||||||
71 | protected function generateFilesystem() |
||||||
72 | { |
||||||
73 | return $this->getRecord()->getMediaFilesystemDisk($this->getName()); |
||||||
74 | } |
||||||
75 | } |
||||||
76 |