Completed
Push — master ( b3978b...8d3a7c )
by
unknown
26:09 queued 12:30
created

PlatesExtension::register()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 69
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 45
nc 1
nop 1
dl 0
loc 69
rs 9.2083
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 League\Plates;
4
5
final class PlatesExtension implements Extension
6
{
7
    public function register(Engine $plates) {
8
        $c = $plates->getContainer();
9
10
        $c->add('config', [
11
            'render_context_var_name' => 'v',
12
            'ext' => 'phtml',
13
            'base_dir' => null,
14
            'escape_encoding' => null,
15
            'escape_flags' => null,
16
            'validate_paths' => true,
17
            'php_extensions' => ['php', 'phtml'],
18
            'image_extensions' => ['png', 'jpg'],
19
        ]);
20
        $c->addComposed('compose', function() { return []; });
21
        $c->add('fileExists', function($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
22
            return 'file_exists';
23
        });
24
        $c->add('renderTemplate', function($c) {
25
            $rt = new RenderTemplate\FileSystemRenderTemplate([
26
                [
27
                    Template\matchExtensions($c->get('config')['php_extensions']),
28
                    new RenderTemplate\PhpRenderTemplate($c->get('renderTemplate.bind'))
29
                ],
30
                [
31
                    Template\matchExtensions($c->get('config')['image_extensions']),
32
                    RenderTemplate\MapContentRenderTemplate::base64Encode(new RenderTemplate\StaticFileRenderTemplate())
33
                ],
34
                [
35
                    Template\matchStub(true),
36
                    new RenderTemplate\StaticFileRenderTemplate(),
37
                ]
38
            ]);
39
            if ($c->get('config')['validate_paths']) {
40
                $rt = new RenderTemplate\ValidatePathRenderTemplate($rt, $c->get('fileExists'));
41
            }
42
            $rt = array_reduce($c->get('renderTemplate.factories'), function($rt, $create) {
43
                return $create($rt);
44
            }, $rt);
45
            $rt = new RenderTemplate\ComposeRenderTemplate($rt, $c->get('compose'));
46
            return $rt;
47
        });
48
        $c->add('renderTemplate.bind', function() {
49
            return Util\id();
50
        });
51
        $c->add('renderTemplate.factories', function() {
52
            return [];
53
        });
54
55
        $plates->addMethods([
56
            'pushComposers' => function(Engine $e, $def_composer) {
57
                $e->getContainer()->wrapComposed('compose', function($composed, $c) use ($def_composer) {
58
                    return array_merge($composed, $def_composer($c));
59
                });
60
            },
61
            'unshiftComposers' => function(Engine $e, $def_composer) {
62
                $e->getContainer()->wrapComposed('compose', function($composed, $c) use ($def_composer) {
63
                    return array_merge($def_composer($c), $composed);
64
                });
65
            },
66
            'addConfig' => function(Engine $e, array $config) {
67
                $e->getContainer()->merge('config', $config);
68
            },
69
            /** merges in config values, but will defer to values already set in the config */
70
            'defineConfig' => function(Engine $e, array $config_def) {
71
                $config = $e->getContainer()->get('config');
72
                $e->getContainer()->add('config', array_merge($config_def, $config));
73
            },
74
        ]);
75
    }
76
}
77