Passed
Pull Request — master (#334)
by US
06:25
created

Media::setFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusCmsPlugin\Entity;
14
15
use BitBag\SyliusCmsPlugin\MediaProvider\FilenameHelper;
16
use Sylius\Component\Resource\Model\ToggleableTrait;
17
use Sylius\Component\Resource\Model\TranslatableTrait;
18
use Sylius\Component\Resource\Model\TranslationInterface;
19
use Symfony\Component\HttpFoundation\File\File;
20
21
class Media implements MediaInterface
22
{
23
    use ToggleableTrait;
24
    use SectionableTrait;
25
    use ProductsAwareTrait;
26
    use ChannelsAwareTrait;
27
    use TranslatableTrait {
28
        __construct as protected initializeTranslationsCollection;
29
    }
30
31
    /** @var int */
32
    protected $id;
33
34
    /** @var string */
35
    protected $type;
36
37
    /** @var string */
38
    protected $code;
39
40
    /** @var string */
41
    protected $path;
42
43
    /** @var File */
44
    protected $file;
45
46
    /** @var string */
47
    protected $mimeType;
48
49
    /** @var string */
50
    protected $originalPath;
51
52
    public function __construct()
53
    {
54
        $this->initializeTranslationsCollection();
55
        $this->initializeSectionsCollection();
56
        $this->initializeProductsCollection();
57
        $this->initializeChannelsCollection();
58
    }
59
60
    public function getId(): ?int
61
    {
62
        return $this->id;
63
    }
64
65
    public function getType(): ?string
66
    {
67
        return $this->type;
68
    }
69
70
    public function setType(?string $type): void
71
    {
72
        $this->type = $type;
73
    }
74
75
    public function getCode(): ?string
76
    {
77
        return $this->code;
78
    }
79
80
    public function setCode(?string $code): void
81
    {
82
        $this->code = $code;
83
    }
84
85
    public function getPath(): ?string
86
    {
87
        return $this->path;
88
    }
89
90
    public function setPath(?string $path): void
91
    {
92
        $this->path = $path;
93
    }
94
95
    public function getFile(): ?File
96
    {
97
        return $this->file;
98
    }
99
100
    public function setFile(?File $file): void
101
    {
102
        $this->file = $file;
103
    }
104
105
    public function hasFile(): bool
106
    {
107
        return null !== $this->file;
108
    }
109
110
    public function getMimeType(): ?string
111
    {
112
        return $this->mimeType;
113
    }
114
115
    public function setMimeType(?string $mimeType): void
116
    {
117
        $this->mimeType = $mimeType;
118
    }
119
120
    public function getName(): ?string
121
    {
122
        return $this->getMediaTranslation()->getName();
123
    }
124
125
    public function setName(?string $name): void
126
    {
127
        $this->getMediaTranslation()->setName($name);
128
    }
129
130
    public function getDownloadName(): string
131
    {
132
        return FilenameHelper::removeSlashes($this->getName() ?? $this->getCode() ?? self::DEFAULT_DOWNLOAD_NAME);
133
    }
134
135
    public function getContent(): ?string
136
    {
137
        return $this->getMediaTranslation()->getContent();
138
    }
139
140
    public function setContent(?string $content): void
141
    {
142
        $this->getMediaTranslation()->setContent($content);
143
    }
144
145
    public function getAlt(): ?string
146
    {
147
        return $this->getMediaTranslation()->getAlt();
148
    }
149
150
    public function setAlt(?string $alt): void
151
    {
152
        $this->getMediaTranslation()->setAlt($alt);
153
    }
154
155
    public function getLink(): ?string
156
    {
157
        return $this->getMediaTranslation()->getLink();
158
    }
159
160
    public function setLink(?string $link): void
161
    {
162
        $this->getMediaTranslation()->setLink($link);
163
    }
164
165
    /**
166
     * @return MediaTranslationInterface|TranslationInterface
167
     */
168
    protected function getMediaTranslation(): TranslationInterface
169
    {
170
        return $this->getTranslation();
171
    }
172
173
    protected function createTranslation(): MediaTranslationInterface
174
    {
175
        return new MediaTranslation();
176
    }
177
    
178
    public function __toString(): string
179
    {
180
        return $this->getName() ?? $this->code;
181
    }
182
}
183