SeoExtension   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 55
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFunctions() 0 6 1
A seo() 0 12 2
A getName() 0 4 1
1
<?php
2
3
namespace Leogout\Bundle\SeoBundle\Twig;
4
5
use Leogout\Bundle\SeoBundle\Model\RenderableInterface;
6
use Leogout\Bundle\SeoBundle\Provider\SeoGeneratorProvider;
7
8
/**
9
 * Description of SeoExtension.
10
 *
11
 * @author: leogout
12
 */
13
class SeoExtension extends \Twig_Extension
14
{
15
    /**
16
     * @var SeoGeneratorProvider
17
     */
18
    protected $generatorProvider;
19
20
    /**
21
     * SeoExtension constructor.
22
     *
23
     * @param SeoGeneratorProvider $generatorProvider
24
     */
25
    public function __construct(SeoGeneratorProvider $generatorProvider)
26
    {
27
        $this->generatorProvider = $generatorProvider;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function getFunctions()
34
    {
35
        return array(
36
            new \Twig_SimpleFunction('leogout_seo', [$this, 'seo'], ['is_safe' => ['html']]),
37
        );
38
    }
39
40
    /**
41
     * @param $alias
42
     *
43
     * @return string
44
     */
45
    public function seo($alias = null)
46
    {
47
        if (null !== $alias) {
48
            return $this->generatorProvider->get($alias)->render();
49
        }
50
51
        return implode(PHP_EOL,
52
            array_map(function (RenderableInterface $tag) {
53
                return $tag->render();
54
            }, $this->generatorProvider->getAll())
55
        );
56
    }
57
58
    /**
59
     * Returns the name of the extension.
60
     *
61
     * @return string The extension name
62
     */
63
    public function getName()
64
    {
65
        return 'leogout_seo.twig.seo_extension';
66
    }
67
}
68