DisplayStartNode   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 16
c 1
b 0
f 0
dl 0
loc 41
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A compile() 0 14 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Shoot\Twig\Node;
5
6
use Twig\Compiler;
7
use Twig\Node\ModuleNode;
8
use Twig\Node\Node;
9
10
/**
11
 * This node is added to the top of the display method of a Twig template and is used by Shoot to wrap the method's
12
 * contents in a callback.
13
 *
14
 * @internal
15
 */
16
final class DisplayStartNode extends Node
17
{
18
    /** @var FindPresentationModelInterface */
19
    private $findPresentationModel;
20
21
    /** @var ModuleNode */
22
    private $module;
23
24
    /**
25
     * @param ModuleNode                     $module
26
     * @param FindPresentationModelInterface $findPresentationModel
27
     */
28 6
    public function __construct(ModuleNode $module, FindPresentationModelInterface $findPresentationModel)
29
    {
30 6
        parent::__construct();
31
32 6
        $this->module = $module;
33 6
        $this->findPresentationModel = $findPresentationModel;
34
35 6
        $this->setSourceContext($module->getSourceContext());
0 ignored issues
show
Bug introduced by
It seems like $module->getSourceContext() can also be of type null; however, parameter $source of Twig\Node\Node::setSourceContext() does only seem to accept Twig\Source, maybe add an additional type check? ( Ignorable by Annotation )

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

35
        $this->setSourceContext(/** @scrutinizer ignore-type */ $module->getSourceContext());
Loading history...
36 6
    }
37
38
    /**
39
     * @param Compiler $compiler
40
     *
41
     * @return void
42
     */
43 6
    public function compile(Compiler $compiler): void
44
    {
45 6
        if ($this->module->hasAttribute('is_embedded')) {
46 1
            return;
47
        }
48
49 6
        $presentationModel = $this->findPresentationModel->for($this->getSourceContext());
0 ignored issues
show
Bug introduced by
It seems like $this->getSourceContext() can also be of type null; however, parameter $source of Shoot\Shoot\Twig\Node\Fi...onModelInterface::for() does only seem to accept Twig\Source, maybe add an additional type check? ( Ignorable by Annotation )

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

49
        $presentationModel = $this->findPresentationModel->for(/** @scrutinizer ignore-type */ $this->getSourceContext());
Loading history...
50
51
        $compiler
52 6
            ->write("\$presentationModel = new $presentationModel(\$context);\n")
53 6
            ->write("\$originalContext = \$context;\n\n")
54 6
            ->write("\$callback = function (array \$context) use (\$blocks, \$originalContext, \$macros) {\n")
55 6
            ->indent()
56 6
            ->write("\$suppressedException = null;\n\n");
57 6
    }
58
}
59