• 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

71.43
/src/Tempest/Router/src/Static/StaticGenerateCommand.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Router\Static;
6

7
use Tempest\Console\Console;
8
use Tempest\Console\ConsoleCommand;
9
use Tempest\Console\HasConsole;
10
use Tempest\Container\Container;
11
use Tempest\Core\Kernel;
12
use Tempest\Http\Method;
13
use Tempest\Http\Status;
14
use Tempest\Router\DataProvider;
15
use Tempest\Router\GenericRequest;
16
use Tempest\Router\Router;
17
use Tempest\View\View;
18
use Tempest\View\ViewRenderer;
19
use Throwable;
20

21
use function Tempest\Support\path;
22
use function Tempest\uri;
23

24
final readonly class StaticGenerateCommand
25
{
26
    use HasConsole;
27

28
    public function __construct(
2✔
29
        private Console $console,
30
        private Kernel $kernel,
31
        private Container $container,
32
        private StaticPageConfig $staticPageConfig,
33
        private Router $router,
34
        private ViewRenderer $viewRenderer,
35
    ) {}
2✔
36

37
    #[ConsoleCommand(
2✔
38
        name: 'static:generate',
39
        description: 'Compiles static pages',
40
    )]
41
    public function __invoke(?string $filter = null): void
42
    {
43
        $publicPath = path($this->kernel->root, 'public');
2✔
44

45
        foreach ($this->staticPageConfig->staticPages as $staticPage) {
2✔
46
            /** @var DataProvider $dataProvider */
47
            $dataProvider = $this->container->get($staticPage->dataProviderClass ?? GenericDataProvider::class);
2✔
48

49
            foreach ($dataProvider->provide() as $params) {
2✔
50
                if (! is_array($params)) {
2✔
UNCOV
51
                    $params = [$params];
×
52
                }
53

54
                $uri = parse_url(uri($staticPage->handler, ...$params), PHP_URL_PATH);
2✔
55

56
                $fileName = $uri === '/'
2✔
UNCOV
57
                    ? 'index.html'
×
58
                    : ($uri . '/index.html');
2✔
59

60
                if ($filter !== null && $uri !== $filter) {
2✔
UNCOV
61
                    continue;
×
62
                }
63

64
                $file = path($publicPath, $fileName);
2✔
65

66
                try {
67
                    $response = $this->router->dispatch(
2✔
68
                        new GenericRequest(
2✔
69
                            method: Method::GET,
2✔
70
                            uri: $uri,
2✔
71
                        ),
2✔
72
                    );
2✔
73

74
                    if ($response->status !== Status::OK) {
2✔
UNCOV
75
                        $this->writeln("- <error>{$uri}</error> > {$response->status->value}");
×
76

UNCOV
77
                        continue;
×
78
                    }
79

80
                    $body = $response->body;
2✔
81

82
                    $content = ($body instanceof View)
2✔
83
                        ? $this->viewRenderer->render($body)
2✔
UNCOV
84
                        : $body;
×
85

86
                    if (! is_string($content)) {
2✔
UNCOV
87
                        $this->error("<u>{$uri}</u> No textual body");
×
88

UNCOV
89
                        continue;
×
90
                    }
91

92
                    $directory = $file->dirname();
2✔
93

94
                    if (! is_dir($directory)) {
2✔
95
                        mkdir($directory, recursive: true);
2✔
96
                    }
97

98
                    file_put_contents($file->path(), $content);
2✔
99

100
                    $this->writeln("- <em>{$uri}</em> > <u>{$file}</u>");
2✔
UNCOV
101
                } catch (Throwable $e) {
×
102
                    $this->error("<u>{$uri}</u> {$e->getMessage()}");
×
103

UNCOV
104
                    ob_get_clean();
×
105

UNCOV
106
                    continue;
×
107
                }
108
            }
109
        }
110

111
        $this->success('Done');
2✔
112
    }
113
}
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