CMSExtension   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 3
dl 0
loc 46
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getName() 0 4 1
A getGlobals() 0 6 1
A getFunctions() 0 7 1
A cmsGetDescription() 0 7 2
A cmsGet() 0 4 1
1
<?php
2
3
namespace Alpixel\Bundle\CMSBundle\Twig\Extension;
4
5
use Alpixel\Bundle\CMSBundle\Entity\Node;
6
use Alpixel\Bundle\CMSBundle\Helper\CMSHelper;
7
8
class CMSExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
9
{
10
    protected $contentTypes;
11
    protected $container;
12
    protected $cmsHelper;
13
14
    public function __construct(CMSHelper $cmsHelper, $container, $contentTypes = null)
15
    {
16
        $this->cmsHelper = $cmsHelper;
17
        $this->container = $container;
18
        $this->contentTypes = $contentTypes;
19
    }
20
21
    public function getName()
22
    {
23
        return 'cms';
24
    }
25
26
    public function getGlobals()
27
    {
28
        return [
29
            'cms_contentTypes' => $this->contentTypes,
30
        ];
31
    }
32
33
    public function getFunctions()
34
    {
35
        return [
36
            new \Twig_SimpleFunction('cms_contentType_get_description', [$this, 'cmsGetDescription']),
37
            new \Twig_SimpleFunction('cms_contentType_get', [$this, 'cmsGet']),
38
        ];
39
    }
40
41
    public function cmsGetDescription(Node $node)
42
    {
43
        $contentType = $this->cmsHelper->getContentTypeFromNodeElementClass($node);
44
        if ($contentType !== null) {
45
            return $contentType['description'];
46
        }
47
    }
48
49
    public function cmsGet(Node $node)
50
    {
51
        return $this->cmsHelper->getContentTypeFromNodeElementClass($node);
52
    }
53
}
54