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

tempestphp / tempest-framework / 14703553131

28 Apr 2025 08:25AM UTC coverage: 80.283% (+0.06%) from 80.219%
14703553131

Pull #1171

github

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

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

2 existing lines in 1 file now uncovered.

11861 of 14774 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
use function Tempest\Support\arr;
15

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

20
    public function __construct(
4✔
21
        private AppConfig $appConfig,
22
        private TempestViewCompiler $compiler,
23
        private ViewConfig $viewConfig,
24
    ) {}
4✔
25

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

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

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

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

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

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

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

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

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

81
        return $compiled;
4✔
82
    }
83
}
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