Issues (63)

src/Entity/Media.php (1 issue)

1
<?php
2
3
/*
4
 * This file was created by developers working at BitBag
5
 * Do you need more information about us and what we do? Visit our https://bitbag.io website!
6
 * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
7
*/
8
9
declare(strict_types=1);
10
11
namespace BitBag\SyliusCmsPlugin\Entity;
12
13
use BitBag\SyliusCmsPlugin\MediaProvider\FilenameHelper;
14
use Sylius\Component\Resource\Model\ToggleableTrait;
15
use Sylius\Component\Resource\Model\TranslatableTrait;
16
use Sylius\Component\Resource\Model\TranslationInterface;
17
use Symfony\Component\HttpFoundation\File\File;
18
use Webmozart\Assert\Assert;
19
20
class Media implements MediaInterface
21
{
22
    use ToggleableTrait;
23
24
    use SectionableTrait;
25
26
    use ProductsAwareTrait;
27
28
    use ChannelsAwareTrait;
29
30
    use TranslatableTrait {
31
        __construct as protected initializeTranslationsCollection;
32
    }
33
34
    /** @var int */
35
    protected $id;
36
37
    /** @var string|null */
38
    protected $type;
39
40
    /** @var string|null */
41
    protected $code;
42
43
    /** @var string|null */
44
    protected $path;
45
46
    /** @var File|null */
47
    protected $file;
48
49
    /** @var string|null */
50
    protected $mimeType;
51
52
    /** @var string */
53
    protected $originalPath;
54
55
    /** @var int|null */
56
    protected $width;
57
58
    /** @var int|null */
59
    protected $height;
60
61
    public function __construct()
62
    {
63
        $this->initializeTranslationsCollection();
64
        $this->initializeSectionsCollection();
65
        $this->initializeProductsCollection();
66
        $this->initializeChannelsCollection();
67
    }
68
69
    public function getId(): ?int
70
    {
71
        return $this->id;
72
    }
73
74
    public function getType(): ?string
75
    {
76
        return $this->type;
77
    }
78
79
    public function setType(?string $type): void
80
    {
81
        $this->type = $type;
82
    }
83
84
    public function getCode(): ?string
85
    {
86
        return $this->code;
87
    }
88
89
    public function setCode(?string $code): void
90
    {
91
        $this->code = $code;
92
    }
93
94
    public function getPath(): ?string
95
    {
96
        return $this->path;
97
    }
98
99
    public function setPath(?string $path): void
100
    {
101
        $this->path = $path;
102
    }
103
104
    public function getFile(): ?File
105
    {
106
        return $this->file;
107
    }
108
109
    public function setFile(?File $file): void
110
    {
111
        $this->file = $file;
112
    }
113
114
    public function hasFile(): bool
115
    {
116
        return null !== $this->file;
117
    }
118
119
    public function getMimeType(): ?string
120
    {
121
        return $this->mimeType;
122
    }
123
124
    public function setMimeType(?string $mimeType): void
125
    {
126
        $this->mimeType = $mimeType;
127
    }
128
129
    public function getName(): ?string
130
    {
131
        /** @var MediaTranslationInterface $mediaTranslationInterface */
132
        $mediaTranslationInterface = $this->getMediaTranslation();
133
134
        return $mediaTranslationInterface->getName();
135
    }
136
137
    public function setName(?string $name): void
138
    {
139
        /** @var MediaTranslationInterface $mediaTranslationInterface */
140
        $mediaTranslationInterface = $this->getMediaTranslation();
141
        $mediaTranslationInterface->setName($name);
142
    }
143
144
    public function getDownloadName(): string
145
    {
146
        return FilenameHelper::removeSlashes($this->getName() ?? $this->getCode() ?? self::DEFAULT_DOWNLOAD_NAME);
147
    }
148
149
    public function getContent(): ?string
150
    {
151
        /** @var MediaTranslationInterface $mediaTranslationInterface */
152
        $mediaTranslationInterface = $this->getMediaTranslation();
153
154
        return $mediaTranslationInterface->getContent();
155
    }
156
157
    public function setContent(?string $content): void
158
    {
159
        /** @var MediaTranslationInterface $mediaTranslationInterface */
160
        $mediaTranslationInterface = $this->getMediaTranslation();
161
        $mediaTranslationInterface->setContent($content);
162
    }
163
164
    public function getAlt(): ?string
165
    {
166
        /** @var MediaTranslationInterface $mediaTranslationInterface */
167
        $mediaTranslationInterface = $this->getMediaTranslation();
168
169
        return $mediaTranslationInterface->getAlt();
170
    }
171
172
    public function setAlt(?string $alt): void
173
    {
174
        /** @var MediaTranslationInterface $mediaTranslationInterface */
175
        $mediaTranslationInterface = $this->getMediaTranslation();
176
        $mediaTranslationInterface->setAlt($alt);
177
    }
178
179
    public function getLink(): ?string
180
    {
181
        /** @var MediaTranslationInterface $mediaTranslationInterface */
182
        $mediaTranslationInterface = $this->getMediaTranslation();
183
184
        return $mediaTranslationInterface->getLink();
185
    }
186
187
    public function setLink(?string $link): void
188
    {
189
        /** @var MediaTranslationInterface $mediaTranslationInterface */
190
        $mediaTranslationInterface = $this->getMediaTranslation();
191
        $mediaTranslationInterface->setLink($link);
192
    }
193
194
    public function getWidth(): ?int
195
    {
196
        return $this->width;
197
    }
198
199
    public function setWidth(?int $width): void
200
    {
201
        $this->width = $width;
202
    }
203
204
    public function getHeight(): ?int
205
    {
206
        return $this->height;
207
    }
208
209
    public function setHeight(?int $height): void
210
    {
211
        $this->height = $height;
212
    }
213
214
    /**
215
     * @return MediaTranslationInterface|TranslationInterface
216
     */
217
    protected function getMediaTranslation(): TranslationInterface
218
    {
219
        return $this->getTranslation();
220
    }
221
222
    protected function createTranslation(): MediaTranslationInterface
223
    {
224
        return new MediaTranslation();
225
    }
226
227
    public function __toString(): string
228
    {
229
        $result = $this->getName() ?? $this->code;
230
        Assert::string($result);
231
232
        return $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
233
    }
234
}
235