Completed
Pull Request — master (#58)
by
unknown
13:38 queued 03:32
created

ExtensionsListener   B

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 18

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 0
cbo 18
dl 0
loc 64
ccs 26
cts 26
cp 1
rs 7.3333

2 Methods

Rating   Name   Duplication   Size   Complexity  
A implementedEvents() 0 6 1
B construct() 0 43 4
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of TwigView.
4
 *
5
 ** (c) 2014 Cees-Jan Kiewiet
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace WyriHaximus\TwigView\Event;
12
13
use Aptoma\Twig\Extension\MarkdownEngineInterface;
14
use Aptoma\Twig\Extension\MarkdownExtension;
15
use Aptoma\Twig\TokenParser\MarkdownTokenParser;
16
// use Ajgl\Twig\Extension\BreakpointExtension; // FIXME Not ported to Twig 2.x yet
17
use Asm89\Twig\CacheExtension\CacheStrategy\LifetimeCacheStrategy;
18
use Asm89\Twig\CacheExtension\Extension as CacheExtension;
19
use Cake\Core\Configure;
20
use Cake\Event\EventListenerInterface;
21
// use Jasny\Twig\ArrayExtension; // FIXME Not ported to Twig 2.x yet
22
// use Jasny\Twig\DateExtension; // FIXME Not ported to Twig 2.x yet
23
// use Jasny\Twig\PcreExtension; // FIXME Not ported to Twig 2.x yet
24
// use Jasny\Twig\TextExtension; // FIXME Not ported to Twig 2.x yet
25
use WyriHaximus\TwigView\Lib\Cache;
26
use WyriHaximus\TwigView\Lib\Twig\Extension;
27
28
/**
29
 * Class ExtensionsListener.
30
 * @package WyriHaximus\TwigView\Event
31
 */
32
class ExtensionsListener implements EventListenerInterface
33
{
34
    /**
35
     * Return implemented events.
36
     *
37
     * @return array
38
     */
39
    public function implementedEvents()
40 1
    {
41
        return [
42
            ConstructEvent::EVENT => 'construct',
43 1
        ];
44
    }
45
46
    /**
47
     * Event handler.
48
     *
49
     * @param ConstructEvent $event Event.
50
     *
51
     */
52
    public function construct(ConstructEvent $event)
53
    {
54
        // Twig core extensions
55 5
        $event->getTwig()->addExtension(new \Twig_Extension_StringLoader());
56
        $event->getTwig()->addExtension(new \Twig_Extension_Debug());
57
58
        // CakePHP bridging extensions
59
        $event->getTwig()->addExtension(new Extension\I18n());
60 5
        $event->getTwig()->addExtension(new Extension\Time());
61 5
        $event->getTwig()->addExtension(new Extension\Basic());
62
        $event->getTwig()->addExtension(new Extension\Number());
63
        $event->getTwig()->addExtension(new Extension\Utils());
64 5
        $event->getTwig()->addExtension(new Extension\Arrays());
65 5
        $event->getTwig()->addExtension(new Extension\Strings());
66 5
        $event->getTwig()->addExtension(new Extension\Inflector());
67 5
68 5
        // Markdown extension
69 5
        if (
70 5
            Configure::check('WyriHaximus.TwigView.markdown.engine') &&
71 5
            Configure::read('WyriHaximus.TwigView.markdown.engine') instanceof MarkdownEngineInterface
72
        ) {
73
            $engine = Configure::read('WyriHaximus.TwigView.markdown.engine');
74
            $event->getTwig()->addExtension(new MarkdownExtension($engine));
75 5
            $event->getTwig()->addTokenParser(new MarkdownTokenParser($engine));
0 ignored issues
show
Unused Code introduced by
The call to MarkdownTokenParser::__construct() has too many arguments starting with $engine.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
76 5
        }
77
78 1
        // Third party cache extension
79 1
        $cacheProvider = new Cache();
80 1
        $cacheStrategy = new LifetimeCacheStrategy($cacheProvider);
81
        $cacheExtension = new CacheExtension($cacheStrategy);
82
        $event->getTwig()->addExtension($cacheExtension);
83
84 5
        // jasny/twig-extensions
85 5
        // $event->getTwig()->addExtension(new DateExtension()); // FIXME Not ported to Twig 2.x yet
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
86 5
        // $event->getTwig()->addExtension(new PcreExtension()); // FIXME Not ported to Twig 2.x yet
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
87 5
        // $event->getTwig()->addExtension(new TextExtension()); // FIXME Not ported to Twig 2.x yet
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
88
        // $event->getTwig()->addExtension(new ArrayExtension()); // FIXME Not ported to Twig 2.x yet
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
89
90 5
        // Breakpoint extension
91 5
        if (Configure::read('debug') === true) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
92 5
            // $event->getTwig()->addExtension(new BreakpointExtension()); // FIXME Not ported to Twig 2.x yet
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
93 5
        }
94
    }
95
}
96