• 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

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

18

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

35

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

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

56

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

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

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