• 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

78.72
/src/Tempest/View/src/ViewComponentDiscovery.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\View;
6

7
use Tempest\Discovery\DiscoversPath;
8
use Tempest\Discovery\Discovery;
9
use Tempest\Discovery\DiscoveryLocation;
10
use Tempest\Discovery\IsDiscovery;
11
use Tempest\Reflection\ClassReflector;
12
use Tempest\View\Components\AnonymousViewComponent;
13

14
use function Tempest\Support\str;
15

16
final class ViewComponentDiscovery implements Discovery, DiscoversPath
17
{
18
    use IsDiscovery;
19

20
    public function __construct(
660✔
21
        private readonly ViewConfig $viewConfig,
22
    ) {}
660✔
23

UNCOV
24
    public function discover(DiscoveryLocation $location, ClassReflector $class): void
×
25
    {
UNCOV
26
        if (! $class->implements(ViewComponent::class)) {
×
27
            return;
×
28
        }
29

UNCOV
30
        $this->discoveryItems->add($location, [
×
31
            forward_static_call($class->getName() . '::getName'),
×
32
            $class->getName(),
×
33
        ]);
×
34
    }
35

36
    public function discoverPath(DiscoveryLocation $location, string $path): void
3✔
37
    {
38
        if (! str_ends_with($path, '.view.php')) {
3✔
UNCOV
39
            return;
×
40
        }
41

42
        if (! is_file($path)) {
3✔
UNCOV
43
            return;
×
44
        }
45

46
        $fileName = str(pathinfo($path, PATHINFO_FILENAME))->before('.');
3✔
47
        $contents = str(file_get_contents($path))->ltrim();
3✔
48

49
        preg_match(
3✔
50
            pattern: '/(?<header>(.|\n)*?)<x-component name="(?<name>[\w\-]+)">(?<view>(.|\n)*?)<\/x-component>/',
3✔
51
            subject: $contents->toString(),
3✔
52
            matches: $matches,
3✔
53
        );
3✔
54

55
        if ($fileName->startsWith('x-') && ! isset($matches['name'])) {
3✔
56
            $this->discoveryItems->add($location, [
1✔
57
                $fileName->toString(),
1✔
58
                new AnonymousViewComponent(
1✔
59
                    contents: $matches['view'] ?? $contents->toString(),
1✔
60
                    file: $path,
1✔
61
                ),
1✔
62
            ]);
1✔
63

64
            return;
1✔
65
        }
66

67
        if (! isset($matches['name'], $matches['header'])) {
2✔
UNCOV
68
            return;
×
69
        }
70

71
        $this->discoveryItems->add($location, [
2✔
72
            $matches['name'],
2✔
73
            new AnonymousViewComponent(
2✔
74
                contents: $matches['header'] . $matches['view'],
2✔
75
                file: $path,
2✔
76
            ),
2✔
77
        ]);
2✔
78
    }
79

80
    public function apply(): void
660✔
81
    {
82
        foreach ($this->discoveryItems as [$name, $viewComponent]) {
660✔
83
            if (is_string($viewComponent)) {
660✔
84
                $viewComponent = new ClassReflector($viewComponent);
660✔
85
            }
86

87
            $this->viewConfig->addViewComponent(
660✔
88
                name: $name,
660✔
89
                viewComponent: $viewComponent,
660✔
90
            );
660✔
91
        }
92
    }
93
}
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