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

nette / latte / 22368407632

24 Feb 2026 08:17PM UTC coverage: 94.825% (-0.2%) from 95.054%
22368407632

push

github

dg
phpstan

135 of 147 new or added lines in 38 files covered. (91.84%)

186 existing lines in 70 files now uncovered.

5534 of 5836 relevant lines covered (94.83%)

0.95 hits per line

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

93.94
/src/Latte/Compiler/Nodes/Php/Expression/ClosureNode.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;
11
use Latte\Compiler\Nodes\Php\ClosureUseNode;
12
use Latte\Compiler\Nodes\Php\ExpressionNode;
13
use Latte\Compiler\Position;
14
use Latte\Compiler\PrintContext;
15
use Latte\Helpers;
16

17

18
/**
19
 * Closure or arrow function (fn($x) => $x or function($x) use ($y) {}).
20
 */
21
class ClosureNode extends ExpressionNode
22
{
23
        public function __construct(
1✔
24
                public bool $byRef,
25
                /** @var Php\ParameterNode[] */
26
                public array $params,
27
                /** @var ClosureUseNode[] */
28
                public array $uses,
29
                public Php\IdentifierNode|Php\NameNode|Php\ComplexTypeNode|null $returnType = null,
30
                public ?ExpressionNode $expr = null,
31
                public ?Position $position = null,
32
        ) {
33
                (function (Php\ParameterNode ...$args) {})(...$params);
1✔
34
                (function (ClosureUseNode ...$args) {})(...$uses);
1✔
35
        }
1✔
36

37

38
        public function print(PrintContext $context): string
1✔
39
        {
40
                $usesByRef = false;
1✔
41
                foreach ($this->uses as $use) {
1✔
42
                        if ($use->byRef) {
1✔
43
                                $usesByRef = true;
1✔
44
                                break;
1✔
45
                        }
46
                }
47

48
                return $this->expr && !$usesByRef
1✔
49
                        ? 'fn' . ($this->byRef ? '&' : '')
1✔
50
                                . '(' . $context->implode($this->params) . ')'
1✔
51
                                . ($this->returnType !== null ? ': ' . $this->returnType->print($context) : '')
1✔
52
                                . ' => '
1✔
53
                                . $this->expr->print($context)
1✔
54
                        : 'function ' . ($this->byRef ? '&' : '')
1✔
55
                                . '(' . $context->implode($this->params) . ')'
1✔
56
                                . (!empty($this->uses) ? ' use (' . $context->implode($this->uses) . ')' : '')
1✔
57
                                . ($this->returnType !== null ? ' : ' . $this->returnType->print($context) : '')
1✔
58
                                . ($this->expr ? ' { return ' . $this->expr->print($context) . '; }' : ' {}');
1✔
59
        }
60

61

62
        public function &getIterator(): \Generator
1✔
63
        {
64
                foreach ($this->params as &$item) {
1✔
UNCOV
65
                        yield $item;
×
66
                }
67
                Helpers::removeNulls($this->params);
1✔
68

69
                foreach ($this->uses as &$item) {
1✔
70
                        yield $item;
1✔
71
                }
72
                Helpers::removeNulls($this->uses);
1✔
73

74
                if ($this->returnType) {
1✔
UNCOV
75
                        yield $this->returnType;
×
76
                }
77
                if ($this->expr) {
1✔
78
                        yield $this->expr;
1✔
79
                }
80
        }
1✔
81
}
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