Skip to content

Commit 79241f5

Browse files
committed
add NoDiscard attribute on mutation free methods
1 parent 696e993 commit 79241f5

11 files changed

Lines changed: 82 additions & 0 deletions

psalm.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@
1414
<directory name="vendor" />
1515
</ignoreFiles>
1616
</projectFiles>
17+
<issueHandlers>
18+
<UndefinedAttributeClass errorLevel="suppress" />
19+
</issueHandlers>
1720
</psalm>

src/Config.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
final class Config
3030
{
3131
/**
32+
* @psalm-mutation-free
33+
*
3234
* @param \Closure(Clock, self): Clock $mapClock
3335
* @param \Closure(Halt, self): Halt $mapHalt
3436
* @param \Closure(HttpTransport, self): HttpTransport $mapHttpTransport
@@ -60,6 +62,7 @@ private function __construct(
6062
) {
6163
}
6264

65+
#[\NoDiscard]
6366
public static function new(): self
6467
{
6568
return new self(
@@ -97,6 +100,7 @@ public static function new(): self
97100
*
98101
* @param callable(self): self $map
99102
*/
103+
#[\NoDiscard]
100104
public function map(callable $map): self
101105
{
102106
/** @psalm-suppress ImpureFunctionCall */
@@ -106,6 +110,7 @@ public function map(callable $map): self
106110
/**
107111
* @psalm-mutation-free
108112
*/
113+
#[\NoDiscard]
109114
public function withClock(Clock $clock): self
110115
{
111116
return new self(
@@ -133,6 +138,7 @@ public function withClock(Clock $clock): self
133138
*
134139
* @param \Closure(Clock, self): Clock $map
135140
*/
141+
#[\NoDiscard]
136142
public function mapClock(\Closure $map): self
137143
{
138144
$previous = $this->mapClock;
@@ -163,6 +169,7 @@ public function mapClock(\Closure $map): self
163169
/**
164170
* @psalm-mutation-free
165171
*/
172+
#[\NoDiscard]
166173
public function haltProcessVia(Halt $halt): self
167174
{
168175
return new self(
@@ -190,6 +197,7 @@ public function haltProcessVia(Halt $halt): self
190197
*
191198
* @param \Closure(Halt, self): Halt $map
192199
*/
200+
#[\NoDiscard]
193201
public function mapHalt(\Closure $map): self
194202
{
195203
$previous = $this->mapHalt;
@@ -221,6 +229,7 @@ public function mapHalt(\Closure $map): self
221229
/**
222230
* @psalm-mutation-free
223231
*/
232+
#[\NoDiscard]
224233
public function withIO(IO $io): self
225234
{
226235
return new self(
@@ -246,6 +255,7 @@ public function withIO(IO $io): self
246255
/**
247256
* @psalm-mutation-free
248257
*/
258+
#[\NoDiscard]
249259
public function withEnvironmentPath(EnvironmentPath $path): self
250260
{
251261
return new self(
@@ -271,6 +281,7 @@ public function withEnvironmentPath(EnvironmentPath $path): self
271281
/**
272282
* @psalm-mutation-free
273283
*/
284+
#[\NoDiscard]
274285
public function useHttpTransport(HttpTransport $transport): self
275286
{
276287
return new self(
@@ -298,6 +309,7 @@ public function useHttpTransport(HttpTransport $transport): self
298309
*
299310
* @param \Closure(HttpTransport, self): HttpTransport $map
300311
*/
312+
#[\NoDiscard]
301313
public function mapHttpTransport(\Closure $map): self
302314
{
303315
$previous = $this->mapHttpTransport;
@@ -330,6 +342,7 @@ public function mapHttpTransport(\Closure $map): self
330342
*
331343
* @param \Closure(Url): AccessLayer\Connection $sql
332344
*/
345+
#[\NoDiscard]
333346
public function openSQLConnectionVia(\Closure $sql): self
334347
{
335348
return new self(
@@ -357,6 +370,7 @@ public function openSQLConnectionVia(\Closure $sql): self
357370
*
358371
* @param \Closure(AccessLayer\Connection, self): AccessLayer\Connection $map
359372
*/
373+
#[\NoDiscard]
360374
public function mapSQLConnection(\Closure $map): self
361375
{
362376
$previous = $this->mapSql;
@@ -389,6 +403,7 @@ public function mapSQLConnection(\Closure $map): self
389403
*
390404
* @param \Closure(Control\Server, self): Control\Server $map
391405
*/
406+
#[\NoDiscard]
392407
public function mapServerControl(\Closure $map): self
393408
{
394409
$previous = $this->mapServerControl;
@@ -421,6 +436,7 @@ public function mapServerControl(\Closure $map): self
421436
*
422437
* @param \Closure(Status\Server, self): Status\Server $map
423438
*/
439+
#[\NoDiscard]
424440
public function mapServerStatus(\Closure $map): self
425441
{
426442
$previous = $this->mapServerStatus;
@@ -453,6 +469,7 @@ public function mapServerStatus(\Closure $map): self
453469
*
454470
* @param \Closure(Watch, self): Watch $map
455471
*/
472+
#[\NoDiscard]
456473
public function mapFileWatch(\Closure $map): self
457474
{
458475
$previous = $this->mapFileWatch;
@@ -485,6 +502,7 @@ public function mapFileWatch(\Closure $map): self
485502
*
486503
* @param \Closure(Path, self): Attempt<Filesystem> $filesystem
487504
*/
505+
#[\NoDiscard]
488506
public function mountFilesystemVia(\Closure $filesystem): self
489507
{
490508
return new self(
@@ -512,6 +530,7 @@ public function mountFilesystemVia(\Closure $filesystem): self
512530
*
513531
* @param \Closure(Filesystem, self): Filesystem $map
514532
*/
533+
#[\NoDiscard]
515534
public function mapFilesystem(\Closure $map): self
516535
{
517536
$previous = $this->mapFilesystem;
@@ -542,6 +561,7 @@ public function mapFilesystem(\Closure $map): self
542561
/**
543562
* @psalm-mutation-free
544563
*/
564+
#[\NoDiscard]
545565
public function handleSignalsVia(Handler $handler): self
546566
{
547567
return new self(
@@ -567,6 +587,7 @@ public function handleSignalsVia(Handler $handler): self
567587
/**
568588
* @internal
569589
*/
590+
#[\NoDiscard]
570591
public function clock(): Clock
571592
{
572593
return ($this->mapClock)($this->clock, $this);
@@ -577,6 +598,7 @@ public function clock(): Clock
577598
*
578599
* @return Attempt<Filesystem>
579600
*/
601+
#[\NoDiscard]
580602
public function filesystem(Path $path): Attempt
581603
{
582604
return ($this->filesystem)($path, $this)->map(
@@ -587,6 +609,7 @@ public function filesystem(Path $path): Attempt
587609
/**
588610
* @internal
589611
*/
612+
#[\NoDiscard]
590613
public function io(): IO
591614
{
592615
return $this->io;
@@ -595,6 +618,7 @@ public function io(): IO
595618
/**
596619
* @internal
597620
*/
621+
#[\NoDiscard]
598622
public function halt(): Halt
599623
{
600624
return ($this->mapHalt)($this->halt, $this);
@@ -603,6 +627,7 @@ public function halt(): Halt
603627
/**
604628
* @internal
605629
*/
630+
#[\NoDiscard]
606631
public function environmentPath(): EnvironmentPath
607632
{
608633
return $this->path;
@@ -611,6 +636,7 @@ public function environmentPath(): EnvironmentPath
611636
/**
612637
* @internal
613638
*/
639+
#[\NoDiscard]
614640
public function httpTransport(): HttpTransport
615641
{
616642
$transport = $this->httpTransport ?? Curl::of(
@@ -624,6 +650,7 @@ public function httpTransport(): HttpTransport
624650
/**
625651
* @internal
626652
*/
653+
#[\NoDiscard]
627654
public function sql(Url $url): AccessLayer\Connection
628655
{
629656
return ($this->mapSql)(
@@ -635,6 +662,7 @@ public function sql(Url $url): AccessLayer\Connection
635662
/**
636663
* @internal
637664
*/
665+
#[\NoDiscard]
638666
public function serverControl(Control\Server $server): Control\Server
639667
{
640668
return ($this->mapServerControl)($server, $this);
@@ -643,6 +671,7 @@ public function serverControl(Control\Server $server): Control\Server
643671
/**
644672
* @internal
645673
*/
674+
#[\NoDiscard]
646675
public function serverStatus(Status\Server $server): Status\Server
647676
{
648677
return ($this->mapServerStatus)($server, $this);
@@ -651,6 +680,7 @@ public function serverStatus(Status\Server $server): Status\Server
651680
/**
652681
* @internal
653682
*/
683+
#[\NoDiscard]
654684
public function fileWatch(Watch $watch): Watch
655685
{
656686
return ($this->mapFileWatch)($watch, $this);
@@ -659,6 +689,7 @@ public function fileWatch(Watch $watch): Watch
659689
/**
660690
* @internal
661691
*/
692+
#[\NoDiscard]
662693
public function signalsHandler(): Handler
663694
{
664695
return $this->signals;

src/Config/Logger.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@
1414
use Formal\AccessLayer\Connection;
1515
use Psr\Log\LoggerInterface;
1616

17+
/**
18+
* @psalm-immutable
19+
*/
1720
final class Logger
1821
{
1922
private function __construct(
2023
private LoggerInterface $logger,
2124
) {
2225
}
2326

27+
#[\NoDiscard]
2428
public function __invoke(Config $config): Config
2529
{
2630
return $config
@@ -55,6 +59,10 @@ public function __invoke(Config $config): Config
5559
));
5660
}
5761

62+
/**
63+
* @psalm-pure
64+
*/
65+
#[\NoDiscard]
5866
public static function psr(LoggerInterface $logger): self
5967
{
6068
return new self($logger);

src/Config/Resilient.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
use Innmind\OperatingSystem\Config;
77
use Innmind\HttpTransport\ExponentialBackoff;
88

9+
/**
10+
* @psalm-immutable
11+
*/
912
enum Resilient
1013
{
1114
case instance;
1215

16+
#[\NoDiscard]
1317
public function __invoke(Config $config): Config
1418
{
1519
return $config
@@ -21,7 +25,10 @@ public function __invoke(Config $config): Config
2125

2226
/**
2327
* This config helps retry certain _safe_ operations on remote systems
28+
*
29+
* @psalm-pure
2430
*/
31+
#[\NoDiscard]
2532
public static function new(): self
2633
{
2734
return self::instance;

src/CurrentProcess.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ private function __construct(Halt $halt, Handler $handler)
2929
/**
3030
* @internal
3131
*/
32+
#[\NoDiscard]
3233
public static function of(Halt $halt, Handler $handler): self
3334
{
3435
return new self($halt, $handler);
@@ -37,6 +38,7 @@ public static function of(Halt $halt, Handler $handler): self
3738
/**
3839
* @return Attempt<Pid>
3940
*/
41+
#[\NoDiscard]
4042
public function id(): Attempt
4143
{
4244
$pid = \getmypid();
@@ -48,6 +50,7 @@ public function id(): Attempt
4850
};
4951
}
5052

53+
#[\NoDiscard]
5154
public function signals(): Signals
5255
{
5356
return $this->signals ??= Signals::of($this->handler);
@@ -56,11 +59,13 @@ public function signals(): Signals
5659
/**
5760
* @return Attempt<SideEffect>
5861
*/
62+
#[\NoDiscard]
5963
public function halt(Period $period): Attempt
6064
{
6165
return ($this->halt)($period);
6266
}
6367

68+
#[\NoDiscard]
6469
public function memory(): Bytes
6570
{
6671
/** @psalm-suppress ArgumentTypeCoercion */

src/Factory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
final class Factory
77
{
8+
#[\NoDiscard]
89
public static function build(?Config $config = null): OperatingSystem
910
{
1011
switch (\PHP_OS) {

src/Filesystem.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ private function __construct(Processes $processes, Config $config)
4141
/**
4242
* @internal
4343
*/
44+
#[\NoDiscard]
4445
public static function of(Processes $processes, Config $config): self
4546
{
4647
return new self($processes, $config);
@@ -49,6 +50,7 @@ public static function of(Processes $processes, Config $config): self
4950
/**
5051
* @return Attempt<Adapter>
5152
*/
53+
#[\NoDiscard]
5254
public function mount(Path $path): Attempt
5355
{
5456
/**
@@ -71,6 +73,7 @@ public function mount(Path $path): Attempt
7173
});
7274
}
7375

76+
#[\NoDiscard]
7477
public function contains(Path $path): bool
7578
{
7679
if (!\file_exists($path->toString())) {
@@ -87,6 +90,7 @@ public function contains(Path $path): bool
8790
/**
8891
* @return Maybe<mixed> Return the value returned by the file or nothing if the file doesn't exist
8992
*/
93+
#[\NoDiscard]
9094
public function require(Path $path): Maybe
9195
{
9296
$path = $path->toString();
@@ -104,6 +108,7 @@ public function require(Path $path): Maybe
104108
return Maybe::just(require $path);
105109
}
106110

111+
#[\NoDiscard]
107112
public function watch(Path $path): Ping
108113
{
109114
return ($this->watch)($path);
@@ -121,6 +126,7 @@ public function watch(Path $path): Ping
121126
*
122127
* @return Attempt<Content>
123128
*/
129+
#[\NoDiscard]
124130
public function temporary(Sequence $chunks): Attempt
125131
{
126132
return $this

0 commit comments

Comments
 (0)