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

nette / latte / 22359082277

24 Feb 2026 04:03PM UTC coverage: 93.959% (+0.05%) from 93.907%
22359082277

push

github

dg
fixed operator ! priority

5273 of 5612 relevant lines covered (93.96%)

0.94 hits per line

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

95.65
/src/Latte/Compiler/Nodes/Php/ArrayItemNode.php
1
<?php declare(strict_types=1);
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
namespace Latte\Compiler\Nodes\Php;
9

10
use Latte\Compiler\Node;
11
use Latte\Compiler\Position;
12
use Latte\Compiler\PrintContext;
13

14

15
class ArrayItemNode extends Node
16
{
17
        public function __construct(
1✔
18
                public ExpressionNode $value,
19
                public ExpressionNode|IdentifierNode|null $key = null,
20
                public bool $byRef = false,
21
                public bool $unpack = false,
22
                public ?Position $position = null,
23
        ) {
24
        }
1✔
25

26

27
        public function print(PrintContext $context): string
1✔
28
        {
29
                $key = match (true) {
1✔
30
                        $this->key instanceof ExpressionNode => $this->key->print($context) . ' => ',
1✔
31
                        $this->key instanceof IdentifierNode => $context->encodeString($this->key->name) . ' => ',
1✔
32
                        $this->key === null => '',
1✔
33
                };
34
                return $key
35
                        . ($this->byRef ? '&' : '')
1✔
36
                        . ($this->unpack ? '...' : '')
1✔
37
                        . $this->value->print($context);
1✔
38
        }
39

40

41
        public function toArgument(): ArgumentNode
42
        {
43
                $key = match (true) {
1✔
44
                        $this->key instanceof Scalar\StringNode => new IdentifierNode($this->key->value),
1✔
45
                        $this->key instanceof IdentifierNode => $this->key,
1✔
46
                        $this->key === null => null,
1✔
47
                        default => throw new \InvalidArgumentException('The expression used in the key cannot be converted to an argument.'),
×
48
                };
49
                return new ArgumentNode($this->value, $this->byRef, $this->unpack, $key, $this->position);
1✔
50
        }
51

52

53
        public function &getIterator(): \Generator
1✔
54
        {
55
                if ($this->key) {
1✔
56
                        yield $this->key;
1✔
57
                }
58
                yield $this->value;
1✔
59
        }
1✔
60
}
61

62

63
class_alias(ArrayItemNode::class, Expression\ArrayItemNode::class);
1✔
64

65
namespace Latte\Compiler\Nodes\Php\Expression;
66

67
if (false) {
1✔
68
        /** @deprecated use Latte\Compiler\Nodes\Php\ArrayItemNode */
69
        class ArrayItemNode
70
        {
71
        }
72
}
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