View   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 49
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFunctions() 0 14 1
A getName() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * This file is part of TwigView.
6
 *
7
 ** (c) 2014 Cees-Jan Kiewiet
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace WyriHaximus\TwigView\Lib\Twig\Extension;
14
15
use Cake\View\View as CakeView;
16
use Twig\Extension\AbstractExtension;
17
use Twig\TwigFunction;
18
19
/**
20
 * Class View.
21
 * @package WyriHaximus\TwigView\Lib\Twig\Extension
22
 */
23
final class View extends AbstractExtension
24
{
25
    /**
26
     * View to call methods upon.
27
     *
28
     * @var \Cake\View\View
29
     */
30
    protected $view;
31
32
    /**
33
     * Constructor.
34
     *
35
     * @param \Cake\View\View $view View instance.
36
     */
37
    public function __construct(CakeView $view)
38
    {
39
        $this->view = $view;
40
    }
41
42
    /**
43
     * Get declared functions.
44
     *
45
     * @return \Twig\TwigFunction[]
46
     */
47
    public function getFunctions(): array
48
    {
49
        return [
50
            new TwigFunction('elementExists', function ($name) {
51
                return $this->view->elementExists($name);
52
            }),
53
            new TwigFunction('getVars', function () {
54
                return $this->view->getVars();
55
            }),
56
            new TwigFunction('get', function ($var, $default = null) {
57
                return $this->view->get($var, $default);
58
            }),
59
        ];
60
    }
61
62
    /**
63
     * Get extension name.
64
     *
65
     * @return string
66
     */
67
    public function getName(): string
68
    {
69
        return 'view';
70
    }
71
}
72