Completed
Push — master ( b3978b...8d3a7c )
by
unknown
26:09 queued 12:30
created

src/Extension/Folders/FoldersExtension.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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