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

nepada / form-renderer / 4853036368

pending completion
4853036368

push

github

GitHub
Update phpstan/phpstan requirement from 1.10.10 to 1.10.14

247 of 265 relevant lines covered (93.21%)

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

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

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

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

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

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