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

NeoIsRecursive / inertia-tempest / 18051850189

26 Sep 2025 11:43PM UTC coverage: 97.642% (-1.4%) from 99.029%
18051850189

push

github

NeoIsRecursive
fix!: rename `LazyProp` to `OptionalProp` and add static helpers

4 of 7 new or added lines in 2 files covered. (57.14%)

207 of 212 relevant lines covered (97.64%)

14.69 hits per line

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

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

3
declare(strict_types=1);
4

5
namespace NeoIsRecursive\Inertia;
6

7
use Closure;
8
use NeoIsRecursive\Inertia\Http\InertiaResponse;
9
use NeoIsRecursive\Inertia\InertiaConfig;
10
use NeoIsRecursive\Inertia\Props\AlwaysProp;
11
use NeoIsRecursive\Inertia\Props\DeferProp;
12
use NeoIsRecursive\Inertia\Props\OptionalProp;
13
use NeoIsRecursive\Inertia\Support\Header;
14
use Tempest\Container\Container;
15
use Tempest\Container\Singleton;
16
use Tempest\Http\GenericResponse;
17
use Tempest\Http\Request;
18
use Tempest\Http\Response;
19
use Tempest\Http\Responses\Redirect;
20
use Tempest\Http\Session\Session;
21
use Tempest\Http\Status;
22
use Tempest\Reflection\FunctionReflector;
23
use Tempest\Reflection\MethodReflector;
24

25
#[Singleton]
26
final class Inertia
27
{
28
    public function __construct(
29
        private Session $session,
30
        private Container $container,
31
        private InertiaConfig $config,
32
    ) {}
23✔
33

34
    /**
35
     * @param string|array<string, mixed> $key
36
     */
37
    public function share(string|array $key, mixed $value = null): self
38
    {
39
        $this->config->share($key, $value);
4✔
40

41
        return $this;
4✔
42
    }
43

44
    public static function optional(MethodReflector|FunctionReflector|Closure $callback): OptionalProp
45
    {
NEW
46
        return new OptionalProp($callback);
×
47
    }
48

49
    public static function defer(MethodReflector|FunctionReflector|Closure $callback): DeferProp
50
    {
NEW
51
        return new DeferProp($callback);
×
52
    }
53

54
    public static function always(mixed $value): AlwaysProp
55
    {
NEW
56
        return new AlwaysProp($value);
×
57
    }
58

59
    public function flushShared(): self
60
    {
61
        $this->config->flushSharedProps();
1✔
62

63
        return $this;
1✔
64
    }
65

66
    public string $version {
67
        get => $this->container->invoke($this->config->versionResolver->resolve(...));
68
    }
69

70
    /**
71
     * @param array<string, mixed> $props
72
     */
73
    public function render(string $component, array $props = []): InertiaResponse
74
    {
75
        /** @var Request */
76
        $request = $this->container->get(Request::class);
9✔
77

78
        return new InertiaResponse(
9✔
79
            request: $request,
9✔
80
            component: $component,
9✔
81
            props: array_merge($this->config->sharedProps, $props),
9✔
82
            rootView: $this->config->rootView,
9✔
83
            version: $this->version,
9✔
84
            clearHistory: $this->session->get(
9✔
85
                key: 'inertia.clear_history',
9✔
86
                default: false,
9✔
87
            ),
9✔
88
            encryptHistory: $this->session->get(
9✔
89
                key: 'inertia.encrypt_history',
9✔
90
                default: false,
9✔
91
            ),
9✔
92
        );
9✔
93
    }
94

95
    public function encryptHistory(): self
96
    {
97
        $this->session->flash(
2✔
98
            key: 'inertia.encrypt_history',
2✔
99
            value: true,
2✔
100
        );
2✔
101

102
        return $this;
2✔
103
    }
104

105
    public function clearHistory(): self
106
    {
107
        $this->session->flash(
2✔
108
            key: 'inertia.clear_history',
2✔
109
            value: true,
2✔
110
        );
2✔
111

112
        return $this;
2✔
113
    }
114

115
    public function location(string|Redirect $url): Response
116
    {
117
        /** @var bool */
118
        $isInertiaRequest = $this->container->get(Request::class)?->headers?->has(Header::INERTIA) ?? false;
7✔
119

120
        if ($isInertiaRequest) {
7✔
121
            if ($url instanceof Redirect) {
3✔
122
                /** @var string */
123
                $url = $url->getHeader(name: 'Location')->values[0] ?? '/';
1✔
124
            }
125

126
            return new GenericResponse(
3✔
127
                status: Status::CONFLICT,
3✔
128
                body: '',
3✔
129
                headers: [
3✔
130
                    Header::LOCATION => $url,
3✔
131
                ],
3✔
132
            );
3✔
133
        }
134

135
        return $url instanceof Redirect ? $url : new Redirect($url);
4✔
136
    }
137
}
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