Completed
Push — master ( 22bc57...1ce92a )
by
unknown
29:24 queued 15:51
created

src/Extension/Path/PathExtension.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\Path;
4
5
use League\Plates;
6
7
final class PathExtension implements Plates\Extension
8
{
9 16
    public function register(Plates\Engine $plates) {
10 16
        $c = $plates->getContainer();
11 16
        $c->add('path.resolvePath.prefixes', function($c) {
12 16
            $config = $c->get('config');
13
14
            // wrap base dir in an array if not already
15 16
            $base_dir = isset($config['base_dir']) ? $config['base_dir'] : null;
16 16
            $base_dir = $base_dir ? (is_string($base_dir) ? [$base_dir] : $base_dir) : $base_dir;
17 16
            return $base_dir;
18 16
        });
19 16
        $c->addComposed('path.normalizeName', function($c) {
20
            return [
21 16
                'path.stripExt' => stripExtNormalizeName(),
22 16
                'path.stripPrefix' => stripPrefixNormalizeName($c->get('path.resolvePath.prefixes'))
23
            ];
24 16
        });
25 16
        $c->addStack('path.resolvePath', function($c) {
26 16
            $config = $c->get('config');
27 16
            $prefixes = $c->get('path.resolvePath.prefixes');
28 16
            return array_filter([
29 16
                'path.id' => idResolvePath(),
30 16
                'path.prefix' => $prefixes ? prefixResolvePath($prefixes, $c->get('fileExists')) : null,
31 16
                'path.ext' => isset($config['ext']) ? extResolvePath($config['ext']) : null,
32 16
                'path.relative' => relativeResolvePath(),
33
            ]);
34 16
        });
35 16
        $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...
36
            'ext' => 'phtml',
37 16
            'base_dir' => null,
38 16
        ]);
39
        $plates->pushComposers(function($c) {
40 16
            return [
41 16
                'path.normalizeName' => normalizeNameCompose($c->get('path.normalizeName')),
42
                'path.resolvePath' => resolvePathCompose($c->get('path.resolvePath')),
43
            ];
44
        });
45
    }
46
}
47