• 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

90.91
/src/Latte/Essential/Nodes/NTagNode.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\Essential\Nodes;
11

12
use Latte;
13
use Latte\CompileException;
14
use Latte\Compiler\Nodes\Php\Expression\AuxiliaryNode;
15
use Latte\Compiler\Nodes\StatementNode;
16
use Latte\Compiler\PrintContext;
17
use Latte\Compiler\Tag;
18
use Latte\Compiler\TemplateParser;
19
use Latte\ContentType;
20
use function is_string, preg_match, strtolower;
21

22

23
/**
24
 * n:tag="..."
25
 */
26
final class NTagNode extends StatementNode
27
{
28
        public static function create(Tag $tag, TemplateParser $parser): void
1✔
29
        {
30
                if (preg_match('(style$|script$)iA', $tag->htmlElement->name)) {
1✔
31
                        throw new CompileException('Attribute n:tag is not allowed in <script> or <style>', $tag->position);
1✔
32
                }
33

34
                $tag->expectArguments();
1✔
35
                $tag->htmlElement->variableName = new AuxiliaryNode(
1✔
36
                        fn(PrintContext $context, $newName) => $context->format(
1✔
37
                                self::class . '::check(%dump, %node, %dump)',
1✔
38
                                $tag->htmlElement->name,
1✔
39
                                $newName,
40
                                $parser->getContentType() === ContentType::Xml,
1✔
41
                        ),
1✔
42
                        [$tag->parser->parseExpression()],
1✔
43
                );
44
        }
1✔
45

46

47
        public function print(PrintContext $context): string
48
        {
UNCOV
49
                throw new \LogicException('Cannot directly print');
×
50
        }
51

52

53
        public static function check(string $orig, mixed $new, bool $xml): mixed
1✔
54
        {
55
                if ($new === null) {
1✔
56
                        return $orig;
1✔
57
                } elseif (!$xml
1✔
58
                        && is_string($new)
1✔
59
                        && isset(Latte\Helpers::$emptyElements[strtolower($orig)]) !== isset(Latte\Helpers::$emptyElements[strtolower($new)])
1✔
60
                ) {
61
                        throw new Latte\RuntimeException("Forbidden tag <$orig> change to <$new>");
1✔
62
                }
63

64
                return $new;
1✔
65
        }
66

67

UNCOV
68
        public function &getIterator(): \Generator
×
69
        {
70
                false && yield;
71
        }
72
}
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