• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nette / latte / 16317493748

16 Jul 2025 10:49AM UTC coverage: 93.696% (-0.002%) from 93.698%
16317493748

push

github

dg
PrintContent: refactoring and updated operator precedence and associativity table

23 of 23 new or added lines in 1 file covered. (100.0%)

30 existing lines in 15 files now uncovered.

5187 of 5536 relevant lines covered (93.7%)

0.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.32
/src/Latte/Essential/Nodes/ParametersNode.php
1
<?php
2

3
/**
4
 * This file is part of the Latte (https://latte.nette.org)
5
 * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
 */
7

8
declare(strict_types=1);
9

10
namespace Latte\Essential\Nodes;
11

12
use Latte\CompileException;
13
use Latte\Compiler\Nodes\Php\Expression\AssignNode;
14
use Latte\Compiler\Nodes\Php\Expression\VariableNode;
15
use Latte\Compiler\Nodes\Php\ParameterNode;
16
use Latte\Compiler\Nodes\Php\Scalar\NullNode;
17
use Latte\Compiler\Nodes\StatementNode;
18
use Latte\Compiler\PrintContext;
19
use Latte\Compiler\Tag;
20
use Latte\Compiler\Token;
21
use Latte\Helpers;
22
use function is_string;
23

24

25
/**
26
 * {parameters [type] $var, ...}
27
 */
28
class ParametersNode extends StatementNode
29
{
30
        /** @var ParameterNode[] */
31
        public array $parameters = [];
32

33

34
        public static function create(Tag $tag): static
1✔
35
        {
36
                if (!$tag->isInHead()) {
1✔
UNCOV
37
                        throw new CompileException('{parameters} is allowed only in template header.', $tag->position);
×
38
                }
39
                $tag->expectArguments();
1✔
40
                $node = new static;
1✔
41
                $node->parameters = self::parseParameters($tag);
1✔
42
                return $node;
1✔
43
        }
44

45

46
        private static function parseParameters(Tag $tag): array
1✔
47
        {
48
                $stream = $tag->parser->stream;
1✔
49
                $params = [];
1✔
50
                do {
51
                        $type = $tag->parser->parseType();
1✔
52

53
                        $save = $stream->getIndex();
1✔
54
                        $expr = $stream->is(Token::Php_Variable) ? $tag->parser->parseExpression() : null;
1✔
55
                        if ($expr instanceof VariableNode && is_string($expr->name)) {
1✔
56
                                $params[] = new ParameterNode($expr, new NullNode, $type);
1✔
57
                        } elseif (
58
                                $expr instanceof AssignNode
1✔
59
                                && $expr->var instanceof VariableNode
1✔
60
                                && is_string($expr->var->name)
1✔
61
                        ) {
62
                                $params[] = new ParameterNode($expr->var, $expr->expr, $type);
1✔
63
                        } else {
64
                                $stream->seek($save);
×
UNCOV
65
                                $stream->throwUnexpectedException(addendum: ' in ' . $tag->getNotation());
×
66
                        }
67
                } while ($stream->tryConsume(',') && !$stream->peek()->isEnd());
1✔
68

69
                return $params;
1✔
70
        }
71

72

73
        public function print(PrintContext $context): string
1✔
74
        {
75
                $context->paramsExtraction = $this->parameters;
1✔
76
                return '';
1✔
77
        }
78

79

80
        public function &getIterator(): \Generator
1✔
81
        {
82
                foreach ($this->parameters as &$param) {
1✔
83
                        yield $param;
1✔
84
                }
85
                Helpers::removeNulls($this->parameters);
1✔
86
        }
1✔
87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc