Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<UndefinedAttributeClass errorLevel="suppress" />
</issueHandlers>
</psalm>
31 changes: 31 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -60,6 +62,7 @@ private function __construct(
) {
}

#[\NoDiscard]
public static function new(): self
{
return new self(
Expand Down Expand Up @@ -97,6 +100,7 @@ public static function new(): self
*
* @param callable(self): self $map
*/
#[\NoDiscard]
public function map(callable $map): self
{
/** @psalm-suppress ImpureFunctionCall */
Expand All @@ -106,6 +110,7 @@ public function map(callable $map): self
/**
* @psalm-mutation-free
*/
#[\NoDiscard]
public function withClock(Clock $clock): self
{
return new self(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -163,6 +169,7 @@ public function mapClock(\Closure $map): self
/**
* @psalm-mutation-free
*/
#[\NoDiscard]
public function haltProcessVia(Halt $halt): self
{
return new self(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -221,6 +229,7 @@ public function mapHalt(\Closure $map): self
/**
* @psalm-mutation-free
*/
#[\NoDiscard]
public function withIO(IO $io): self
{
return new self(
Expand All @@ -246,6 +255,7 @@ public function withIO(IO $io): self
/**
* @psalm-mutation-free
*/
#[\NoDiscard]
public function withEnvironmentPath(EnvironmentPath $path): self
{
return new self(
Expand All @@ -271,6 +281,7 @@ public function withEnvironmentPath(EnvironmentPath $path): self
/**
* @psalm-mutation-free
*/
#[\NoDiscard]
public function useHttpTransport(HttpTransport $transport): self
{
return new self(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -485,6 +502,7 @@ public function mapFileWatch(\Closure $map): self
*
* @param \Closure(Path, self): Attempt<Filesystem> $filesystem
*/
#[\NoDiscard]
public function mountFilesystemVia(\Closure $filesystem): self
{
return new self(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -542,6 +561,7 @@ public function mapFilesystem(\Closure $map): self
/**
* @psalm-mutation-free
*/
#[\NoDiscard]
public function handleSignalsVia(Handler $handler): self
{
return new self(
Expand All @@ -567,6 +587,7 @@ public function handleSignalsVia(Handler $handler): self
/**
* @internal
*/
#[\NoDiscard]
public function clock(): Clock
{
return ($this->mapClock)($this->clock, $this);
Expand All @@ -577,6 +598,7 @@ public function clock(): Clock
*
* @return Attempt<Filesystem>
*/
#[\NoDiscard]
public function filesystem(Path $path): Attempt
{
return ($this->filesystem)($path, $this)->map(
Expand All @@ -587,6 +609,7 @@ public function filesystem(Path $path): Attempt
/**
* @internal
*/
#[\NoDiscard]
public function io(): IO
{
return $this->io;
Expand All @@ -595,6 +618,7 @@ public function io(): IO
/**
* @internal
*/
#[\NoDiscard]
public function halt(): Halt
{
return ($this->mapHalt)($this->halt, $this);
Expand All @@ -603,6 +627,7 @@ public function halt(): Halt
/**
* @internal
*/
#[\NoDiscard]
public function environmentPath(): EnvironmentPath
{
return $this->path;
Expand All @@ -611,6 +636,7 @@ public function environmentPath(): EnvironmentPath
/**
* @internal
*/
#[\NoDiscard]
public function httpTransport(): HttpTransport
{
$transport = $this->httpTransport ?? Curl::of(
Expand All @@ -624,6 +650,7 @@ public function httpTransport(): HttpTransport
/**
* @internal
*/
#[\NoDiscard]
public function sql(Url $url): AccessLayer\Connection
{
return ($this->mapSql)(
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -659,6 +689,7 @@ public function fileWatch(Watch $watch): Watch
/**
* @internal
*/
#[\NoDiscard]
public function signalsHandler(): Handler
{
return $this->signals;
Expand Down
8 changes: 8 additions & 0 deletions src/Config/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
use Formal\AccessLayer\Connection;
use Psr\Log\LoggerInterface;

/**
* @psalm-immutable
*/
final class Logger
{
private function __construct(
private LoggerInterface $logger,
) {
}

#[\NoDiscard]
public function __invoke(Config $config): Config
{
return $config
Expand Down Expand Up @@ -55,6 +59,10 @@ public function __invoke(Config $config): Config
));
}

/**
* @psalm-pure
*/
#[\NoDiscard]
public static function psr(LoggerInterface $logger): self
{
return new self($logger);
Expand Down
7 changes: 7 additions & 0 deletions src/Config/Resilient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/CurrentProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -37,6 +38,7 @@ public static function of(Halt $halt, Handler $handler): self
/**
* @return Attempt<Pid>
*/
#[\NoDiscard]
public function id(): Attempt
{
$pid = \getmypid();
Expand All @@ -48,6 +50,7 @@ public function id(): Attempt
};
}

#[\NoDiscard]
public function signals(): Signals
{
return $this->signals ??= Signals::of($this->handler);
Expand All @@ -56,11 +59,13 @@ public function signals(): Signals
/**
* @return Attempt<SideEffect>
*/
#[\NoDiscard]
public function halt(Period $period): Attempt
{
return ($this->halt)($period);
}

#[\NoDiscard]
public function memory(): Bytes
{
/** @psalm-suppress ArgumentTypeCoercion */
Expand Down
1 change: 1 addition & 0 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

final class Factory
{
#[\NoDiscard]
public static function build(?Config $config = null): OperatingSystem
{
switch (\PHP_OS) {
Expand Down
6 changes: 6 additions & 0 deletions src/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -49,6 +50,7 @@ public static function of(Processes $processes, Config $config): self
/**
* @return Attempt<Adapter>
*/
#[\NoDiscard]
public function mount(Path $path): Attempt
{
/**
Expand All @@ -71,6 +73,7 @@ public function mount(Path $path): Attempt
});
}

#[\NoDiscard]
public function contains(Path $path): bool
{
if (!\file_exists($path->toString())) {
Expand All @@ -87,6 +90,7 @@ public function contains(Path $path): bool
/**
* @return Maybe<mixed> 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();
Expand All @@ -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);
Expand All @@ -121,6 +126,7 @@ public function watch(Path $path): Ping
*
* @return Attempt<Content>
*/
#[\NoDiscard]
public function temporary(Sequence $chunks): Attempt
{
return $this
Expand Down
Loading
Loading