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

tempestphp / tempest-framework / 14322727335

07 Apr 2025 03:10PM UTC coverage: 81.259% (+0.4%) from 80.906%
14322727335

push

github

web-flow
fix(support): non-dev bun dependencies installation (#1124)

0 of 12 new or added lines in 1 file covered. (0.0%)

25 existing lines in 6 files now uncovered.

11434 of 14071 relevant lines covered (81.26%)

105.02 hits per line

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

98.72
/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\Element;
11
use Tempest\View\Parser\TempestViewCompiler;
12
use Tempest\View\Parser\Token;
13
use Tempest\View\Parser\TokenType;
14
use Tempest\View\ViewComponent;
15
use Tempest\View\ViewConfig;
16

17
use function Tempest\Support\str;
18

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

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

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

33
        return $this;
121✔
34
    }
35

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

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

55
        if ($token->type === TokenType::CONTENT) {
122✔
56
            $text = $token->compile();
97✔
57

58
            if (trim($text) === '') {
97✔
59
                return null;
59✔
60
            }
61

62
            return new TextElement(text: $text);
74✔
63
        }
64

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

69
        $attributes = [];
113✔
70

71
        foreach ($token->htmlAttributes as $name => $value) {
113✔
72
            $name = str($name)
98✔
73
                ->trim()
98✔
74
                ->before('=')
98✔
75
                ->camel()
98✔
76
                ->toString();
98✔
77

78
            $value = str($value)
98✔
79
                ->afterFirst('"')
98✔
80
                ->beforeLast('"')
98✔
81
                ->toString();
98✔
82

83
            $attributes[$name] = $value;
98✔
84
        }
85

86
        foreach ($token->phpAttributes as $index => $content) {
113✔
87
            $attributes[] = new PhpAttribute((string) $index, $content);
1✔
88
        }
89

90
        if ($token->tag === 'code' || $token->tag === 'pre') {
113✔
91
            return new RawElement(
2✔
92
                tag: $token->tag,
2✔
93
                content: $token->compileChildren(),
2✔
94
                attributes: $attributes,
2✔
95
            );
2✔
96
        }
97

98
        if ($viewComponentClass = $this->viewConfig->viewComponents[$token->tag] ?? null) {
112✔
99
            if (! ($viewComponentClass instanceof ViewComponent)) {
71✔
100
                $viewComponentClass = $this->container->get($viewComponentClass);
28✔
101
            }
102

103
            $element = new ViewComponentElement(
71✔
104
                environment: $this->appConfig->environment,
71✔
105
                compiler: $this->compiler,
71✔
106
                viewComponent: $viewComponentClass,
71✔
107
                attributes: $attributes,
71✔
108
            );
71✔
109
        } elseif ($token->tag === 'x-template') {
103✔
110
            $element = new TemplateElement(
1✔
111
                attributes: $attributes,
1✔
112
            );
1✔
113
        } elseif ($token->tag === 'x-slot') {
103✔
114
            $element = new SlotElement(
6✔
115
                name: $token->getAttribute('name') ?? 'slot',
6✔
116
                attributes: $attributes,
6✔
117
            );
6✔
118
        } else {
119
            $element = new GenericElement(
102✔
120
                tag: $token->tag,
102✔
121
                attributes: $attributes,
102✔
122
            );
102✔
123
        }
124

125
        $children = [];
112✔
126

127
        foreach ($token->children as $child) {
112✔
128
            $childElement = $this->clone()->makeElement(
78✔
129
                token: $child,
78✔
130
                parent: $parent,
78✔
131
            );
78✔
132

133
            if ($childElement === null) {
78✔
134
                continue;
38✔
135
            }
136

137
            $children[] = $childElement;
78✔
138
        }
139

140
        $element->setChildren($children);
112✔
141

142
        return $element;
112✔
143
    }
144

145
    private function clone(): self
78✔
146
    {
147
        return clone $this;
78✔
148
    }
149
}
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

© 2025 Coveralls, Inc