diff --git a/psalm.xml b/psalm.xml
index bd44196..38edc2c 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -14,4 +14,7 @@
+
+
+
diff --git a/src/Config.php b/src/Config.php
index 69e7c29..e866fc8 100644
--- a/src/Config.php
+++ b/src/Config.php
@@ -29,6 +29,8 @@
final class Config
{
/**
+ * @psalm-mutation-free
+ *
* @param \Closure(Clock, self): Clock $mapClock
* @param \Closure(Halt, self): Halt $mapHalt
* @param \Closure(HttpTransport, self): HttpTransport $mapHttpTransport
@@ -60,6 +62,7 @@ private function __construct(
) {
}
+ #[\NoDiscard]
public static function new(): self
{
return new self(
@@ -97,6 +100,7 @@ public static function new(): self
*
* @param callable(self): self $map
*/
+ #[\NoDiscard]
public function map(callable $map): self
{
/** @psalm-suppress ImpureFunctionCall */
@@ -106,6 +110,7 @@ public function map(callable $map): self
/**
* @psalm-mutation-free
*/
+ #[\NoDiscard]
public function withClock(Clock $clock): self
{
return new self(
@@ -133,6 +138,7 @@ public function withClock(Clock $clock): self
*
* @param \Closure(Clock, self): Clock $map
*/
+ #[\NoDiscard]
public function mapClock(\Closure $map): self
{
$previous = $this->mapClock;
@@ -163,6 +169,7 @@ public function mapClock(\Closure $map): self
/**
* @psalm-mutation-free
*/
+ #[\NoDiscard]
public function haltProcessVia(Halt $halt): self
{
return new self(
@@ -190,6 +197,7 @@ public function haltProcessVia(Halt $halt): self
*
* @param \Closure(Halt, self): Halt $map
*/
+ #[\NoDiscard]
public function mapHalt(\Closure $map): self
{
$previous = $this->mapHalt;
@@ -221,6 +229,7 @@ public function mapHalt(\Closure $map): self
/**
* @psalm-mutation-free
*/
+ #[\NoDiscard]
public function withIO(IO $io): self
{
return new self(
@@ -246,6 +255,7 @@ public function withIO(IO $io): self
/**
* @psalm-mutation-free
*/
+ #[\NoDiscard]
public function withEnvironmentPath(EnvironmentPath $path): self
{
return new self(
@@ -271,6 +281,7 @@ public function withEnvironmentPath(EnvironmentPath $path): self
/**
* @psalm-mutation-free
*/
+ #[\NoDiscard]
public function useHttpTransport(HttpTransport $transport): self
{
return new self(
@@ -298,6 +309,7 @@ public function useHttpTransport(HttpTransport $transport): self
*
* @param \Closure(HttpTransport, self): HttpTransport $map
*/
+ #[\NoDiscard]
public function mapHttpTransport(\Closure $map): self
{
$previous = $this->mapHttpTransport;
@@ -330,6 +342,7 @@ public function mapHttpTransport(\Closure $map): self
*
* @param \Closure(Url): AccessLayer\Connection $sql
*/
+ #[\NoDiscard]
public function openSQLConnectionVia(\Closure $sql): self
{
return new self(
@@ -357,6 +370,7 @@ public function openSQLConnectionVia(\Closure $sql): self
*
* @param \Closure(AccessLayer\Connection, self): AccessLayer\Connection $map
*/
+ #[\NoDiscard]
public function mapSQLConnection(\Closure $map): self
{
$previous = $this->mapSql;
@@ -389,6 +403,7 @@ public function mapSQLConnection(\Closure $map): self
*
* @param \Closure(Control\Server, self): Control\Server $map
*/
+ #[\NoDiscard]
public function mapServerControl(\Closure $map): self
{
$previous = $this->mapServerControl;
@@ -421,6 +436,7 @@ public function mapServerControl(\Closure $map): self
*
* @param \Closure(Status\Server, self): Status\Server $map
*/
+ #[\NoDiscard]
public function mapServerStatus(\Closure $map): self
{
$previous = $this->mapServerStatus;
@@ -453,6 +469,7 @@ public function mapServerStatus(\Closure $map): self
*
* @param \Closure(Watch, self): Watch $map
*/
+ #[\NoDiscard]
public function mapFileWatch(\Closure $map): self
{
$previous = $this->mapFileWatch;
@@ -485,6 +502,7 @@ public function mapFileWatch(\Closure $map): self
*
* @param \Closure(Path, self): Attempt $filesystem
*/
+ #[\NoDiscard]
public function mountFilesystemVia(\Closure $filesystem): self
{
return new self(
@@ -512,6 +530,7 @@ public function mountFilesystemVia(\Closure $filesystem): self
*
* @param \Closure(Filesystem, self): Filesystem $map
*/
+ #[\NoDiscard]
public function mapFilesystem(\Closure $map): self
{
$previous = $this->mapFilesystem;
@@ -542,6 +561,7 @@ public function mapFilesystem(\Closure $map): self
/**
* @psalm-mutation-free
*/
+ #[\NoDiscard]
public function handleSignalsVia(Handler $handler): self
{
return new self(
@@ -567,6 +587,7 @@ public function handleSignalsVia(Handler $handler): self
/**
* @internal
*/
+ #[\NoDiscard]
public function clock(): Clock
{
return ($this->mapClock)($this->clock, $this);
@@ -577,6 +598,7 @@ public function clock(): Clock
*
* @return Attempt
*/
+ #[\NoDiscard]
public function filesystem(Path $path): Attempt
{
return ($this->filesystem)($path, $this)->map(
@@ -587,6 +609,7 @@ public function filesystem(Path $path): Attempt
/**
* @internal
*/
+ #[\NoDiscard]
public function io(): IO
{
return $this->io;
@@ -595,6 +618,7 @@ public function io(): IO
/**
* @internal
*/
+ #[\NoDiscard]
public function halt(): Halt
{
return ($this->mapHalt)($this->halt, $this);
@@ -603,6 +627,7 @@ public function halt(): Halt
/**
* @internal
*/
+ #[\NoDiscard]
public function environmentPath(): EnvironmentPath
{
return $this->path;
@@ -611,6 +636,7 @@ public function environmentPath(): EnvironmentPath
/**
* @internal
*/
+ #[\NoDiscard]
public function httpTransport(): HttpTransport
{
$transport = $this->httpTransport ?? Curl::of(
@@ -624,6 +650,7 @@ public function httpTransport(): HttpTransport
/**
* @internal
*/
+ #[\NoDiscard]
public function sql(Url $url): AccessLayer\Connection
{
return ($this->mapSql)(
@@ -635,6 +662,7 @@ public function sql(Url $url): AccessLayer\Connection
/**
* @internal
*/
+ #[\NoDiscard]
public function serverControl(Control\Server $server): Control\Server
{
return ($this->mapServerControl)($server, $this);
@@ -643,6 +671,7 @@ public function serverControl(Control\Server $server): Control\Server
/**
* @internal
*/
+ #[\NoDiscard]
public function serverStatus(Status\Server $server): Status\Server
{
return ($this->mapServerStatus)($server, $this);
@@ -651,6 +680,7 @@ public function serverStatus(Status\Server $server): Status\Server
/**
* @internal
*/
+ #[\NoDiscard]
public function fileWatch(Watch $watch): Watch
{
return ($this->mapFileWatch)($watch, $this);
@@ -659,6 +689,7 @@ public function fileWatch(Watch $watch): Watch
/**
* @internal
*/
+ #[\NoDiscard]
public function signalsHandler(): Handler
{
return $this->signals;
diff --git a/src/Config/Logger.php b/src/Config/Logger.php
index 56dcdc2..fb7d2a4 100644
--- a/src/Config/Logger.php
+++ b/src/Config/Logger.php
@@ -14,6 +14,9 @@
use Formal\AccessLayer\Connection;
use Psr\Log\LoggerInterface;
+/**
+ * @psalm-immutable
+ */
final class Logger
{
private function __construct(
@@ -21,6 +24,7 @@ private function __construct(
) {
}
+ #[\NoDiscard]
public function __invoke(Config $config): Config
{
return $config
@@ -55,6 +59,10 @@ public function __invoke(Config $config): Config
));
}
+ /**
+ * @psalm-pure
+ */
+ #[\NoDiscard]
public static function psr(LoggerInterface $logger): self
{
return new self($logger);
diff --git a/src/Config/Resilient.php b/src/Config/Resilient.php
index dd04ba6..3f44206 100644
--- a/src/Config/Resilient.php
+++ b/src/Config/Resilient.php
@@ -6,10 +6,14 @@
use Innmind\OperatingSystem\Config;
use Innmind\HttpTransport\ExponentialBackoff;
+/**
+ * @psalm-immutable
+ */
enum Resilient
{
case instance;
+ #[\NoDiscard]
public function __invoke(Config $config): Config
{
return $config
@@ -21,7 +25,10 @@ public function __invoke(Config $config): Config
/**
* This config helps retry certain _safe_ operations on remote systems
+ *
+ * @psalm-pure
*/
+ #[\NoDiscard]
public static function new(): self
{
return self::instance;
diff --git a/src/CurrentProcess.php b/src/CurrentProcess.php
index eb3a433..e30d96c 100644
--- a/src/CurrentProcess.php
+++ b/src/CurrentProcess.php
@@ -29,6 +29,7 @@ private function __construct(Halt $halt, Handler $handler)
/**
* @internal
*/
+ #[\NoDiscard]
public static function of(Halt $halt, Handler $handler): self
{
return new self($halt, $handler);
@@ -37,6 +38,7 @@ public static function of(Halt $halt, Handler $handler): self
/**
* @return Attempt
*/
+ #[\NoDiscard]
public function id(): Attempt
{
$pid = \getmypid();
@@ -48,6 +50,7 @@ public function id(): Attempt
};
}
+ #[\NoDiscard]
public function signals(): Signals
{
return $this->signals ??= Signals::of($this->handler);
@@ -56,11 +59,13 @@ public function signals(): Signals
/**
* @return Attempt
*/
+ #[\NoDiscard]
public function halt(Period $period): Attempt
{
return ($this->halt)($period);
}
+ #[\NoDiscard]
public function memory(): Bytes
{
/** @psalm-suppress ArgumentTypeCoercion */
diff --git a/src/Factory.php b/src/Factory.php
index ee9cc5a..e67a1a9 100644
--- a/src/Factory.php
+++ b/src/Factory.php
@@ -5,6 +5,7 @@
final class Factory
{
+ #[\NoDiscard]
public static function build(?Config $config = null): OperatingSystem
{
switch (\PHP_OS) {
diff --git a/src/Filesystem.php b/src/Filesystem.php
index 8426b11..4454165 100644
--- a/src/Filesystem.php
+++ b/src/Filesystem.php
@@ -41,6 +41,7 @@ private function __construct(Processes $processes, Config $config)
/**
* @internal
*/
+ #[\NoDiscard]
public static function of(Processes $processes, Config $config): self
{
return new self($processes, $config);
@@ -49,6 +50,7 @@ public static function of(Processes $processes, Config $config): self
/**
* @return Attempt
*/
+ #[\NoDiscard]
public function mount(Path $path): Attempt
{
/**
@@ -71,6 +73,7 @@ public function mount(Path $path): Attempt
});
}
+ #[\NoDiscard]
public function contains(Path $path): bool
{
if (!\file_exists($path->toString())) {
@@ -87,6 +90,7 @@ public function contains(Path $path): bool
/**
* @return Maybe Return the value returned by the file or nothing if the file doesn't exist
*/
+ #[\NoDiscard]
public function require(Path $path): Maybe
{
$path = $path->toString();
@@ -104,6 +108,7 @@ public function require(Path $path): Maybe
return Maybe::just(require $path);
}
+ #[\NoDiscard]
public function watch(Path $path): Ping
{
return ($this->watch)($path);
@@ -121,6 +126,7 @@ public function watch(Path $path): Ping
*
* @return Attempt
*/
+ #[\NoDiscard]
public function temporary(Sequence $chunks): Attempt
{
return $this
diff --git a/src/OperatingSystem.php b/src/OperatingSystem.php
index a9ebd2a..e99877c 100644
--- a/src/OperatingSystem.php
+++ b/src/OperatingSystem.php
@@ -29,6 +29,7 @@ private function __construct(Config $config)
$this->config = $config;
}
+ #[\NoDiscard]
public static function new(?Config $config = null): self
{
return new self($config ?? Config::new());
@@ -40,16 +41,19 @@ public static function new(?Config $config = null): self
*
* @param callable(Config): Config $map
*/
+ #[\NoDiscard]
public function map(callable $map): self
{
return new self($map($this->config));
}
+ #[\NoDiscard]
public function clock(): Clock
{
return $this->config->clock();
}
+ #[\NoDiscard]
public function filesystem(): Filesystem
{
return $this->filesystem ??= Filesystem::of(
@@ -58,6 +62,7 @@ public function filesystem(): Filesystem
);
}
+ #[\NoDiscard]
public function status(): ServerStatus
{
return $this->status ??= $this->config->serverStatus(
@@ -69,6 +74,7 @@ public function status(): ServerStatus
);
}
+ #[\NoDiscard]
public function control(): ServerControl
{
return $this->control ??= $this->config->serverControl(
@@ -80,16 +86,19 @@ public function control(): ServerControl
);
}
+ #[\NoDiscard]
public function ports(): Ports
{
return $this->ports ??= Ports::of($this->config);
}
+ #[\NoDiscard]
public function sockets(): Sockets
{
return $this->sockets ??= Sockets::of($this->config);
}
+ #[\NoDiscard]
public function remote(): Remote
{
return $this->remote ??= Remote::of(
@@ -98,6 +107,7 @@ public function remote(): Remote
);
}
+ #[\NoDiscard]
public function process(): CurrentProcess
{
return $this->process ??= CurrentProcess::of(
diff --git a/src/Ports.php b/src/Ports.php
index 5794216..a938968 100644
--- a/src/Ports.php
+++ b/src/Ports.php
@@ -23,6 +23,7 @@ private function __construct(Config $config)
/**
* @internal
*/
+ #[\NoDiscard]
public static function of(Config $config): self
{
return new self($config);
@@ -31,6 +32,7 @@ public static function of(Config $config): self
/**
* @return Attempt
*/
+ #[\NoDiscard]
public function open(Transport $transport, IP $ip, Port $port): Attempt
{
return $this
diff --git a/src/Remote.php b/src/Remote.php
index e20ef77..fee3f57 100644
--- a/src/Remote.php
+++ b/src/Remote.php
@@ -35,11 +35,13 @@ private function __construct(Server $server, Config $config)
/**
* @internal
*/
+ #[\NoDiscard]
public static function of(Server $server, Config $config): self
{
return new self($server, $config);
}
+ #[\NoDiscard]
public function ssh(Url $server): Server
{
$port = null;
@@ -61,6 +63,7 @@ public function ssh(Url $server): Server
/**
* @return Attempt
*/
+ #[\NoDiscard]
public function socket(Transport $transport, Authority $authority): Attempt
{
return $this
@@ -71,11 +74,13 @@ public function socket(Transport $transport, Authority $authority): Attempt
->internet($transport, $authority);
}
+ #[\NoDiscard]
public function http(): HttpTransport
{
return $this->http ??= $this->config->httpTransport();
}
+ #[\NoDiscard]
public function sql(Url $server): Connection
{
return $this->config->sql($server);
diff --git a/src/Sockets.php b/src/Sockets.php
index a743622..abaadce 100644
--- a/src/Sockets.php
+++ b/src/Sockets.php
@@ -22,6 +22,7 @@ private function __construct(Config $config)
/**
* @internal
*/
+ #[\NoDiscard]
public static function of(Config $config): self
{
return new self($config);
@@ -32,6 +33,7 @@ public static function of(Config $config): self
*
* @return Attempt
*/
+ #[\NoDiscard]
public function open(Address $address): Attempt
{
return $this
@@ -47,6 +49,7 @@ public function open(Address $address): Attempt
*
* @return Attempt
*/
+ #[\NoDiscard]
public function takeOver(Address $address): Attempt
{
return $this
@@ -60,6 +63,7 @@ public function takeOver(Address $address): Attempt
/**
* @return Attempt
*/
+ #[\NoDiscard]
public function connectTo(Address $address): Attempt
{
return $this