Passed
Push — master ( e1c3af...d33dd4 )
by Mateusz
13:19 queued 07:37
created

Media::getHeight()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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
    /** @var int|null */
53
    protected $width;
54
55
    /** @var int|null */
56
    protected $height;
57
58
    public function __construct()
59
    {
60
        $this->initializeTranslationsCollection();
61
        $this->initializeSectionsCollection();
62
        $this->initializeProductsCollection();
63
        $this->initializeChannelsCollection();
64
    }
65
66
    public function getId(): ?int
67
    {
68
        return $this->id;
69
    }
70
71
    public function getType(): ?string
72
    {
73
        return $this->type;
74
    }
75
76
    public function setType(?string $type): void
77
    {
78
        $this->type = $type;
79
    }
80
81
    public function getCode(): ?string
82
    {
83
        return $this->code;
84
    }
85
86
    public function setCode(?string $code): void
87
    {
88
        $this->code = $code;
89
    }
90
91
    public function getPath(): ?string
92
    {
93
        return $this->path;
94
    }
95
96
    public function setPath(?string $path): void
97
    {
98
        $this->path = $path;
99
    }
100
101
    public function getFile(): ?File
102
    {
103
        return $this->file;
104
    }
105
106
    public function setFile(?File $file): void
107
    {
108
        $this->file = $file;
109
    }
110
111
    public function hasFile(): bool
112
    {
113
        return null !== $this->file;
114
    }
115
116
    public function getMimeType(): ?string
117
    {
118
        return $this->mimeType;
119
    }
120
121
    public function setMimeType(?string $mimeType): void
122
    {
123
        $this->mimeType = $mimeType;
124
    }
125
126
    public function getName(): ?string
127
    {
128
        return $this->getMediaTranslation()->getName();
129
    }
130
131
    public function setName(?string $name): void
132
    {
133
        $this->getMediaTranslation()->setName($name);
134
    }
135
136
    public function getDownloadName(): string
137
    {
138
        return FilenameHelper::removeSlashes($this->getName() ?? $this->getCode() ?? self::DEFAULT_DOWNLOAD_NAME);
139
    }
140
141
    public function getContent(): ?string
142
    {
143
        return $this->getMediaTranslation()->getContent();
144
    }
145
146
    public function setContent(?string $content): void
147
    {
148
        $this->getMediaTranslation()->setContent($content);
149
    }
150
151
    public function getAlt(): ?string
152
    {
153
        return $this->getMediaTranslation()->getAlt();
154
    }
155
156
    public function setAlt(?string $alt): void
157
    {
158
        $this->getMediaTranslation()->setAlt($alt);
159
    }
160
161
    public function getLink(): ?string
162
    {
163
        return $this->getMediaTranslation()->getLink();
164
    }
165
166
    public function setLink(?string $link): void
167
    {
168
        $this->getMediaTranslation()->setLink($link);
169
    }
170
171
    public function getWidth(): ?int
172
    {
173
        return $this->width;
174
    }
175
176
    public function setWidth(?int $width): void
177
    {
178
        $this->width = $width;
179
    }
180
181
    public function getHeight(): ?int
182
    {
183
        return $this->height;
184
    }
185
186
    public function setHeight(?int $height): void
187
    {
188
        $this->height = $height;
189
    }
190
191
    /**
192
     * @return MediaTranslationInterface|TranslationInterface
193
     */
194
    protected function getMediaTranslation(): TranslationInterface
195
    {
196
        return $this->getTranslation();
197
    }
198
199
    protected function createTranslation(): MediaTranslationInterface
200
    {
201
        return new MediaTranslation();
202
    }
203
204
    public function __toString(): string
205
    {
206
        return $this->getName() ?? $this->code;
207
    }
208
}
209