PathExtension   A
last analyzed

Coupling/Cohesion

Components 0
Dependencies 2

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 35
ccs 25
cts 25
cp 1
rs 10
wmc 3
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B register() 0 32 3
1
<?php
2
3
namespace League\Plates\Extension\Path;
4
5
use League\Plates;
6
7
final class PathExtension implements Plates\Extension
8
{
9 24
    public function register(Plates\Engine $plates) {
10 24
        $c = $plates->getContainer();
11 24
        $c->add('path.resolvePath.prefixes', function($c) {
12 24
            return (array) ($c->get('config')['base_dir'] ?? []);
13 24
        });
14 24
        $c->addComposed('path.normalizeName', function($c) {
15
            return [
16 24
                'path.stripExt' => stripExtNormalizeName(),
17 24
                'path.stripPrefix' => stripPrefixNormalizeName($c->get('path.resolvePath.prefixes'))
18
            ];
19 24
        });
20 24
        $c->addStack('path.resolvePath', function($c) {
21 24
            $config = $c->get('config');
22 24
            $prefixes = $c->get('path.resolvePath.prefixes');
23 24
            return array_filter([
24 24
                'path.id' => idResolvePath(),
25 24
                'path.prefix' => $prefixes ? prefixResolvePath($prefixes, $c->get('fileExists')) : null,
26 24
                'path.ext' => isset($config['ext']) ? extResolvePath($config['ext']) : null,
27 24
                'path.relative' => relativeResolvePath(),
28
            ]);
29 24
        });
30 24
        $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...
31 24
            'ext' => 'phtml',
32
            'base_dir' => null,
33
        ]);
34 24
        $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...
35
            return [
36 24
                'path.normalizeName' => normalizeNameCompose($c->get('path.normalizeName')),
37 24
                'path.resolvePath' => resolvePathCompose($c->get('path.resolvePath')),
38
            ];
39 24
        });
40 24
    }
41
}
42