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

IframelyExtension::__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 IframelyExtension
7
 * @package KaLLoSz\Twig\Extension
8
 *
9
 * @author Patryk Kala <[email protected]>
10
 */
11
class IframelyExtension extends \Twig_Extension
12
{
13
    /**
14
     * @var IframelyClientInterface
15
     */
16
    protected $client;
17
18
    /**
19
     * @param IframelyClientInterface $client Iframely Client
20
     */
21 24
    public function __construct(IframelyClientInterface $client)
22
    {
23 24
        $this->client = $client;
24 24
    }
25
26
    /**
27
     * @param string $url
28
     *
29
     * @return IframelyDTO
30
     */
31 8
    public function getDTO(string $url): IframelyDTO
32
    {
33 8
        return $this->client->getUrlData($url);
34
    }
35
36
    /**
37
     * @param string $url
38
     *
39
     * @return string
40
     */
41 4
    public function getEmbedHTML(string $url): string
42
    {
43 4
        return $this->getDTO($url)->getHTML();
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 4
    public function getFilters()
50
    {
51
        return [
52 4
            new \Twig_SimpleFilter('iframelyHTML', [$this, 'getEmbedHTML']),
53
        ];
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 4
    public function getFunctions()
60
    {
61
        return [
62 4
            new \Twig_SimpleFunction('iframely', [$this, 'getDTO']),
63
        ];
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 4
    public function getName()
70
    {
71 4
        return 'kallosz\twig-iframely-extension';
72
    }
73
}
74