PlatesExtension   A
last analyzed

Coupling/Cohesion

Components 0
Dependencies 8

Complexity

Total Complexity 2

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 93.48%

Importance

Changes 0
Metric Value
dl 0
loc 67
ccs 43
cts 46
cp 0.9348
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 8

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 64 2
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
            'validate_paths' => true,
12
            'php_extensions' => ['php', 'phtml'],
13
            'image_extensions' => ['png', 'jpg'],
14
        ]);
15
        $c->addComposed('compose', function() { return []; });
16 20
        $c->add('fileExists', function($c) {
0 ignored issues
show
Unused Code introduced by RJ Garcia
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...
17 20
            return 'file_exists';
18 20
        });
19 20
        $c->add('renderTemplate', function($c) {
20 20
            $rt = new RenderTemplate\FileSystemRenderTemplate([
21
                [
22 20
                    Template\matchExtensions($c->get('config')['php_extensions']),
23 20
                    new RenderTemplate\PhpRenderTemplate($c->get('renderTemplate.bind'))
24
                ],
25
                [
26 20
                    Template\matchExtensions($c->get('config')['image_extensions']),
27 20
                    RenderTemplate\MapContentRenderTemplate::base64Encode(new RenderTemplate\StaticFileRenderTemplate())
28
                ],
29
                [
30 20
                    Template\matchStub(true),
31 20
                    new RenderTemplate\StaticFileRenderTemplate(),
32
                ]
33
            ]);
34 20
            if ($c->get('config')['validate_paths']) {
35 20
                $rt = new RenderTemplate\ValidatePathRenderTemplate($rt, $c->get('fileExists'));
36
            }
37 20
            $rt = array_reduce($c->get('renderTemplate.factories'), function($rt, $create) {
38 20
                return $create($rt);
39 20
            }, $rt);
40 20
            $rt = new RenderTemplate\ComposeRenderTemplate($rt, $c->get('compose'));
41 20
            return $rt;
42 20
        });
43 20
        $c->add('renderTemplate.bind', function() {
44 20
            return Util\id();
45 20
        });
46 20
        $c->add('renderTemplate.factories', function() {
47 20
            return [];
48 20
        });
49
50 20
        $plates->addMethods([
51
            'pushComposers' => function(Engine $e, $def_composer) {
52 20
                $e->getContainer()->wrapComposed('compose', function($composed, $c) use ($def_composer) {
53 20
                    return array_merge($composed, $def_composer($c));
54 20
                });
55 20
            },
56
            'unshiftComposers' => function(Engine $e, $def_composer) {
57
                $e->getContainer()->wrapComposed('compose', function($composed, $c) use ($def_composer) {
58
                    return array_merge($def_composer($c), $composed);
59
                });
60 20
            },
61 20
            'addConfig' => function(Engine $e, array $config) {
62 20
                $e->getContainer()->merge('config', $config);
63 20
            },
64
            /** merges in config values, but will defer to values already set in the config */
65 20
            'defineConfig' => function(Engine $e, array $config_def) {
66 20
                $config = $e->getContainer()->get('config');
67 20
                $e->getContainer()->add('config', array_merge($config_def, $config));
68 20
            },
69
        ]);
70 20
    }
71
}
72