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

tempestphp / tempest-framework / 14703585423

28 Apr 2025 08:26AM UTC coverage: 80.282% (+0.03%) from 80.248%
14703585423

Pull #1171

github

web-flow
Merge db3be45e4 into 22dbe0737
Pull Request #1171: fix(view): dynamic components with slots

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

1 existing line in 1 file now uncovered.

11860 of 14773 relevant lines covered (80.28%)

106.8 hits per line

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

94.44
/src/Tempest/View/src/Components/DynamicViewComponent.php
1
<?php
2

3
namespace Tempest\View\Components;
4

5
use Stringable;
6
use Tempest\Core\AppConfig;
7
use Tempest\Support\Str\ImmutableString;
8
use Tempest\View\Elements\CollectionElement;
9
use Tempest\View\Elements\ViewComponentElement;
10
use Tempest\View\Parser\TempestViewCompiler;
11
use Tempest\View\Parser\Token;
12
use Tempest\View\ViewComponent;
13
use Tempest\View\ViewConfig;
14

15
use function Tempest\Support\arr;
16

17
final class DynamicViewComponent implements ViewComponent
18
{
19
    private Token $token;
20

21
    public function __construct()
4✔
22
    {
23
    }
4✔
24

25
    public function setToken(Token $token): void
4✔
26
    {
27
        $this->token = $token;
4✔
28
    }
29

30
    public static function getName(): string
×
31
    {
UNCOV
32
        return 'x-dynamic-component';
×
33
    }
34

35
    public function compile(ViewComponentElement $element): string
4✔
36
    {
37
        $name = $this->token->getAttribute('is') ?? $this->token->getAttribute(':is');
4✔
38

39
        $isExpression = $this->token->getAttribute(':is') !== null;
4✔
40

41
        $collectionElement = new CollectionElement($element->getChildren());
4✔
42

43
        $attributes = arr($element->getAttributes())
4✔
44
            ->filter(fn (string $_value, string $key) => $key !== 'is' && $key !== ':is')
4✔
45
            ->map(function (string $value, string $key) {
4✔
46
                return sprintf('%s="%s"', $key, trim($value));
3✔
47
            })
4✔
48
            ->implode(' ')
4✔
49
            ->when(
4✔
50
                fn (Stringable $string) => ((string) $string) !== '',
4✔
51
                fn (Stringable $string) => new ImmutableString(" {$string}"),
4✔
52
            );
4✔
53

54
        $compiledChildren = sprintf(
4✔
55
            <<<'HTML'
4✔
56
            <%s%s>
57
            %s
58
            </%s>
59
            HTML,
4✔
60
            '%s',
4✔
61
            $attributes,
4✔
62
            $collectionElement->compile(),
4✔
63
            '%s',
4✔
64
        );
4✔
65

66
        return sprintf(
4✔
67
            '<?php 
4✔
68
$vars = get_defined_vars();
69
unset($vars[\'_view\'], $vars[\'_path\'], $vars[\'_data\'], $vars[\'_propIsLocal\'], $vars[\'_isIsLocal\'], $vars[\'_previousAttributes\'], $vars[\'_previousSlots\'], $vars[\'slots\']);
70

71
echo \Tempest\get(' . \Tempest\View\Renderers\TempestViewRenderer::class . '::class)->render(\Tempest\view(sprintf(<<<\'HTML\'
4✔
72
%s
73
HTML, %s, %s), ...$vars)); ?>
74
',
4✔
75
            $compiledChildren,
4✔
76
            $isExpression ? $name : "'{$name}'",
4✔
77
            $isExpression ? $name : "'{$name}'",
4✔
78
        );
4✔
79
    }
80
}
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