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

nette / latte / 16317493748

16 Jul 2025 10:49AM UTC coverage: 93.696% (-0.002%) from 93.698%
16317493748

push

github

dg
PrintContent: refactoring and updated operator precedence and associativity table

23 of 23 new or added lines in 1 file covered. (100.0%)

30 existing lines in 15 files now uncovered.

5187 of 5536 relevant lines covered (93.7%)

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
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
use Latte\Helpers;
18

19

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

36

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

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

57

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

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

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