diff --git a/psalm.xml b/psalm.xml index 78df975..a2dbf3d 100644 --- a/psalm.xml +++ b/psalm.xml @@ -17,4 +17,7 @@ + + + diff --git a/src/Application.php b/src/Application.php index 3e9894e..96a8be7 100644 --- a/src/Application.php +++ b/src/Application.php @@ -46,6 +46,7 @@ private function __construct( * * @return self */ + #[\NoDiscard] public static function http(OperatingSystem $os, Environment $env): self { return new self(Application\Http::of($os, $env)); @@ -56,6 +57,7 @@ public static function http(OperatingSystem $os, Environment $env): self * * @return self> */ + #[\NoDiscard] public static function cli(OperatingSystem $os, Environment $env): self { return new self(Application\Cli::of($os, $env)); @@ -67,6 +69,7 @@ public static function cli(OperatingSystem $os, Environment $env): self * * @return self> */ + #[\NoDiscard] public static function asyncHttp(OperatingSystem $os): self { return new self(Application\Async\Http::of($os)); @@ -79,6 +82,7 @@ public static function asyncHttp(OperatingSystem $os): self * * @return self */ + #[\NoDiscard] public function mapEnvironment(callable $map): self { return new self($this->app->mapEnvironment($map)); @@ -91,6 +95,7 @@ public function mapEnvironment(callable $map): self * * @return self */ + #[\NoDiscard] public function mapOperatingSystem(callable $map): self { return new self($this->app->mapOperatingSystem($map)); @@ -101,6 +106,7 @@ public function mapOperatingSystem(callable $map): self * * @return self */ + #[\NoDiscard] public function map(Middleware $map): self { /** @psalm-suppress ImpureMethodCall Mutation free to force the user to use the returned object */ @@ -114,6 +120,7 @@ public function map(Middleware $map): self * * @return self */ + #[\NoDiscard] public function service(Service $name, callable $definition): self { return new self($this->app->service($name, $definition)); @@ -126,6 +133,7 @@ public function service(Service $name, callable $definition): self * * @return self */ + #[\NoDiscard] public function command(callable $command): self { return new self($this->app->command($command)); @@ -138,6 +146,7 @@ public function command(callable $command): self * * @return self */ + #[\NoDiscard] public function mapCommand(callable $map): self { return new self($this->app->mapCommand($map)); @@ -150,6 +159,7 @@ public function mapCommand(callable $map): self * * @return self */ + #[\NoDiscard] public function route(Http\Route\Reference|callable $handle): self { if ($handle instanceof Http\Route\Reference) { @@ -166,6 +176,7 @@ public function route(Http\Route\Reference|callable $handle): self * * @return self */ + #[\NoDiscard] public function routes(string $routes): self { $self = $this; @@ -184,6 +195,7 @@ public function routes(string $routes): self * * @return self */ + #[\NoDiscard] public function mapRoute(callable $map): self { return new self($this->app->mapRoute($map)); @@ -196,6 +208,7 @@ public function mapRoute(callable $map): self * * @return self */ + #[\NoDiscard] public function routeNotFound(callable $handle): self { return new self($this->app->routeNotFound($handle)); @@ -208,6 +221,7 @@ public function routeNotFound(callable $handle): self * * @return self */ + #[\NoDiscard] public function recoverRouteError(callable $recover): self { return new self($this->app->recoverRouteError($recover)); @@ -218,6 +232,7 @@ public function recoverRouteError(callable $recover): self * * @return O */ + #[\NoDiscard] public function run(CliEnv|ServerRequest $input): Attempt|Response { return $this->app->run($input); diff --git a/src/Cli/Command.php b/src/Cli/Command.php index cd9ddee..0198973 100644 --- a/src/Cli/Command.php +++ b/src/Cli/Command.php @@ -41,6 +41,7 @@ public function __invoke(Console $console): Attempt * * @param class-string $class */ + #[\NoDiscard] public static function of( string $class, Service ...$dependencies, diff --git a/src/Environment.php b/src/Environment.php index 318f7b0..ed3b960 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -27,6 +27,7 @@ private function __construct(private Map $variables) * * @param Map $variables */ + #[\NoDiscard] public static function of(Map $variables): self { return new self($variables); @@ -37,6 +38,7 @@ public static function of(Map $variables): self * * @param list $variables */ + #[\NoDiscard] public static function test(array $variables): self { return self::of(Map::of(...$variables)); @@ -45,6 +47,7 @@ public static function test(array $variables): self /** * @psalm-pure */ + #[\NoDiscard] public static function http(HttpEnvironment $env): self { return $env->reduce( @@ -53,6 +56,7 @@ public static function http(HttpEnvironment $env): self ); } + #[\NoDiscard] public function with(string $key, string $value): self { return new self(($this->variables)($key, $value)); @@ -63,6 +67,7 @@ public function with(string $key, string $value): self * * @throws LogicException If the variable doesn't exist */ + #[\NoDiscard] public function get(string $key): string { return $this->maybe($key)->match( @@ -74,6 +79,7 @@ public function get(string $key): string /** * @return Maybe */ + #[\NoDiscard] public function maybe(string $key): Maybe { return $this->variables->get($key); @@ -82,6 +88,7 @@ public function maybe(string $key): Maybe /** * @return Map */ + #[\NoDiscard] public function all(): Map { return $this->variables; diff --git a/src/Http/Route.php b/src/Http/Route.php index 12c75da..ba2ad86 100644 --- a/src/Http/Route.php +++ b/src/Http/Route.php @@ -31,6 +31,7 @@ private function __construct() * * @return callable(Pipe, Container): Component */ + #[\NoDiscard] public static function get( string|Template|Alias $endpoint, Service $handler, @@ -52,6 +53,7 @@ public static function get( * * @return callable(Pipe, Container): Component */ + #[\NoDiscard] public static function post( string|Template|Alias $endpoint, Service $handler, @@ -73,6 +75,7 @@ public static function post( * * @return callable(Pipe, Container): Component */ + #[\NoDiscard] public static function put( string|Template|Alias $endpoint, Service $handler, @@ -94,6 +97,7 @@ public static function put( * * @return callable(Pipe, Container): Component */ + #[\NoDiscard] public static function patch( string|Template|Alias $endpoint, Service $handler, @@ -115,6 +119,7 @@ public static function patch( * * @return callable(Pipe, Container): Component */ + #[\NoDiscard] public static function delete( string|Template|Alias $endpoint, Service $handler, @@ -136,6 +141,7 @@ public static function delete( * * @return callable(Pipe, Container): Component */ + #[\NoDiscard] public static function options( string|Template|Alias $endpoint, Service $handler, @@ -157,6 +163,7 @@ public static function options( * * @return callable(Pipe, Container): Component */ + #[\NoDiscard] public static function trace( string|Template|Alias $endpoint, Service $handler, @@ -178,6 +185,7 @@ public static function trace( * * @return callable(Pipe, Container): Component */ + #[\NoDiscard] public static function connect( string|Template|Alias $endpoint, Service $handler, @@ -199,6 +207,7 @@ public static function connect( * * @return callable(Pipe, Container): Component */ + #[\NoDiscard] public static function head( string|Template|Alias $endpoint, Service $handler, @@ -220,6 +229,7 @@ public static function head( * * @return callable(Pipe, Container): Component */ + #[\NoDiscard] public static function link( string|Template|Alias $endpoint, Service $handler, @@ -241,6 +251,7 @@ public static function link( * * @return callable(Pipe, Container): Component */ + #[\NoDiscard] public static function unlink( string|Template|Alias $endpoint, Service $handler, diff --git a/src/Http/Route/Reference.php b/src/Http/Route/Reference.php index 9967289..feac960 100644 --- a/src/Http/Route/Reference.php +++ b/src/Http/Route/Reference.php @@ -19,5 +19,6 @@ interface Reference extends \UnitEnum /** * @return callable(Pipe, Container): Component */ + #[\NoDiscard] public function route(): callable; } diff --git a/src/Middleware.php b/src/Middleware.php index 8303918..de06db0 100644 --- a/src/Middleware.php +++ b/src/Middleware.php @@ -20,5 +20,6 @@ interface Middleware * * @return Application */ + #[\NoDiscard] public function __invoke(Application $app): Application; }