PathExtension   A
last analyzed

Coupling/Cohesion

Components 0
Dependencies 2

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 40
ccs 28
cts 28
cp 1
rs 10
c 1
b 0
f 0
wmc 6
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B register() 0 37 6
1
<?php
2
3
namespace League\Plates\Extension\Path;
4
5
use League\Plates;
6
7
final class PathExtension implements Plates\Extension
8
{
9 20
    public function register(Plates\Engine $plates) {
10 20
        $c = $plates->getContainer();
11 20
        $c->add('path.resolvePath.prefixes', function($c) {
12 20
            $config = $c->get('config');
13
14
            // wrap base dir in an array if not already
15 20
            $base_dir = isset($config['base_dir']) ? $config['base_dir'] : null;
16 20
            $base_dir = $base_dir ? (is_string($base_dir) ? [$base_dir] : $base_dir) : $base_dir;
17 20
            return $base_dir;
18 20
        });
19 20
        $c->addComposed('path.normalizeName', function($c) {
20
            return [
21 20
                'path.stripExt' => stripExtNormalizeName(),
22 20
                'path.stripPrefix' => stripPrefixNormalizeName($c->get('path.resolvePath.prefixes'))
23
            ];
24 20
        });
25 20
        $c->addStack('path.resolvePath', function($c) {
26 20
            $config = $c->get('config');
27 20
            $prefixes = $c->get('path.resolvePath.prefixes');
28 20
            return array_filter([
29 20
                'path.id' => idResolvePath(),
30 20
                'path.prefix' => $prefixes ? prefixResolvePath($prefixes, $c->get('fileExists')) : null,
31 20
                'path.ext' => isset($config['ext']) ? extResolvePath($config['ext']) : null,
32 20
                'path.relative' => relativeResolvePath(),
33
            ]);
34 20
        });
35 20
        $plates->defineConfig([
0 ignored issues
show
Documentation Bug introduced by RJ Garcia
The method defineConfig does not exist on object<League\Plates\Engine>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
36 20
            'ext' => 'phtml',
37
            'base_dir' => null,
38
        ]);
39 20
        $plates->pushComposers(function($c) {
0 ignored issues
show
Documentation Bug introduced by RJ Garcia
The method pushComposers does not exist on object<League\Plates\Engine>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
40
            return [
41 20
                'path.normalizeName' => normalizeNameCompose($c->get('path.normalizeName')),
42 20
                'path.resolvePath' => resolvePathCompose($c->get('path.resolvePath')),
43
            ];
44 20
        });
45 20
    }
46
}
47