LayoutSectionsExtension::register()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 1
nop 1
dl 0
loc 29
ccs 23
cts 23
cp 1
crap 2
rs 9.456
c 0
b 0
f 0
1
<?php
2
3
namespace League\Plates\Extension\LayoutSections;
4
5
use League\Plates;
6
use League\Plates\Extension\RenderContext;
7
8
final class LayoutSectionsExtension implements Plates\Extension
9
{
10 24
    public function register(Plates\Engine $plates) {
11 24
        $c = $plates->getContainer();
12
13 24
        $c->wrap('renderTemplate.factories', function($factories, $c) {
14 24
            $default_layout_path = $c->get('config')['default_layout_path'];
15 24
            if ($default_layout_path) {
16 12
                $factories[] = DefaultLayoutRenderTemplate::factory($default_layout_path);
17
            }
18 24
            $factories[] = LayoutRenderTemplate::factory();
19 24
            return $factories;
20 24
        });
21
22 24
        $plates->defineConfig(['default_layout_path' => null]);
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...
23 24
        $plates->pushComposers(function($c) {
0 ignored issues
show
Documentation Bug introduced by
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...
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
24 24
            return ['layoutSections.sections' => sectionsCompose()];
25 24
        });
26 24
        $plates->addFuncs(function($c) {
0 ignored issues
show
Documentation Bug introduced by
The method addFuncs 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...
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
27 24
            $template_args = RenderContext\assertTemplateArgsFunc();
28 24
            $one_arg = RenderContext\assertArgsFunc(1);
29
30
            return [
31 24
                'layout' => [layoutFunc(), $template_args],
32 24
                'section' => [sectionFunc(), RenderContext\assertArgsFunc(1, 1)],
33 24
                'start' => [startFunc(), $one_arg],
34 24
                'push' => [startFunc(START_APPEND), $one_arg],
35 24
                'unshift' => [startFunc(START_PREPEND), $one_arg],
36
            ];
37 24
        });
38 24
    }
39
}
40