Completed
Push — master ( bbe0e7...1d2424 )
by jelmer
32:52 queued 27:17
created

TwigFilters::addFilters()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 88
Code Lines 60

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 61
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 60
nc 1
nop 2
dl 0
loc 88
ccs 61
cts 61
cp 1
crap 1
rs 8.8727
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Common\Core\Twig\Extensions;
4
5
/**
6
 * Contains all Forkcms filters for Twig
7
 */
8
9
use Twig\TwigFilter;
10
use Twig\TwigFunction;
11
use Twig_Environment;
12
13
class TwigFilters
14
{
15
    /**
16
     * //http://twig.sensiolabs.org/doc/advanced.html#id2
17
     * returns a collection of Twig SimpleFilters
18
     *
19
     * @param Twig_Environment $twig
20
     * @param string $app
21
     */
22 82
    public static function addFilters(Twig_Environment $twig, string $app): void
23
    {
24 82
        $app .= '\Core\Engine\TemplateModifiers';
25 82
        $twig->addFilter(new TwigFilter('getpageinfo', $app . '::getPageInfo'));
26 82
        $twig->addFilter(new TwigFilter('highlight', $app . '::highlightCode'));
27 82
        $twig->addFilter(new TwigFilter('profilesetting', $app . '::profileSetting'));
28 82
        $twig->addFilter(new TwigFilter('formatcurrency', $app . '::formatCurrency', ['is_safe' => ['html']]));
29 82
        $twig->addFilter(new TwigFilter('usersetting', $app . '::userSetting'));
30 82
        $twig->addFilter(new TwigFilter('uppercase', $app . '::uppercase'));
31 82
        $twig->addFilter(new TwigFilter('rand', $app . '::random'));
32 82
        $twig->addFilter(new TwigFilter('formatfloat', $app . '::formatFloat'));
33 82
        $twig->addFilter(new TwigFilter('truncate', $app . '::truncate'));
34 82
        $twig->addFilter(new TwigFilter('camelcase', $app . '::camelCase'));
35 82
        $twig->addFilter(new TwigFilter('snakeCase', $app . '::snakeCase'));
36 82
        $twig->addFilter(new TwigFilter('stripnewlines', $app . '::stripNewlines'));
37 82
        $twig->addFilter(new TwigFilter('formatnumber', $app . '::formatNumber'));
38 82
        $twig->addFilter(new TwigFilter('tolabel', $app . '::toLabel'));
39 82
        $twig->addFilter(new TwigFilter('cleanupplaintext', $app . '::cleanupPlainText'));
40
41
        // exposed PHP functions
42 82
        $twig->addFilter(new TwigFilter('urlencode', 'urlencode'));
43 82
        $twig->addFilter(new TwigFilter('rawurlencode', 'rawurlencode'));
44 82
        $twig->addFilter(new TwigFilter('striptags', 'strip_tags'));
45 82
        $twig->addFilter(new TwigFilter('addslashes', 'addslashes'));
46 82
        $twig->addFilter(new TwigFilter('count', 'count'));
47 82
        $twig->addFilter(new TwigFilter('is_array', 'is_array'));
48 82
        $twig->addFilter(new TwigFilter('ucfirst', 'ucfirst'));
49
50
        // Functions navigation
51 82
        $twig->addFunction(
52 82
            new TwigFunction(
53 82
                'getnavigation',
54 82
                $app . '::getNavigation',
55 82
                ['is_safe' => ['html']]
56
            )
57
        );
58 82
        $twig->addFunction(
59 82
            new TwigFunction(
60 82
                'getsubnavigation',
61 82
                $app . '::getSubNavigation',
62 82
                ['is_safe' => ['html']]
63
            )
64
        );
65 82
        $twig->addFunction(
66 82
            new TwigFunction(
67 82
                'parsewidget',
68 82
                $app . '::parseWidget',
69 82
                ['is_safe' => ['html']]
70
            )
71
        );
72
73
        // Function URL
74 82
        $twig->addFunction(
75 82
            new TwigFunction(
76 82
                'geturl',
77 82
                $app . '::getUrl'
78
            )
79
        );
80 82
        $twig->addFunction(
81 82
            new TwigFunction(
82 82
                'geturlforextraid',
83 82
                $app . '::getUrlForExtraId'
84
            )
85
        );
86 82
        $twig->addFunction(
87 82
            new TwigFunction(
88 82
                'geturlforblock',
89 82
                $app . '::getUrlForBlock'
90
            )
91
        );
92
93
        // boolean functions
94 82
        $twig->addFunction(
95 82
            new TwigFunction(
96 82
                'showbool',
97 82
                $app . '::showBool',
98 82
                ['is_safe' => ['html']]
99
            )
100
        );
101
102
        // @Deprecated We should look for replacements because they run on spoon library
103
        // after we have those we can remove them
104
105 82
        $twig->addFilter(new TwigFilter('spoondate', $app . '::spoonDate'));
106 82
        $twig->addFilter(new TwigFilter('formatdate', $app . '::formatDate'));
107 82
        $twig->addFilter(new TwigFilter('formattime', $app . '::formatTime'));
108 82
        $twig->addFilter(new TwigFilter('timeago', $app . '::timeAgo'));
109 82
        $twig->addFilter(new TwigFilter('formatdatetime', $app . '::formatDateTime'));
110 82
    }
111
}
112