Passed
Pull Request — master (#1)
by
unknown
02:45
created

Video::getYoutubeId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 2
nc 2
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Nelexa\GPlay\Model;
5
6
class Video
7
{
8
    /**
9
     * @var string
10
     */
11
    private $thumb;
12
    /**
13
     * @var string
14
     */
15
    private $url;
16
17
    /**
18
     * Video constructor.
19
     *
20
     * @param string $thumb
21
     * @param string $url
22
     */
23
    public function __construct(string $thumb, string $url)
24
    {
25
        $this->thumb = $thumb;
26
        $this->url = $url;
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function getThumb(): string
33
    {
34
        return $this->thumb;
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function getUrl(): string
41
    {
42
        return $this->url;
43
    }
44
45
    /**
46
     * @return string|null
47
     */
48
    public function getYoutubeId(): ?string
49
    {
50
        if (preg_match('~^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|\&v(?:i)?=))([^#\&\?]*).*~', $this->url, $match)) {
51
            return $match[1];
52
        }
53
        return null;
54
    }
55
}
56