TemplateHook   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A setContext() 0 4 1
A getContext() 0 3 1
A setEnvironment() 0 4 1
A getTemplating() 0 3 1
1
<?php
2
3
4
namespace Braunstetter\TemplateHooks\Twig;
5
6
7
use Braunstetter\TemplateHooks\Twig\Contracts\HookInterface;
8
use Twig\Environment;
9
10
abstract class TemplateHook implements HookInterface
11
{
12
    protected Environment $templating;
13
    public string|array $target;
14
    public array $context;
15
16
    public function __construct()
17
    {
18
        if (method_exists($this, 'setTarget')) {
19
            $this->target = $this->setTarget();
20
        }
21
    }
22
23
    /**
24
     * @return Environment
25
     */
26
    public function getTemplating(): Environment
27
    {
28
        return $this->templating;
29
    }
30
31
    /**
32
     * @param array $context
33
     * @return TemplateHook
34
     */
35
    public function setContext(array $context): TemplateHook
36
    {
37
        $this->context = $context;
38
        return $this;
39
    }
40
41
    /**
42
     * @param Environment $env
43
     * @return TemplateHook
44
     */
45
    public function setEnvironment(Environment $env): TemplateHook
46
    {
47
        $this->templating = $env;
48
        return $this;
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    public function getContext(): array
55
    {
56
        return $this->context;
57
    }
58
59
}