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

nepada / form-renderer / 19613572817

23 Nov 2025 03:43PM UTC coverage: 97.568%. Remained the same
19613572817

push

github

xificurk
Update deps for PHP 8.5

361 of 370 relevant lines covered (97.57%)

0.98 hits per line

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

92.31
/src/FormRenderer/LatteExtensions/Nodes/NClassNode.php
1
<?php
2
declare(strict_types = 1);
3

4
namespace Nepada\FormRenderer\LatteExtensions\Nodes;
5

6
use Latte\CompileException;
7
use Latte\Compiler\Nodes\Php\Expression\ArrayNode;
8
use Latte\Compiler\Nodes\StatementNode;
9
use Latte\Compiler\PrintContext;
10
use Latte\Compiler\Tag;
11
use Latte\Runtime\HtmlHelpers;
12
use Nepada\FormRenderer\Helpers;
13
use function class_exists;
14
use function is_callable;
15

16
/**
17
 * Improved version of `n:class="..."` that supports array arguments, e.g. `n:class="firstClass, $condition ? [foo => true, bar => true], anotherClass"`.
18
 * This is especially useful in combination with instances of Nette\Utils\Html, so you can do stuff like `n:class="foo, $el->class"`.
19
 */
20
final class NClassNode extends StatementNode
21
{
22

23
    public ArrayNode $args;
24

25
    /**
26
     * @throws CompileException
27
     */
28
    public static function create(Tag $tag): self
29
    {
30
        if ($tag->htmlElement?->getAttribute('class') !== null) {
1✔
31
            throw new CompileException('It is not possible to combine class with n:class.', $tag->position);
×
32
        }
33

34
        $tag->expectArguments();
1✔
35
        $node = new self();
1✔
36
        $node->args = $tag->parser->parseArguments();
1✔
37
        return $node;
1✔
38
    }
39

40
    public function print(PrintContext $context): string
41
    {
42
        $classListCode = '$ʟ_tmp = array_filter(array_merge(...array_map([\'' . Helpers::class . '\', \'parseClassList\'], %node)))';
1✔
43
        $escaper = class_exists(HtmlHelpers::class) && is_callable([HtmlHelpers::class, 'escapeAttr']) ? 'HtmlHelpers::escapeAttr' : 'Filters::escapeHtmlAttr'; // Latte <3.1 compatibility
1✔
44
        $code = 'if (' . $classListCode . ') echo \' class="\', LR\\' . $escaper . '(implode(\' \', array_unique($ʟ_tmp))), \'"\' %line;';
1✔
45

46
        return $context->format($code, $this->args, $this->position);
1✔
47
    }
48

49
    public function &getIterator(): \Generator
1✔
50
    {
51
        yield $this->args;
1✔
52
    }
1✔
53

54
}
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

© 2025 Coveralls, Inc