SeoExtension::seo()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 12
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 7
nc 2
nop 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