Completed
Push — master ( 178130...678bac )
by Paweł
15:27
created

Image::addVariant()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 0
cts 1
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Content Bundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\ContentBundle\Model;
16
17
use Doctrine\Common\Collections\ArrayCollection;
18
use function in_array;
19
use SWP\Component\Common\Model\TimestampableTrait;
20
21
class Image implements ImageInterface
22
{
23
    use TimestampableTrait;
24
25
    /**
26
     * @var string
27
     */
28
    protected $id;
29
30
    /**
31
     * Uploaded file extension.
32
     *
33
     * @var string
34
     */
35
    protected $fileExtension;
36
37
    /**
38
     * @var string
39
     */
40
    protected $assetId;
41
42
    /**
43
     * @var ArticleMediaInterface
44
     */
45
    protected $media;
46
47
    /**
48
     * @var int
49
     */
50
    protected $width;
51
52
    /**
53
     * @var int
54
     */
55
    protected $height;
56
57
    /**
58
     * @var ArrayCollection
59
     */
60
    protected $renditions;
61
62
    protected $variants = [];
63
64
    /**
65
     * File constructor.
66
     */
67
    public function __construct()
68
    {
69
        $this->setCreatedAt(new \DateTime());
70
        $this->setRenditions(new ArrayCollection());
71
    }
72
73
    /**
74
     * @return ArticleMediaInterface
75
     */
76
    public function getMedia(): ArticleMediaInterface
77
    {
78
        return $this->media;
79
    }
80
81
    /**
82
     * @param ArticleMediaInterface $media
83
     */
84
    public function setMedia(ArticleMediaInterface $media)
85
    {
86
        $this->media = $media;
87
    }
88
89
    /**
90
     * @param string $id
91
     */
92
    public function setId($id)
93
    {
94
        $this->id = $id;
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100
    public function getId()
101
    {
102
        return $this->id;
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108
    public function setFileExtension($extension)
109
    {
110
        $this->fileExtension = $extension;
111
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116
    public function getFileExtension()
117
    {
118
        return $this->fileExtension;
119
    }
120
121
    /**
122
     * @return string
123
     */
124
    public function getAssetId(): string
125
    {
126
        return $this->assetId;
127
    }
128
129
    /**
130
     * {@inheritdoc}
131
     */
132
    public function setAssetId(string $assetId)
133
    {
134
        $this->assetId = $assetId;
135
    }
136
137
    /**
138
     * @return ArrayCollection
139
     */
140
    public function getRenditions()
141
    {
142
        return $this->renditions;
143
    }
144
145
    /**
146
     * @param ImageRendition $rendition
147
     */
148
    public function addRendition(ImageRendition $rendition)
149
    {
150
        $this->renditions->add($rendition);
151
    }
152
153
    /**
154
     * @param ArrayCollection $renditions
155
     */
156
    public function setRenditions($renditions)
157
    {
158
        $this->renditions = $renditions;
159
    }
160
161
    public function getWidth(): int
162
    {
163
        return $this->width;
164
    }
165
166
    public function setWidth(int $width): void
167
    {
168
        $this->width = $width;
169
    }
170
171
    public function getHeight(): int
172
    {
173
        return $this->height;
174
    }
175
176
    public function setHeight(int $height): void
177
    {
178
        $this->height = $height;
179
    }
180
181
    public function getVariants(): array
182
    {
183
        return $this->variants;
184
    }
185
186
    public function setVariants(array $variants): void
187
    {
188
        $this->variants = $variants;
189
    }
190
191
    public function addVariant(string $variant): void
192
    {
193
        if (!$this->hasVariant($variant)) {
194
            $this->variants[] = $variant;
195
        }
196
    }
197
198
    public function hasVariant(string $variant): bool
199
    {
200
        return in_array($variant, $this->getVariants(), true);
201
    }
202
}
203