Completed
Push — master ( 9510d2...b45a00 )
by Patryk
05:23 queued 03:41
created

IframelyDTO::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace KaLLoSz\Twig\Extension;
4
5
/**
6
 * Class IframelyDTO
7
 * @package KaLLoSz\Twig\Extension
8
 *
9
 * @author Patryk Kala <[email protected]>
10
 */
11
class IframelyDTO
12
{
13
    /**
14
     * @var array
15
     */
16
    protected $data;
17
18
    /**
19
     * Build IframelyDTO object base on iframely schema
20
     * (http://iframe.ly/api/iframely?url=http://iframe.ly/ACcM3Y)
21
     *
22
     * @param array $data
23
     */
24 32
    public function __construct(array $data)
25
    {
26 32
        $this->data = $data;
27 32
    }
28
29
    /**
30
     * @return array
31
     */
32 4
    public function getMeta(): array
33
    {
34 4
        return $this->data['meta'];
35
    }
36
37
    /**
38
     * @return string
39
     */
40 4
    public function getHTML(): string
41
    {
42 4
        return $this->data['html'];
43
    }
44
45
    /**
46
     * @return string
47
     */
48 4
    public function getFirstPlayerHref(): string
49
    {
50 4
        return $this->getLinks()['player'][0]['href'];
51
    }
52
53
    /**
54
     * @return null|string
55
     */
56 8
    public function getAutoplayPlayerHref()
57
    {
58 8
        $players = $this->getLinks()['player'];
59
60 8
        foreach ($players as $player) {
61 4
            if (in_array('autoplay', $player['rel'])) {
62 4
                return $player['href'];
63
            }
64
        }
65
66 4
        return null;
67
    }
68
69
    /**
70
     * @return array
71
     */
72 16
    public function getLinks(): array
73
    {
74 16
        return $this->data['links'];
75
    }
76
}
77