Completed
Pull Request — master (#213)
by
unknown
13:03 queued 11:41
created

PlatesExtension::register()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 69
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 43
CRAP Score 2.0011

Importance

Changes 0
Metric Value
cc 2
eloc 45
nc 1
nop 1
dl 0
loc 69
ccs 43
cts 46
cp 0.9348
crap 2.0011
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 20
    public function register(Engine $plates) {
8 20
        $c = $plates->getContainer();
9
10 20
        $c->add('config', [
11 20
            '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 20
        $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 20
            return 'file_exists';
23 20
        });
24 20
        $c->add('renderTemplate', function($c) {
25 20
            $rt = new RenderTemplate\FileSystemRenderTemplate([
26
                [
27 20
                    Template\matchExtensions($c->get('config')['php_extensions']),
28 20
                    new RenderTemplate\PhpRenderTemplate($c->get('renderTemplate.bind'))
29
                ],
30
                [
31 20
                    Template\matchExtensions($c->get('config')['image_extensions']),
32 20
                    RenderTemplate\MapContentRenderTemplate::base64Encode(new RenderTemplate\StaticFileRenderTemplate())
33
                ],
34
                [
35 20
                    Template\matchStub(true),
36 20
                    new RenderTemplate\StaticFileRenderTemplate(),
37
                ]
38
            ]);
39 20
            if ($c->get('config')['validate_paths']) {
40 20
                $rt = new RenderTemplate\ValidatePathRenderTemplate($rt, $c->get('fileExists'));
41
            }
42 20
            $rt = array_reduce($c->get('renderTemplate.factories'), function($rt, $create) {
43 20
                return $create($rt);
44 20
            }, $rt);
45 20
            $rt = new RenderTemplate\ComposeRenderTemplate($rt, $c->get('compose'));
46 20
            return $rt;
47 20
        });
48 20
        $c->add('renderTemplate.bind', function() {
49 20
            return Util\id();
50 20
        });
51 20
        $c->add('renderTemplate.factories', function() {
52 20
            return [];
53 20
        });
54
55 20
        $plates->addMethods([
56
            'pushComposers' => function(Engine $e, $def_composer) {
57 20
                $e->getContainer()->wrapComposed('compose', function($composed, $c) use ($def_composer) {
58 20
                    return array_merge($composed, $def_composer($c));
59 20
                });
60 20
            },
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 20
            },
66 20
            'addConfig' => function(Engine $e, array $config) {
67 20
                $e->getContainer()->merge('config', $config);
68 20
            },
69
            /** merges in config values, but will defer to values already set in the config */
70 20
            'defineConfig' => function(Engine $e, array $config_def) {
71 20
                $config = $e->getContainer()->get('config');
72 20
                $e->getContainer()->add('config', array_merge($config_def, $config));
73 20
            },
74
        ]);
75 20
    }
76
}
77