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
![]() |
|||||
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
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
![]() |
|||||
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 |