FoldersExtension   A
last analyzed

Coupling/Cohesion

Components 0
Dependencies 2

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 96.3%

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 26
cts 27
cp 0.963
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B register() 0 37 3
1
<?php
2
3
namespace League\Plates\Extension\Folders;
4
5
use League\Plates;
6
7
final class FoldersExtension implements Plates\Extension
8
{
9 20
    public function register(Plates\Engine $plates) {
10 20
        $c = $plates->getContainer();
11 20
        $c->add('folders.folders', []);
12 20
        $c->wrapStack('path.resolvePath', function($stack, $c) {
13 20
            $config = $c;
14 20
            return array_merge($stack, [
15 20
                'folders' => foldersResolvePath(
16 20
                    $c->get('folders.folders'),
17 20
                    $c->get('config')['folder_separator'],
18 20
                    $c->get('fileExists')
19
                )
20
            ]);
21 20
        });
22 20
        $c->wrapComposed('path.normalizeName', function($composed, $c) {
23 20
            return array_merge($composed, [
24 20
                'folders.stripFolders' => stripFoldersNormalizeName($c->get('folders.folders'))
25
            ]);
26 20
        });
27
28 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...
29 20
            'folder_separator' => '::',
30
        ]);
31 20
        $plates->addMethods([
32 20
            'addFolder' => function($plates, $folder, $prefixes, $fallback = false) {
33 4
                $prefixes = is_string($prefixes) ? [$prefixes] : $prefixes;
34 4
                if ($fallback) {
35
                    $prefixes[] = '';
36
                }
37 4
                $plates->getContainer()->merge('folders.folders', [
38
                    $folder => [
39 4
                        'folder' => $folder,
40 4
                        'prefixes' => $prefixes,
41
                    ]
42
                ]);
43 20
            },
44
        ]);
45 20
    }
46
}
47