Total Complexity | 8 |
Total Lines | 66 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
13 | class FileAdder implements FileAdderInterface |
||
14 | { |
||
15 | 1 | use Traits\HasFileTrait; |
|
16 | 1 | use Traits\HasSubjectTrait; |
|
17 | 1 | use Traits\HasMediaRepository; |
|
18 | 1 | use Traits\FileAdderProcessesTrait; |
|
|
|||
19 | |||
20 | /** @var null|\ByTIC\MediaLibrary\Media\Media */ |
||
21 | protected $media = null; |
||
22 | |||
23 | /** @var string */ |
||
24 | protected $mediaName; |
||
25 | |||
26 | /** |
||
27 | * @return Media|null |
||
28 | */ |
||
29 | public function getMedia() |
||
30 | { |
||
31 | if ($this->media === null) { |
||
32 | $this->setMedia($this->createMedia()); |
||
33 | } |
||
34 | |||
35 | return $this->media; |
||
36 | 6 | } |
|
37 | |||
38 | 6 | /** |
|
39 | * @param Media|null $media |
||
40 | 6 | */ |
|
41 | public function setMedia($media) |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @throws Exception |
||
48 | 6 | * |
|
49 | * @return Media |
||
50 | 6 | */ |
|
51 | protected function createMedia() |
||
52 | { |
||
53 | if (($this->getFile() instanceof SymfonyFile) === false) { |
||
54 | throw new Exception(self::NO_FILE_DEFINED); |
||
55 | } |
||
56 | 5 | if (($this->subject instanceof HasMedia) === false) { |
|
57 | throw new Exception(self::NO_SUBJECT_DEFINED); |
||
58 | 5 | } |
|
59 | 5 | $media = new Media(); |
|
60 | $media->setModel($this->getSubject()); |
||
61 | |||
62 | 3 | return $media; |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * @return string |
||
67 | */ |
||
68 | 3 | public function getMediaName(): string |
|
71 | 3 | } |
|
72 | |||
73 | /** |
||
74 | * @return string |
||
75 | */ |
||
76 | public function getFileName(): string |
||
79 | } |
||
80 | } |
||
81 |