Skip to content

Commit c0cde0a

Browse files
authored
Merge pull request #17 from Innmind/no-discard-attributes
Add `NoDiscard` attribute on mutation free methods
2 parents e205ae8 + 9fa2fa5 commit c0cde0a

7 files changed

Lines changed: 39 additions & 0 deletions

File tree

psalm.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
<disableExtensions>
1818
<extension name="random" />
1919
</disableExtensions>
20+
<issueHandlers>
21+
<UndefinedAttributeClass errorLevel="suppress" />
22+
</issueHandlers>
2023
</psalm>

src/Application.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ private function __construct(
4646
*
4747
* @return self<ServerRequest, Response>
4848
*/
49+
#[\NoDiscard]
4950
public static function http(OperatingSystem $os, Environment $env): self
5051
{
5152
return new self(Application\Http::of($os, $env));
@@ -56,6 +57,7 @@ public static function http(OperatingSystem $os, Environment $env): self
5657
*
5758
* @return self<CliEnv, Attempt<CliEnv>>
5859
*/
60+
#[\NoDiscard]
5961
public static function cli(OperatingSystem $os, Environment $env): self
6062
{
6163
return new self(Application\Cli::of($os, $env));
@@ -67,6 +69,7 @@ public static function cli(OperatingSystem $os, Environment $env): self
6769
*
6870
* @return self<CliEnv, Attempt<CliEnv>>
6971
*/
72+
#[\NoDiscard]
7073
public static function asyncHttp(OperatingSystem $os): self
7174
{
7275
return new self(Application\Async\Http::of($os));
@@ -79,6 +82,7 @@ public static function asyncHttp(OperatingSystem $os): self
7982
*
8083
* @return self<I, O>
8184
*/
85+
#[\NoDiscard]
8286
public function mapEnvironment(callable $map): self
8387
{
8488
return new self($this->app->mapEnvironment($map));
@@ -91,6 +95,7 @@ public function mapEnvironment(callable $map): self
9195
*
9296
* @return self<I, O>
9397
*/
98+
#[\NoDiscard]
9499
public function mapOperatingSystem(callable $map): self
95100
{
96101
return new self($this->app->mapOperatingSystem($map));
@@ -101,6 +106,7 @@ public function mapOperatingSystem(callable $map): self
101106
*
102107
* @return self<I, O>
103108
*/
109+
#[\NoDiscard]
104110
public function map(Middleware $map): self
105111
{
106112
/** @psalm-suppress ImpureMethodCall Mutation free to force the user to use the returned object */
@@ -114,6 +120,7 @@ public function map(Middleware $map): self
114120
*
115121
* @return self<I, O>
116122
*/
123+
#[\NoDiscard]
117124
public function service(Service $name, callable $definition): self
118125
{
119126
return new self($this->app->service($name, $definition));
@@ -126,6 +133,7 @@ public function service(Service $name, callable $definition): self
126133
*
127134
* @return self<I, O>
128135
*/
136+
#[\NoDiscard]
129137
public function command(callable $command): self
130138
{
131139
return new self($this->app->command($command));
@@ -138,6 +146,7 @@ public function command(callable $command): self
138146
*
139147
* @return self<I, O>
140148
*/
149+
#[\NoDiscard]
141150
public function mapCommand(callable $map): self
142151
{
143152
return new self($this->app->mapCommand($map));
@@ -150,6 +159,7 @@ public function mapCommand(callable $map): self
150159
*
151160
* @return self<I, O>
152161
*/
162+
#[\NoDiscard]
153163
public function route(Http\Route\Reference|callable $handle): self
154164
{
155165
if ($handle instanceof Http\Route\Reference) {
@@ -166,6 +176,7 @@ public function route(Http\Route\Reference|callable $handle): self
166176
*
167177
* @return self<I, O>
168178
*/
179+
#[\NoDiscard]
169180
public function routes(string $routes): self
170181
{
171182
$self = $this;
@@ -184,6 +195,7 @@ public function routes(string $routes): self
184195
*
185196
* @return self<I, O>
186197
*/
198+
#[\NoDiscard]
187199
public function mapRoute(callable $map): self
188200
{
189201
return new self($this->app->mapRoute($map));
@@ -196,6 +208,7 @@ public function mapRoute(callable $map): self
196208
*
197209
* @return self<I, O>
198210
*/
211+
#[\NoDiscard]
199212
public function routeNotFound(callable $handle): self
200213
{
201214
return new self($this->app->routeNotFound($handle));
@@ -208,6 +221,7 @@ public function routeNotFound(callable $handle): self
208221
*
209222
* @return self<I, O>
210223
*/
224+
#[\NoDiscard]
211225
public function recoverRouteError(callable $recover): self
212226
{
213227
return new self($this->app->recoverRouteError($recover));
@@ -218,6 +232,7 @@ public function recoverRouteError(callable $recover): self
218232
*
219233
* @return O
220234
*/
235+
#[\NoDiscard]
221236
public function run(CliEnv|ServerRequest $input): Attempt|Response
222237
{
223238
return $this->app->run($input);

src/Cli/Command.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function __invoke(Console $console): Attempt
4141
*
4242
* @param class-string<CommandInterface> $class
4343
*/
44+
#[\NoDiscard]
4445
public static function of(
4546
string $class,
4647
Service ...$dependencies,

src/Environment.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ private function __construct(private Map $variables)
2727
*
2828
* @param Map<string, string> $variables
2929
*/
30+
#[\NoDiscard]
3031
public static function of(Map $variables): self
3132
{
3233
return new self($variables);
@@ -37,6 +38,7 @@ public static function of(Map $variables): self
3738
*
3839
* @param list<array{string, string}> $variables
3940
*/
41+
#[\NoDiscard]
4042
public static function test(array $variables): self
4143
{
4244
return self::of(Map::of(...$variables));
@@ -45,6 +47,7 @@ public static function test(array $variables): self
4547
/**
4648
* @psalm-pure
4749
*/
50+
#[\NoDiscard]
4851
public static function http(HttpEnvironment $env): self
4952
{
5053
return $env->reduce(
@@ -53,6 +56,7 @@ public static function http(HttpEnvironment $env): self
5356
);
5457
}
5558

59+
#[\NoDiscard]
5660
public function with(string $key, string $value): self
5761
{
5862
return new self(($this->variables)($key, $value));
@@ -63,6 +67,7 @@ public function with(string $key, string $value): self
6367
*
6468
* @throws LogicException If the variable doesn't exist
6569
*/
70+
#[\NoDiscard]
6671
public function get(string $key): string
6772
{
6873
return $this->maybe($key)->match(
@@ -74,6 +79,7 @@ public function get(string $key): string
7479
/**
7580
* @return Maybe<string>
7681
*/
82+
#[\NoDiscard]
7783
public function maybe(string $key): Maybe
7884
{
7985
return $this->variables->get($key);
@@ -82,6 +88,7 @@ public function maybe(string $key): Maybe
8288
/**
8389
* @return Map<string, string>
8490
*/
91+
#[\NoDiscard]
8592
public function all(): Map
8693
{
8794
return $this->variables;

src/Http/Route.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ private function __construct()
3131
*
3232
* @return callable(Pipe, Container): Component<mixed, Response>
3333
*/
34+
#[\NoDiscard]
3435
public static function get(
3536
string|Template|Alias $endpoint,
3637
Service $handler,
@@ -52,6 +53,7 @@ public static function get(
5253
*
5354
* @return callable(Pipe, Container): Component<mixed, Response>
5455
*/
56+
#[\NoDiscard]
5557
public static function post(
5658
string|Template|Alias $endpoint,
5759
Service $handler,
@@ -73,6 +75,7 @@ public static function post(
7375
*
7476
* @return callable(Pipe, Container): Component<mixed, Response>
7577
*/
78+
#[\NoDiscard]
7679
public static function put(
7780
string|Template|Alias $endpoint,
7881
Service $handler,
@@ -94,6 +97,7 @@ public static function put(
9497
*
9598
* @return callable(Pipe, Container): Component<mixed, Response>
9699
*/
100+
#[\NoDiscard]
97101
public static function patch(
98102
string|Template|Alias $endpoint,
99103
Service $handler,
@@ -115,6 +119,7 @@ public static function patch(
115119
*
116120
* @return callable(Pipe, Container): Component<mixed, Response>
117121
*/
122+
#[\NoDiscard]
118123
public static function delete(
119124
string|Template|Alias $endpoint,
120125
Service $handler,
@@ -136,6 +141,7 @@ public static function delete(
136141
*
137142
* @return callable(Pipe, Container): Component<mixed, Response>
138143
*/
144+
#[\NoDiscard]
139145
public static function options(
140146
string|Template|Alias $endpoint,
141147
Service $handler,
@@ -157,6 +163,7 @@ public static function options(
157163
*
158164
* @return callable(Pipe, Container): Component<mixed, Response>
159165
*/
166+
#[\NoDiscard]
160167
public static function trace(
161168
string|Template|Alias $endpoint,
162169
Service $handler,
@@ -178,6 +185,7 @@ public static function trace(
178185
*
179186
* @return callable(Pipe, Container): Component<mixed, Response>
180187
*/
188+
#[\NoDiscard]
181189
public static function connect(
182190
string|Template|Alias $endpoint,
183191
Service $handler,
@@ -199,6 +207,7 @@ public static function connect(
199207
*
200208
* @return callable(Pipe, Container): Component<mixed, Response>
201209
*/
210+
#[\NoDiscard]
202211
public static function head(
203212
string|Template|Alias $endpoint,
204213
Service $handler,
@@ -220,6 +229,7 @@ public static function head(
220229
*
221230
* @return callable(Pipe, Container): Component<mixed, Response>
222231
*/
232+
#[\NoDiscard]
223233
public static function link(
224234
string|Template|Alias $endpoint,
225235
Service $handler,
@@ -241,6 +251,7 @@ public static function link(
241251
*
242252
* @return callable(Pipe, Container): Component<mixed, Response>
243253
*/
254+
#[\NoDiscard]
244255
public static function unlink(
245256
string|Template|Alias $endpoint,
246257
Service $handler,

src/Http/Route/Reference.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ interface Reference extends \UnitEnum
1919
/**
2020
* @return callable(Pipe, Container): Component<SideEffect, Response>
2121
*/
22+
#[\NoDiscard]
2223
public function route(): callable;
2324
}

src/Middleware.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ interface Middleware
2020
*
2121
* @return Application<I, O>
2222
*/
23+
#[\NoDiscard]
2324
public function __invoke(Application $app): Application;
2425
}

0 commit comments

Comments
 (0)