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

nette / forms / 26455457147

26 May 2026 02:44PM UTC coverage: 93.345%. Remained the same
26455457147

push

github

dg
fixed PHPStan errors

48 of 51 new or added lines in 12 files covered. (94.12%)

34 existing lines in 10 files now uncovered.

2104 of 2254 relevant lines covered (93.35%)

0.93 hits per line

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

98.33
/src/Bridges/FormsLatte/Nodes/FieldNNameNode.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 Nette\Bridges\FormsLatte\Nodes;
9

10
use Latte\Compiler\Nodes\AreaNode;
11
use Latte\Compiler\Nodes\AuxiliaryNode;
12
use Latte\Compiler\Nodes\Html\AttributeNode;
13
use Latte\Compiler\Nodes\Html\ElementNode;
14
use Latte\Compiler\Nodes\Html\ExpressionAttributeNode;
15
use Latte\Compiler\Nodes\NopNode;
16
use Latte\Compiler\Nodes\Php\ExpressionNode;
17
use Latte\Compiler\Nodes\Php\Scalar\StringNode;
18
use Latte\Compiler\Nodes\StatementNode;
19
use Latte\Compiler\Nodes\TextNode;
20
use Latte\Compiler\PrintContext;
21
use Latte\Compiler\Tag;
22

23

24
/**
25
 * <input n:name>, <select n:name>, <textarea n:name>, <label n:name> and <button n:name>
26
 */
27
final class FieldNNameNode extends StatementNode
28
{
29
        public ExpressionNode $name;
30
        public ?ExpressionNode $part = null;
31
        public AreaNode $content;
32

33

34
        /** @return \Generator<int, ?list<string>, array{AreaNode, ?Tag}, static> */
35
        public static function create(Tag $tag): \Generator
1✔
36
        {
37
                $tag->expectArguments();
1✔
38
                $node = $tag->node = new static;
1✔
39
                $node->name = $tag->parser->parseUnquotedStringOrExpression(colon: false);
1✔
40
                if ($tag->parser->stream->tryConsume(':')) {
1✔
41
                        $node->part = $tag->parser->isEnd()
1✔
42
                                ? new StringNode('')
1✔
43
                                : $tag->parser->parseUnquotedStringOrExpression();
1✔
44
                }
45

46
                [$node->content] = yield;
1✔
47

48
                $node->init($tag);
1✔
49

50
                return $node;
1✔
51
        }
52

53

54
        public function print(PrintContext $context): string
1✔
55
        {
56
                return $this->content->print($context);
1✔
57
        }
58

59

60
        private function init(Tag $tag): void
1✔
61
        {
62
                $el = $tag->htmlElement;
1✔
63
                assert($el !== null);
64
                $usedAttributes = self::findUsedAttributes($el);
1✔
65
                $elName = strtolower($el->name);
1✔
66

67
                $tag->replaceNAttribute(new AuxiliaryNode(fn(PrintContext $context) => $context->format(
1✔
68
                        'echo ($ʟ_elem = Nette\Bridges\FormsLatte\Runtime::item(%node, $this->global)'
69
                        . ($elName === 'label' ? '->getLabelPart(%node))' : '->getControlPart(%node))')
1✔
70
                        . ($usedAttributes ? '->addAttributes(%dump)' : '')
1✔
71
                        . '->attributes() %3.line;',
1✔
72
                        $this->name,
1✔
73
                        $this->part,
1✔
74
                        array_fill_keys($usedAttributes, null),
1✔
75
                        $this->position,
1✔
76
                )));
1✔
77

78
                if ($elName === 'label') {
1✔
79
                        if ($el->content instanceof NopNode) {
1✔
80
                                $el->content = new AuxiliaryNode(fn(PrintContext $context) => $context->format(
1✔
81
                                        'echo $ʟ_elem->getHtml() %line;',
1✔
82
                                        $this->position,
1✔
83
                                ));
1✔
84
                        }
85
                } elseif ($elName === 'button') {
1✔
86
                        if ($el->content instanceof NopNode) {
1✔
87
                                $el->content = new AuxiliaryNode(fn(PrintContext $context) => $context->format(
1✔
88
                                        'echo %escape($ʟ_elem->getValue()) %line;',
1✔
89
                                        $this->position,
1✔
90
                                ));
1✔
91
                        }
92
                } elseif ($el->content) { // select, textarea
1✔
93
                        $el->content = new AuxiliaryNode(fn(PrintContext $context) => $context->format(
1✔
94
                                'echo $ʟ_elem->getHtml() %line;',
1✔
95
                                $this->position,
1✔
96
                        ));
1✔
97
                }
98
        }
1✔
99

100

101
        /**
102
         * @internal
103
         * @return string[]
104
         */
105
        public static function findUsedAttributes(ElementNode $el): array
1✔
106
        {
107
                $res = [];
1✔
108
                foreach ($el->attributes?->children as $child) {
1✔
109
                        if ($child instanceof AttributeNode && $child->name instanceof TextNode) {
1✔
110
                                $res[] = $child->name->content;
1✔
111
                        } elseif ($child instanceof ExpressionAttributeNode) {
1✔
UNCOV
112
                                $res[] = $child->name;
×
113
                        }
114
                }
115

116
                if (isset($el->nAttributes['class'])) {
1✔
117
                        $res[] = 'class';
1✔
118
                }
119
                return $res;
1✔
120
        }
121

122

123
        public function &getIterator(): \Generator
1✔
124
        {
125
                yield $this->name;
1✔
126
                if ($this->part) {
1✔
127
                        yield $this->part;
1✔
128
                }
129
                yield $this->content;
1✔
130
        }
1✔
131
}
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