Completed
Push — master ( 69416a...547cab )
by Nikola
03:28
created

Extension   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 56
ccs 13
cts 15
cp 0.8667
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 3
A getNodeVisitors() 0 11 2
A getTokenParsers() 0 6 1
A createBuffer() 0 4 1
1
<?php
2
3
namespace RunOpenCode\Twig\BufferizedTemplate;
4
5
use RunOpenCode\Twig\BufferizedTemplate\Tag\Bufferize\TokenParser;
6
7
class Extension extends \Twig_Extension
8
{
9
    /**
10
     * @var array
11
     */
12
    private $settings;
13
14 2
    public function __construct(array $settings = array())
15
    {
16 2
        $this->settings = array_merge(array(
17 2
            'enabled' => true,
18
            'nodes' => array(),
19
            'whitelist' => array(),
20
            'blacklist' => array(),
21
            'bufferManager' => 'RunOpenCode\\Twig\\BufferizedTemplate\\Buffer\\BufferManager',
22
            'defaultExecutionPriority' => 0,
23
            'nodeVisitorPriority' => 10
24
        ), $settings);
25
26 2
        $this->settings['nodes']['RunOpenCode\\Twig\\BufferizedTemplate\\Tag\\Bufferize\\Node'] = $this->settings['defaultExecutionPriority'];
27
28 2
        if (count($this->settings['blacklist']) > 0 && count($this->settings['whitelist'])) {
29
            throw new \InvalidArgumentException('You can use either black list or white list setting or non for bufferizing templates, but not both.');
30
        }
31 2
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 2
    public function getNodeVisitors()
37
    {
38 2
        if ($this->settings['enabled']) {
39
40
            return array(
41 2
                new NodeVisitor($this->settings)
42
            );
43
        } else {
44
            return array();
45
        }
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 2
    public function getTokenParsers()
52
    {
53
        return array(
54 2
            new TokenParser()
55
        );
56
    }
57
58 2
    public function createBuffer()
59
    {
60 2
        return new $this->settings['bufferManager']();
61
    }
62
}
63