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

nepada / form-renderer / 10957480930

02 Sep 2024 06:49PM UTC coverage: 97.561%. Remained the same
10957480930

push

github

web-flow
Bump the phpstan group with 3 updates (#161)

360 of 369 relevant lines covered (97.56%)

0.98 hits per line

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

91.67
/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 Nepada\FormRenderer\Helpers;
12

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

20
    public ArrayNode $args;
21

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

31
        $tag->expectArguments();
1✔
32
        $node = new self();
1✔
33
        $node->args = $tag->parser->parseArguments();
1✔
34
        return $node;
1✔
35
    }
36

37
    public function print(PrintContext $context): string
38
    {
39
        $classListCode = '$ʟ_tmp = array_filter(array_merge(...array_map([\'' . Helpers::class . '\', \'parseClassList\'], %node)))';
1✔
40
        $code = 'if (' . $classListCode . ') echo \' class="\', LR\Filters::escapeHtmlAttr(implode(\' \', array_unique($ʟ_tmp))), \'"\' %line;';
1✔
41

42
        return $context->format($code, $this->args, $this->position);
1✔
43
    }
44

45
    public function &getIterator(): \Generator
1✔
46
    {
47
        yield $this->args;
1✔
48
    }
1✔
49

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