• 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

57.14
/src/Latte/Compiler/Nodes/Php/Expression/ArrayNode.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\Expression;
9

10
use Latte\Compiler\Nodes\Php\ArgumentNode;
11
use Latte\Compiler\Nodes\Php\ArrayItemNode;
12
use Latte\Compiler\Nodes\Php\ExpressionNode;
13
use Latte\Compiler\Position;
14
use Latte\Compiler\PrintContext;
15
use Latte\Helpers;
16
use const PHP_VERSION_ID;
17

18

19
class ArrayNode extends ExpressionNode
20
{
21
        public function __construct(
1✔
22
                /** @var array<ArrayItemNode> */
23
                public array $items = [],
24
                public ?Position $position = null,
25
        ) {
26
                (function (ArrayItemNode ...$args) {})(...$items);
1✔
27
        }
1✔
28

29

30
        /** @return ArgumentNode[] */
31
        public function toArguments(): array
32
        {
33
                return array_map(fn(ArrayItemNode $item) => $item->toArgument(), $this->items);
1✔
34
        }
35

36

37
        public function print(PrintContext $context): string
1✔
38
        {
39
                // Converts [...$var] -> $var, because PHP 8.0 doesn't support unpacking with string keys
40
                if (PHP_VERSION_ID < 80100) {
1✔
41
                        $res = '[';
×
42
                        $merge = false;
×
43
                        foreach ($this->items as $item) {
×
44
                                if ($item->unpack) {
×
45
                                        $res .= '], ' . $item->value->print($context) . ', [';
×
46
                                        $merge = true;
×
47
                                } else {
48
                                        $res .= $item->print($context) . ', ';
×
49
                                }
50
                        }
51

52
                        $res = str_ends_with($res, ', ') ? substr($res, 0, -2) : $res;
×
53
                        return $merge ? "array_merge($res])" : $res . ']';
×
54
                }
55

56
                return '[' . $context->implode($this->items) . ']';
1✔
57
        }
58

59

60
        public function &getIterator(): \Generator
1✔
61
        {
62
                foreach ($this->items as &$item) {
1✔
63
                        yield $item;
1✔
64
                }
65
                Helpers::removeNulls($this->items);
1✔
66
        }
1✔
67
}
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