• 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

93.55
/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
class ClosureNode extends ExpressionNode
19
{
20
        public function __construct(
1✔
21
                public bool $byRef,
22
                /** @var Php\ParameterNode[] */
23
                public array $params,
24
                /** @var ClosureUseNode[] */
25
                public array $uses,
26
                public Php\IdentifierNode|Php\NameNode|Php\ComplexTypeNode|null $returnType = null,
27
                public ?ExpressionNode $expr = null,
28
                public ?Position $position = null,
29
        ) {
30
                (function (Php\ParameterNode ...$args) {})(...$params);
1✔
31
                (function (ClosureUseNode ...$args) {})(...$uses);
1✔
32
        }
1✔
33

34

35
        public function print(PrintContext $context): string
1✔
36
        {
37
                $arrow = (bool) $this->expr;
1✔
38
                foreach ($this->uses as $use) {
1✔
39
                        $arrow = $arrow && !$use->byRef;
1✔
40
                }
41

42
                return $arrow
1✔
43
                        ? 'fn' . ($this->byRef ? '&' : '')
1✔
44
                                . '(' . $context->implode($this->params) . ')'
1✔
45
                                . ($this->returnType !== null ? ': ' . $this->returnType->print($context) : '')
1✔
46
                                . ' => '
1✔
47
                                . $this->expr->print($context)
1✔
48
                        : 'function ' . ($this->byRef ? '&' : '')
1✔
49
                                . '(' . $context->implode($this->params) . ')'
1✔
50
                                . (!empty($this->uses) ? ' use (' . $context->implode($this->uses) . ')' : '')
1✔
51
                                . ($this->returnType !== null ? ' : ' . $this->returnType->print($context) : '')
1✔
52
                                . ($this->expr ? ' { return ' . $this->expr->print($context) . '; }' : ' {}');
1✔
53
        }
54

55

56
        public function &getIterator(): \Generator
1✔
57
        {
58
                foreach ($this->params as &$item) {
1✔
59
                        yield $item;
×
60
                }
61
                Helpers::removeNulls($this->params);
1✔
62

63
                foreach ($this->uses as &$item) {
1✔
64
                        yield $item;
1✔
65
                }
66
                Helpers::removeNulls($this->uses);
1✔
67

68
                if ($this->returnType) {
1✔
69
                        yield $this->returnType;
×
70
                }
71
                if ($this->expr) {
1✔
72
                        yield $this->expr;
1✔
73
                }
74
        }
1✔
75
}
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