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

nette / latte / 16317387179

16 Jul 2025 10:46AM UTC coverage: 93.699% (-0.1%) from 93.84%
16317387179

push

github

dg
added Helpers::stringOrNull() [Closes #401]

6 of 6 new or added lines in 2 files covered. (100.0%)

57 existing lines in 19 files now uncovered.

5160 of 5507 relevant lines covered (93.7%)

0.94 hits per line

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

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

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

19

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

30

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

37

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

55
                        $res = str_ends_with($res, ', ') ? substr($res, 0, -2) : $res;
×
UNCOV
56
                        return $merge ? "array_merge($res])" : $res . ']';
×
57
                }
58

59
                return '[' . $context->implode($this->items) . ']';
1✔
60
        }
61

62

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