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

tempestphp / tempest-framework / 14024978163

23 Mar 2025 05:55PM UTC coverage: 79.391% (-0.05%) from 79.441%
14024978163

push

github

web-flow
feat(view): cache Blade and Twig templates in internal storage (#1061)

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

912 existing lines in 110 files now uncovered.

10478 of 13198 relevant lines covered (79.39%)

91.09 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
    ) {
17
    }
1✔
18

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

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

33
        return $element;
1✔
34
    }
35

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

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

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

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

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