Issues (112)

src/FileAdder/FileAdder.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace ByTIC\MediaLibrary\FileAdder;
4
5
use ByTIC\MediaLibrary\HasMedia\Interfaces\HasMedia;
6
use ByTIC\MediaLibrary\Media\Media;
7
use Nip\Logger\Exception;
8
use Symfony\Component\HttpFoundation\File\File as SymfonyFile;
9
10
/**
11
 * Class FileAdder.
12
 */
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;
0 ignored issues
show
The trait ByTIC\MediaLibrary\FileA...FileAdderProcessesTrait requires the property $acceptsMedia which is not provided by ByTIC\MediaLibrary\FileAdder\FileAdder.
Loading history...
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)
42
    {
43
        $this->media = $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
69
    {
70 3
        return $this->mediaName;
71 3
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function getFileName(): string
77
    {
78 5
        return $this->fileName;
79
    }
80
}
81