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

tempestphp / tempest-framework / 14049246919

24 Mar 2025 09:42PM UTC coverage: 79.353% (-0.04%) from 79.391%
14049246919

push

github

web-flow
feat(support): support array parameters in string manipulations (#1073)

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

735 existing lines in 126 files now uncovered.

10492 of 13222 relevant lines covered (79.35%)

90.78 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
    ) {}
25✔
22

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

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

31
        if ($this->name === ':class' || $this->name === ':style') {
21✔
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(
20✔
43
                ltrim($this->name, ':'),
20✔
44
                sprintf('<?= ' . \Tempest\View\Attributes\ExpressionAttribute::class . '::resolveValue(%s) ?>', $value),
20✔
45
            );
20✔
46

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

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

56
        return $element;
21✔
57
    }
58

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

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

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

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