Completed
Push — master ( b035c8...ddcf44 )
by Paweł
02:10
created

Video   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 250
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 250
rs 10
c 0
b 0
f 0
ccs 53
cts 53
cp 1
wmc 4
lcom 0
cbo 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 51 1
A toArray() 0 8 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Wszetko\Sitemap\Items;
5
6
use InvalidArgumentException as InvalidArgumentException;
7
use Wszetko\Sitemap\Items\DataTypes\StringType;
8
use Wszetko\Sitemap\Traits\DateTime;
9
use Wszetko\Sitemap\Traits\IsAssoc;
10
11
/**
12
 * Class Video
13
 *
14
 * @todo    : add support for content_segment_loc tag
15
 * @todo    : add support for tvshow tag
16
 * @todo    : add support for id tag
17
 * @package Wszetko\Sitemap\Items
18
 * @method setThumbnailLoc($thumbnail)
19
 * @method getThumbnailLoc()
20
 * @method setTitle($title)
21
 * @method getTitle()
22
 * @method setDescription($description)
23
 * @method getDescription()
24
 * @method setRating($rating)
25
 * @method getRating()
26
 * @method setViewCount($viewCount)
27
 * @method getViewCount()
28
 * @method setExpirationDate($expirationDate)
29
 * @method getExpirationDate()
30
 * @method setPublicationDate($publicationDate)
31
 * @method getPublicationDate()
32
 * @method setDuration($duration)
33
 * @method getDuration()
34
 * @method setGalleryLoc($galleryLoc)
35
 * @method getGalleryLoc()
36
 * @method setCategory($category)
37
 * @method getCategory()
38
 * @method setLive($live)
39
 * @method getLive()
40
 * @method setRequiresSubscription($subscription)
41
 * @method getRequiresSubscription()
42
 * @method setFamilyFriendly($familyFriendly)
43
 * @method getFamilyFriendly()
44
 * @method setContentLoc($contentLoc)
45
 * @method getContentLoc()
46
 * @method setPlayerLoc($player, $allow_embed = null, $autoplay = null)
47
 * @method getPlayerLoc()
48
 * @method addTag($tags)
49
 * @method setTag($tag)
50
 * @method getTag()
51
 * @method setUploader($uploader, $info = null)
52
 * @method getUploader()
53
 * @method setRestriction($countries, $relationship)
54
 * @method getRestriction()
55
 * @method setPlatform($platform, $relationship)
56
 * @method getPlatform()
57
 * @method setPrice($price, $currency, $type = null, $resolution = null)
58
 * @method getPrice()
59
 */
60
class Video extends Extension
61
{
62
    use DateTime;
63
    use IsAssoc;
64
65
    /**
66
     * Name of Namescapce
67
     */
68
    const NAMESPACE_NAME = 'video';
69
70
    /**
71
     * Namespace URL
72
     */
73
    const NAMESPACE_URL = 'http://www.google.com/schemas/sitemap-video/1.1';
74
75
    /**
76
     * Element name
77
     */
78
    const ELEMENT_NAME = 'video';
79
80
    /**
81
     * URL pointing to an image thumbnail.
82
     *
83
     * @var \Wszetko\Sitemap\Items\DataTypes\URLType
84
     */
85
    protected $thumbnailLoc;
86
87
    /**
88
     * Title of the video, max 100 characters.
89
     *
90
     * @var \Wszetko\Sitemap\Items\DataTypes\StringType
91
     */
92
    protected $title;
93
94
    /**
95
     * Description of the video, max 2048 characters.
96
     *
97
     * @var \Wszetko\Sitemap\Items\DataTypes\StringType
98
     */
99
    protected $description;
100
101
    /**
102
     * URL pointing to the actual media file (mp4).
103
     *
104
     * @var \Wszetko\Sitemap\Items\DataTypes\URLType
105
     */
106
    protected $contentLoc;
107
108
    /**
109
     * URL pointing to the player file (normally a SWF).
110
     *
111
     * @attribute allow_embed
112
     * @attributeDataType \Wszetko\Sitemap\Items\DataTypes\YesNoType
113
     * @attribute autoplay
114
     * @attributeDataType \Wszetko\Sitemap\Items\DataTypes\StringType
115
     * @var \Wszetko\Sitemap\Items\DataTypes\URLType
116
     */
117
    protected $playerLoc;
118
119
    /**
120
     * Indicates whether the video is live.
121
     *
122
     * @var \Wszetko\Sitemap\Items\DataTypes\YesNoType
123
     */
124
    protected $live;
125
126
    /**
127
     * Duration of the video in seconds.
128
     *
129
     * @var \Wszetko\Sitemap\Items\DataTypes\IntegerType
130
     */
131
    protected $duration;
132
133
    /**
134
     * String of space delimited platform values.
135
     * Allowed values are web, mobile, and tv.
136
     *
137
     * @attribute relationship
138
     * @attributeDataType \Wszetko\Sitemap\Items\DataTypes\StringType
139
     * @var \Wszetko\Sitemap\Items\DataTypes\StringType
140
     */
141
    protected $platform;
142
143
    /**
144
     * Does the video require a subscription?
145
     *
146
     * @var \Wszetko\Sitemap\Items\DataTypes\YesNoType
147
     */
148
    protected $requiresSubscription;
149
150
    /**
151
     * @attribute currency
152
     * @attributeDataType \Wszetko\Sitemap\Items\DataTypes\StringType
153
     * @attribute type
154
     * @attributeDataType \Wszetko\Sitemap\Items\DataTypes\StringType
155
     * @attribute resolution
156
     * @attributeDataType \Wszetko\Sitemap\Items\DataTypes\StringType
157
     * @var \Wszetko\Sitemap\Items\DataTypes\FloatType
158
     */
159
    protected $price;
160
161
    /**
162
     * Link to gallery of which this video appears in.
163
     *
164
     * @var \Wszetko\Sitemap\Items\DataTypes\URLType
165
     */
166
    protected $galleryLoc;
167
168
    /**
169
     * A space-delimited list of countries where the video may or may not be played.
170
     *
171
     * @attribute relationship
172
     * @attributeDataType \Wszetko\Sitemap\Items\DataTypes\StringType
173
     * @var \Wszetko\Sitemap\Items\DataTypes\StringType
174
     */
175
    protected $restriction;
176
177
    /**
178
     * A tag associated with the video.
179
     *
180
     * @dataType \Wszetko\Sitemap\Items\DataTypes\StringType
181
     * @var \Wszetko\Sitemap\Items\DataTypes\ArrayType
182
     */
183
    protected $tag;
184
185
    /**
186
     * The video's category. For example, cooking.
187
     *
188
     * @var \Wszetko\Sitemap\Items\DataTypes\StringType
189
     */
190
    protected $category;
191
192
    /**
193
     * No if the video should be available only to users with SafeSearch turned off.
194
     *
195
     * @var \Wszetko\Sitemap\Items\DataTypes\YesNoType
196
     */
197
    protected $familyFriendly;
198
199
    /**
200
     * The date the video was first published.
201
     *
202
     * @var \Wszetko\Sitemap\Items\DataTypes\DateTimeType
203
     */
204
    protected $publicationDate;
205
206
    /**
207
     * The number of times the video has been viewed.
208
     *
209
     * @var \Wszetko\Sitemap\Items\DataTypes\IntegerType
210
     */
211
    protected $viewCount;
212
213
    /**
214
     * The video uploader's name. Only one <video:uploader> is allowed per video.
215
     *
216
     * @attribute info
217
     * @attributeDataType \Wszetko\Sitemap\Items\DataTypes\URLType
218
     * @var \Wszetko\Sitemap\Items\DataTypes\StringType
219
     */
220
    protected $uploader;
221
222
    /**
223
     * The rating of the video. Allowed values are float numbers in the range 0.0 to 5.0.
224
     *
225
     * @var \Wszetko\Sitemap\Items\DataTypes\FloatType
226
     */
227
    protected $rating;
228
229
    /**
230
     * The date after which the video will no longer be available
231
     *
232
     * @var \Wszetko\Sitemap\Items\DataTypes\DateTimeType
233
     */
234
    protected $expirationDate;
235
236
    /**
237
     * Video constructor.
238
     *
239
     * @param string $thumbnailLoc
240
     * @param string $title
241
     * @param string $description
242
     *
243
     * @throws InvalidArgumentException
244
     * @throws \ReflectionException
245
     */
246 24
    public function __construct($thumbnailLoc, $title, $description)
247
    {
248 24
        parent::__construct();
249
250 24
        $this->thumbnailLoc
251 24
            ->setRequired(true);
252 24
        $this->setThumbnailLoc($thumbnailLoc);
253 24
        $this->title
254 24
            ->setMinLength(1)
255 24
            ->setMaxLength(100);
256 24
        $this->setTitle($title);
257 24
        $this->description
258 24
            ->setMinLength(1)
259 24
            ->setMaxLength(2048);
260 24
        $this->setDescription($description);
261 24
        $this->rating
262 24
            ->setMinValue(0)
263 24
            ->setMaxValue(5)
264 24
            ->setPrecision(1);
265 24
        $this->viewCount
266 24
            ->setMinValue(0);
267 24
        $this->duration
268 24
            ->setMinValue(0)
269 24
            ->setMaxValue(28800);
270 24
        $this->restriction
271 24
            ->setValueRegex("/^(?'countries'[A-Z]{2}( +[A-Z]{2})*)?$/", 'countries');
272 24
        $this->restriction
273 24
            ->getAttribute('relationship')
274 24
            ->setAllowedValues('allow, deny');
275 24
        $this->platform
276 24
            ->setValueRegex("/^(?'platform'(web|mobile|tv)( (web|mobile|tv))*)?/", 'platform');
277 24
        $this->platform
278 24
            ->getAttribute('relationship')
279 24
            ->setAllowedValues('allow, deny');
280 24
        $this->price
281 24
            ->setMinValue(0)
282 24
            ->setPrecision(2);
283 24
        $this->price
284 24
            ->getAttribute('currency')
285 24
            ->setValueRegex("/^(?'currency'[A-Z]{3})$/", 'currency');
286 24
        $this->price
287 24
            ->getAttribute('type')
288 24
            ->setAllowedValues('rent, purchase');
289 24
        $this->price
290 24
            ->getAttribute('resolution')
291 24
            ->setAllowedValues('SD, HD');
292 24
        $this->tag
293 24
            ->setMaxElements(32);
294 24
        $this->category
295 24
            ->setMaxLength(256);
296 24
    }
297
298
    /**
299
     * @return array
300
     */
301 1
    public function toArray(): array
302
    {
303 1
        if (empty($this->getContentLoc()) && empty($this->getPlayerLoc())) {
304 1
            throw new InvalidArgumentException('Nor content_loc or player_loc parameter is set.');
305
        }
306
307 1
        return parent::toArray();
308
    }
309
}
310