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

tempestphp / tempest-framework / 14255792578

03 Apr 2025 09:07AM UTC coverage: 81.07%. First build
14255792578

push

github

web-flow
chore(view): revert boolean attribute changes (#1112)

30 of 48 new or added lines in 3 files covered. (62.5%)

11178 of 13788 relevant lines covered (81.07%)

103.41 hits per line

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

60.0
/src/Tempest/View/src/Attributes/BooleanAttribute.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\View\Attributes;
6

7
use Exception;
8
use Tempest\View\Attribute;
9
use Tempest\View\Element;
10
use Tempest\View\Elements\GenericElement;
11

12
final readonly class BooleanAttribute implements Attribute
13
{
14
    public function __construct(
1✔
15
        private string $attributeName,
16
    ) {}
1✔
17

18
    public function apply(Element $element): Element
1✔
19
    {
20
        if (! ($element instanceof GenericElement)) {
1✔
NEW
21
            throw new Exception('This cannot happen');
×
22
        }
23

24
        $element
1✔
25
            ->addRawAttribute(sprintf(
1✔
26
                '<?php if(%s) { ?>%s<?php } ?>',
1✔
27
                $element->getAttribute($this->attributeName),
1✔
28
                ltrim($this->attributeName, ':'),
1✔
29
            ))
1✔
30
            ->unsetAttribute($this->attributeName);
1✔
31

32
        return $element;
1✔
33
    }
34

35
    public static function matches(Element $element, string $attributeName): bool
75✔
36
    {
37
        if (! ($element instanceof GenericElement)) {
75✔
38
            return false;
41✔
39
        }
40

41
        if (! str_starts_with($attributeName, ':')) {
54✔
42
            return false;
43✔
43
        }
44

45
        $attributeName = ltrim($attributeName, ':');
13✔
46

47
        $allowedElements = match ($attributeName) {
13✔
NEW
48
            'autofocus' => true,
×
NEW
49
            'allowfullscreen' => ['iframe'],
×
NEW
50
            'alpha', 'checked' => ['input'],
×
NEW
51
            'async', 'nomodule', 'defer' => ['script'],
×
NEW
52
            'autoplay', 'controls', 'loop', 'muted' => ['audio', 'video'],
×
NEW
53
            'default' => ['track'],
×
NEW
54
            'disabled' => ['link', 'fieldset', 'button', 'input', 'optgroup', 'option', 'select', 'textarea;'],
×
NEW
55
            'formnovalidate' => ['button', 'input'],
×
NEW
56
            'inert', 'itemscope' => ['HTML elements'],
×
NEW
57
            'ismap' => ['img'],
×
NEW
58
            'multiple' => ['input', 'select'],
×
NEW
59
            'open' => ['dialog', 'details'],
×
NEW
60
            'playsinline' => ['video'],
×
NEW
61
            'readonly' => ['input', 'textarea'],
×
NEW
62
            'required' => ['input', 'select', 'textarea'],
×
NEW
63
            'reversed' => ['ol'],
×
64
            'selected' => ['option'],
1✔
NEW
65
            'shadowrootclonable', 'shadowrootserializable', 'shadowrootdelegatesfocus' => ['template'],
×
66
            default => null,
12✔
67
        };
13✔
68

69
        return match (true) {
13✔
70
            $allowedElements === null => false,
12✔
71
            $allowedElements === true => true,
1✔
72
            default => in_array($element->getTag(), $allowedElements, strict: true),
13✔
73
        };
13✔
74
    }
75
}
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