Issues (53)

RenderConditions/RenderConditionsExtension.php (3 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nip\View\Extensions\RenderConditions;
6
7
use League\Plates\Engine;
8
use Nip\View\Extensions\AbstractExtension;
9
use Nip\View\View;
10
use function is_callable;
11
12
class RenderConditionsExtension extends AbstractExtension
13
{
14
    public function register(View|Engine $engine)
15
    {
16
        parent::register($engine);
17
        $engine->addMethod('loadIfExists', [$this, 'loadIfExists']);
0 ignored issues
show
The method addMethod() 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

17
        $engine->/** @scrutinizer ignore-call */ 
18
                 addMethod('loadIfExists', [$this, 'loadIfExists']);
Loading history...
18
        $engine->addMethod('loadIf', [$this, 'loadIf']);
19
        $engine->addMethod('loadWithFallback', [$this, 'loadWithFallback']);
20
        $engine->addMethod('existPath', [$this, 'existPath']);
21
    }
22
23
    /**
24
     * @param array $variables
25
     * @param bool $return
26
     *
27
     * @return bool|string|void|null
28
     */
29
    public function loadIfExists($view, $variables = [], $return = false)
30
    {
31
        return $this->loadIf($this->existPath($view), $view, $variables, $return);
0 ignored issues
show
The call to Nip\View\Extensions\Rend...ionsExtension::loadIf() has too many arguments starting with $return. ( Ignorable by Annotation )

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

31
        return $this->/** @scrutinizer ignore-call */ loadIf($this->existPath($view), $view, $variables, $return);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
32
    }
33
34
    /**
35
     * @param bool|callable $condition
36
     * @param array $variables
37
     *
38
     * @return bool|string|void|null
39
     */
40
    public function loadIf($condition, $view, $variables = [])
41
    {
42
        $condition = is_callable($condition) ? $condition() : $condition;
43
        if (false == $condition) {
44
            return;
45
        }
46
47
        return $this->template->fetch($view, $variables);
48
    }
49
50
    public function existPath($view): bool
51
    {
52
        return $this->engine->existPath($view);
53
    }
54
55
    /**
56
     * @param array $variables
57
     * @param bool $return
58
     *
59
     * @return bool|string|void|null
60
     */
61
    public function loadWithFallback($view, $fallback, $variables = [], $return = false)
62
    {
63
        $view = $this->existPath($view) ? $view : $fallback;
64
65
        return $this->template->fetch($view, $variables, $return);
0 ignored issues
show
The call to League\Plates\Template\Template::fetch() has too many arguments starting with $return. ( Ignorable by Annotation )

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

65
        return $this->template->/** @scrutinizer ignore-call */ fetch($view, $variables, $return);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
66
    }
67
}
68