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

tempestphp / tempest-framework / 14239242351

03 Apr 2025 09:08AM UTC coverage: 81.144% (+0.07%) from 81.07%
14239242351

Pull #1113

github

web-flow
Merge 47a013561 into b96e68dbd
Pull Request #1113: feat(view): improve boolean attributes

52 of 52 new or added lines in 8 files covered. (100.0%)

9 existing lines in 2 files now uncovered.

11163 of 13757 relevant lines covered (81.14%)

104.65 hits per line

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

89.29
/src/Tempest/View/src/Elements/GenericElement.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\View\Elements;
6

7
use Tempest\View\Element;
8

9
use function Tempest\Support\Html\is_void_tag;
10
use function Tempest\Support\str;
11

12
final class GenericElement implements Element
13
{
14
    use IsElement;
15

16
    private array $rawAttributes = [];
17

18
    public function __construct(
101✔
19
        private readonly string $tag,
20
        array $attributes,
21
    ) {
22
        $this->attributes = $attributes;
101✔
23
    }
24

UNCOV
25
    public function getTag(): string
×
26
    {
UNCOV
27
        return $this->tag;
×
28
    }
29

30
    public function addRawAttribute(string $attribute): self
16✔
31
    {
32
        $this->rawAttributes[] = $attribute;
16✔
33

34
        return $this;
16✔
35
    }
36

37
    public function compile(): string
95✔
38
    {
39
        $content = [];
95✔
40

41
        foreach ($this->getChildren() as $child) {
95✔
42
            $content[] = $child->compile();
70✔
43
        }
44

45
        $content = implode('', $content);
95✔
46

47
        $attributes = [];
95✔
48

49
        foreach ($this->getAttributes() as $name => $value) {
95✔
50
            $name = str($name);
43✔
51

52
            if ($name->startsWith(':')) {
43✔
53
                $name = ':' . $name->kebab()->toString();
×
54
            } else {
55
                $name = $name->kebab()->toString();
43✔
56
            }
57

58
            if ($value) {
43✔
59
                $attributes[] = $name . '="' . $value . '"';
43✔
60
            } else {
61
                $attributes[] = $name;
2✔
62
            }
63
        }
64

65
        $attributes = implode(' ', [...$attributes, ...$this->rawAttributes]);
95✔
66

67
        if ($attributes !== '') {
95✔
68
            $attributes = ' ' . $attributes;
58✔
69
            $attributes = str_replace('?> <?php', '?><?php', $attributes);
58✔
70
        }
71

72
        // Void elements
73
        if (is_void_tag($this->tag)) {
95✔
74
            return "<{$this->tag}{$attributes}>";
8✔
75
        }
76

77
        return "<{$this->tag}{$attributes}>{$content}</{$this->tag}>";
95✔
78
    }
79
}
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