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

tempestphp / tempest-framework / 14654722276

24 Apr 2025 07:39PM UTC coverage: 80.219% (+0.03%) from 80.194%
14654722276

push

github

web-flow
fix(view): wrong matched imports in view component slots (#1173)

Co-authored-by: brendt <brent.roose@gmail.com>

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

2 existing lines in 2 files now uncovered.

11785 of 14691 relevant lines covered (80.22%)

106.33 hits per line

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

98.57
/src/Tempest/View/src/Elements/ElementFactory.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\View\Elements;
6

7
use Tempest\Container\Container;
8
use Tempest\Core\AppConfig;
9
use Tempest\View\Attributes\PhpAttribute;
10
use Tempest\View\Components\DynamicViewComponent;
11
use Tempest\View\Element;
12
use Tempest\View\Parser\TempestViewCompiler;
13
use Tempest\View\Parser\Token;
14
use Tempest\View\Parser\TokenType;
15
use Tempest\View\ViewComponent;
16
use Tempest\View\ViewConfig;
17

18
use function Tempest\Support\str;
19

20
final class ElementFactory
21
{
22
    private TempestViewCompiler $compiler;
23

24
    public function __construct(
144✔
25
        private readonly AppConfig $appConfig,
26
        private readonly ViewConfig $viewConfig,
27
        private readonly Container $container,
28
    ) {}
144✔
29

30
    public function setViewCompiler(TempestViewCompiler $compiler): self
137✔
31
    {
32
        $this->compiler = $compiler;
137✔
33

34
        return $this;
137✔
35
    }
36

37
    public function make(Token $token): ?Element
138✔
38
    {
39
        return $this->makeElement(
138✔
40
            token: $token,
138✔
41
            parent: null,
138✔
42
        );
138✔
43
    }
44

45
    private function makeElement(Token $token, ?Element $parent): ?Element
138✔
46
    {
47
        if (
48
            $token->type === TokenType::OPEN_TAG_END ||
138✔
49
                $token->type === TokenType::ATTRIBUTE_NAME ||
138✔
50
                $token->type === TokenType::ATTRIBUTE_VALUE ||
138✔
51
                $token->type === TokenType::SELF_CLOSING_TAG_END
138✔
52
        ) {
UNCOV
53
            return null;
×
54
        }
55

56
        if ($token->type === TokenType::CONTENT) {
138✔
57
            $text = $token->compile();
119✔
58

59
            if (trim($text) === '') {
119✔
60
                return null;
67✔
61
            }
62

63
            return new TextElement(text: $text);
96✔
64
        }
65

66
        if (! $token->tag || $token->type === TokenType::COMMENT || $token->type === TokenType::PHP) {
130✔
67
            return new RawElement(tag: null, content: $token->compile());
86✔
68
        }
69

70
        $attributes = $token->htmlAttributes;
129✔
71

72
        foreach ($token->phpAttributes as $index => $content) {
129✔
73
            $attributes[] = new PhpAttribute((string) $index, $content);
1✔
74
        }
75

76
        if ($token->tag === 'code' || $token->tag === 'pre') {
129✔
77
            return new RawElement(
2✔
78
                tag: $token->tag,
2✔
79
                content: $token->compileChildren(),
2✔
80
                attributes: $attributes,
2✔
81
            );
2✔
82
        }
83

84
        if ($viewComponentClass = $this->viewConfig->viewComponents[$token->tag] ?? null) {
128✔
85
            if ($token->getAttribute('is') || $token->getAttribute(':is')) {
83✔
86
                $viewComponentClass = $this->container->get(DynamicViewComponent::class);
3✔
87
                $viewComponentClass->setToken($token);
3✔
88
            }
89

90
            if (! ($viewComponentClass instanceof ViewComponent)) {
83✔
91
                $viewComponentClass = $this->container->get($viewComponentClass);
21✔
92
            }
93

94
            $element = new ViewComponentElement(
83✔
95
                environment: $this->appConfig->environment,
83✔
96
                compiler: $this->compiler,
83✔
97
                viewComponent: $viewComponentClass,
83✔
98
                attributes: $attributes,
83✔
99
            );
83✔
100
        } elseif ($token->tag === 'x-template') {
113✔
101
            $element = new TemplateElement(
1✔
102
                attributes: $attributes,
1✔
103
            );
1✔
104
        } elseif ($token->tag === 'x-slot') {
113✔
105
            $element = new SlotElement(
10✔
106
                name: $token->getAttribute('name') ?? 'slot',
10✔
107
                attributes: $attributes,
10✔
108
            );
10✔
109
        } else {
110
            $element = new GenericElement(
112✔
111
                tag: $token->tag,
112✔
112
                attributes: $attributes,
112✔
113
            );
112✔
114
        }
115

116
        $children = [];
128✔
117

118
        foreach ($token->children as $child) {
128✔
119
            $childElement = $this->clone()->makeElement(
92✔
120
                token: $child,
92✔
121
                parent: $parent,
92✔
122
            );
92✔
123

124
            if ($childElement === null) {
92✔
125
                continue;
43✔
126
            }
127

128
            $children[] = $childElement;
92✔
129
        }
130

131
        $element->setChildren($children);
128✔
132

133
        return $element;
128✔
134
    }
135

136
    private function clone(): self
92✔
137
    {
138
        return clone $this;
92✔
139
    }
140
}
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