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

tempestphp / tempest-framework / 14279044006

05 Apr 2025 05:59AM UTC coverage: 81.139% (+0.2%) from 80.906%
14279044006

Pull #1115

github

web-flow
Merge f5e63ae2b into 90e820853
Pull Request #1115: refactor(view): implement custom html parser

275 of 292 new or added lines in 13 files covered. (94.18%)

10 existing lines in 5 files now uncovered.

11344 of 13981 relevant lines covered (81.14%)

104.8 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(
34✔
20
        private string $name,
21
    ) {}
34✔
22

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

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

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

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

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

54
        $element->unsetAttribute($this->name);
30✔
55

56
        return $element;
30✔
57
    }
58

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

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

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

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