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

NeoIsRecursive / inertia-tempest / 18051215324

26 Sep 2025 10:59PM UTC coverage: 98.558% (-0.5%) from 99.034%
18051215324

push

github

NeoIsRecursive
refactor!: tighten types, use tempest json\encode and update mago to
1.0.0-beta.24

12 of 14 new or added lines in 3 files covered. (85.71%)

205 of 208 relevant lines covered (98.56%)

14.73 hits per line

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

97.78
/src/Inertia.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace NeoIsRecursive\Inertia;
6

7
use Exception;
8
use NeoIsRecursive\Inertia\Http\InertiaResponse;
9
use NeoIsRecursive\Inertia\InertiaConfig;
10
use NeoIsRecursive\Inertia\Support\Header;
11
use Tempest\Container\Container;
12
use Tempest\Container\Singleton;
13
use Tempest\Http\GenericResponse;
14
use Tempest\Http\Request;
15
use Tempest\Http\Response;
16
use Tempest\Http\Responses\Redirect;
17
use Tempest\Http\Session\Session;
18
use Tempest\Http\Status;
19

20
#[Singleton]
21
final class Inertia
22
{
23
    public function __construct(
24
        private Session $session,
25
        private Container $container,
26
        private InertiaConfig $config,
27
    ) {}
23✔
28

29
    /**
30
     * @param string|array<string, mixed> $key
31
     */
32
    public function share(string|array $key, mixed $value = null): self
33
    {
34
        $this->config->share($key, $value);
4✔
35

36
        return $this;
4✔
37
    }
38

39
    public function flushShared(): self
40
    {
41
        $this->config->flushSharedProps();
1✔
42

43
        return $this;
1✔
44
    }
45

46
    public string $version {
47
        get => $this->container->invoke($this->config->versionResolver->resolve(...));
48
    }
49

50
    /**
51
     * @param array<string, mixed> $props
52
     * @mago-expect analyzer:unhandled-thrown-type
53
     */
54
    public function render(string $component, array $props = []): InertiaResponse
55
    {
56
        $request = $this->container->get(Request::class);
9✔
57

58
        if (!$request) {
9✔
NEW
59
            throw new Exception('No request');
×
60
        }
61

62
        return new InertiaResponse(
9✔
63
            request: $request,
9✔
64
            component: $component,
9✔
65
            props: array_merge($this->config->sharedProps, $props),
9✔
66
            rootView: $this->config->rootView,
9✔
67
            version: $this->version,
9✔
68
            clearHistory: $this->session->get(
9✔
69
                key: 'inertia.clear_history',
9✔
70
                default: false,
9✔
71
            ),
9✔
72
            encryptHistory: $this->session->get(
9✔
73
                key: 'inertia.encrypt_history',
9✔
74
                default: false,
9✔
75
            ),
9✔
76
        );
9✔
77
    }
78

79
    public function encryptHistory(): self
80
    {
81
        $this->session->flash(
2✔
82
            key: 'inertia.encrypt_history',
2✔
83
            value: true,
2✔
84
        );
2✔
85

86
        return $this;
2✔
87
    }
88

89
    public function clearHistory(): self
90
    {
91
        $this->session->flash(
2✔
92
            key: 'inertia.clear_history',
2✔
93
            value: true,
2✔
94
        );
2✔
95

96
        return $this;
2✔
97
    }
98

99
    public function location(string|Redirect $url): Response
100
    {
101
        /** @var bool */
102
        $isInertiaRequest = $this->container->get(Request::class)?->headers?->has(Header::INERTIA) ?? false;
7✔
103

104
        if ($isInertiaRequest) {
7✔
105
            if ($url instanceof Redirect) {
3✔
106
                /** @var string */
107
                $url = $url->getHeader(name: 'Location')->values[0] ?? '/';
1✔
108
            }
109

110
            return new GenericResponse(
3✔
111
                status: Status::CONFLICT,
3✔
112
                body: '',
3✔
113
                headers: [
3✔
114
                    Header::LOCATION => $url,
3✔
115
                ],
3✔
116
            );
3✔
117
        }
118

119
        return $url instanceof Redirect ? $url : new Redirect($url);
4✔
120
    }
121
}
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