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

nette / latte / 22371200612

24 Feb 2026 09:38PM UTC coverage: 94.76% (-0.08%) from 94.841%
22371200612

push

github

dg
added CLAUDE.md

5534 of 5840 relevant lines covered (94.76%)

0.95 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
/**
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
                        $usesByRef = $usesByRef || $use->byRef;
1✔
43
                }
44

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

58

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

66
                foreach ($this->uses as &$item) {
1✔
67
                        yield $item;
1✔
68
                }
69
                Helpers::removeNulls($this->uses);
1✔
70

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