Completed
Pull Request — master (#1)
by Patryk
10:48
created

IframelyExtension   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 63
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getDTO() 0 4 1
A getEmbedHTML() 0 4 1
A getFilters() 0 6 1
A getFunctions() 0 6 1
A getName() 0 4 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
    public function __construct(IframelyClientInterface $client)
22
    {
23
        $this->client = $client;
24
    }
25
26
    /**
27
     * @param string $url
28
     *
29
     * @return IframelyDTO
30
     */
31
    public function getDTO(string $url): IframelyDTO
32
    {
33
        return $this->client->getUrlData($url);
34
    }
35
36
    /**
37
     * @param string $url
38
     *
39
     * @return string
40
     */
41
    public function getEmbedHTML(string $url): string
42
    {
43
        return $this->getDTO($url)->getHTML();
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function getFilters()
50
    {
51
        return [
52
            new \Twig_SimpleFilter('iframelyHTML', [$this, 'getEmbedHTML']),
53
        ];
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getFunctions()
60
    {
61
        return [
62
            new \Twig_SimpleFunction('iframely', [$this, 'getDTO']),
63
        ];
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function getName()
70
    {
71
        return 'kallosz\twig-iframely-extension';
72
    }
73
}
74