• 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

94.12
/src/Tempest/View/src/Attributes/ExpressionAttribute.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\View\Attributes;
6

7
use Stringable;
8
use Tempest\Support\Arr\ArrayInterface;
9
use Tempest\View\Attribute;
10
use Tempest\View\Element;
11
use Tempest\View\Elements\PhpDataElement;
12
use Tempest\View\Exceptions\InvalidExpressionAttribute;
13
use Tempest\View\Renderers\TempestViewCompiler;
14

15
use function Tempest\Support\str;
16

17
final readonly class ExpressionAttribute implements Attribute
18
{
19
    public function __construct(
25✔
20
        private string $name,
21
    ) {
22
    }
25✔
23

24
    public function apply(Element $element): Element
25✔
25
    {
26
        $value = str($element->getAttribute($this->name));
25✔
27

28
        if ($value->startsWith(['{{', '{!!', ...TempestViewCompiler::TOKEN_MAPPING])) {
25✔
29
            throw new InvalidExpressionAttribute($value);
4✔
30
        }
31

32
        if ($this->name === ':class' || $this->name === ':style') {
21✔
33
            $value = self::resolveValue([
1✔
34
                $element->getAttribute(ltrim($this->name, ':')),
1✔
35
                sprintf('<?= %s ?>', $element->getAttribute($this->name)),
1✔
36
            ]);
1✔
37

38
            $element->setAttribute(
1✔
39
                ltrim($this->name, ':'),
1✔
40
                sprintf('%s', $value),
1✔
41
            );
1✔
42
        } else {
43
            $element->setAttribute(
20✔
44
                ltrim($this->name, ':'),
20✔
45
                sprintf('<?= ' . \Tempest\View\Attributes\ExpressionAttribute::class . '::resolveValue(%s) ?>', $value),
20✔
46
            );
20✔
47

48
            $element = new PhpDataElement(
20✔
49
                name: $this->name,
20✔
50
                value: $value->toString(),
20✔
51
                wrappingElement: $element,
20✔
52
            );
20✔
53
        }
54

55
        $element->unsetAttribute($this->name);
21✔
56

57
        return $element;
21✔
58
    }
59

60
    public static function resolveValue(mixed $value): string
11✔
61
    {
62
        if ($value instanceof Stringable) {
11✔
UNCOV
63
            $value = (string) $value;
×
64
        }
65

66
        if ($value instanceof ArrayInterface) {
11✔
UNCOV
67
            $value = $value->toArray();
×
68
        }
69

70
        if (is_array($value)) {
11✔
71
            $value = trim(implode(' ', $value));
2✔
72
        }
73

74
        return (string) $value;
11✔
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