Passed
Push — master ( 11e596...ed648f )
by Gabriel
13:25
created

LegacyLoadExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
c 2
b 0
f 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 16 4
1
<?php
2
declare(strict_types=1);
3
4
namespace Nip\View\Extensions;
5
6
use League\Plates\Engine;
7
use Nip\View;
8
use Nip\View\Traits\HasMethodsTrait;
9
use Nip\View\ViewInterface;
10
11
/**
12
 * Class LegacyLoadExtension
13
 * @package Nip\View\Extensions
14
 */
15
class LegacyLoadExtension extends AbstractExtension
16
{
17
    /**
18
     * @param ViewInterface|HasMethodsTrait|View $engine
19
     * @return void
20
     */
21
    public function register(Engine $engine)
22
    {
23
        $engine->registerFunction('load', function (...$arguments) use ($engine) {
24
            $view = array_shift($arguments);
25
            $variables = array_shift($arguments);
26
            $return = array_shift($arguments);
27
            if (is_array($view)) {
28
                $view = $engine->buildPath($view);
0 ignored issues
show
introduced by
The method buildPath() does not exist on League\Plates\Engine. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
                /** @scrutinizer ignore-call */ 
29
                $view = $engine->buildPath($view);
Loading history...
29
            }
30
            $variables = is_array($variables) ? $variables : [];
31
32
            $content = $engine->getContents($view, $variables);
0 ignored issues
show
introduced by
The method getContents() does not exist on League\Plates\Engine. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
            /** @scrutinizer ignore-call */ 
33
            $content = $engine->getContents($view, $variables);
Loading history...
33
            if ($return === true) {
34
                return $content;
35
            }
36
            echo $content;
37
        });
38
    }
39
}
40