diff --git a/src/Application.php b/src/Application.php index d1804bd..fcffeda 100644 --- a/src/Application.php +++ b/src/Application.php @@ -28,17 +28,14 @@ */ final class Application { - /** @var Application\Implementation */ - private Application\Implementation $app; - /** * @psalm-mutation-free * * @param Application\Implementation $app */ - private function __construct(Application\Implementation $app) - { - $this->app = $app; + private function __construct( + private Application\Implementation $app, + ) { } /** diff --git a/src/Application/Async/Http.php b/src/Application/Async/Http.php index cc2e27f..9658bc7 100644 --- a/src/Application/Async/Http.php +++ b/src/Application/Async/Http.php @@ -40,41 +40,23 @@ */ final class Http implements Implementation { - private OperatingSystem $os; - /** @var callable(OperatingSystem, Environment): array{OperatingSystem, Environment} */ - private $map; - /** @var callable(OperatingSystem, Environment): Builder */ - private $container; - /** @var Sequence */ - private Sequence $routes; - /** @var callable(RequestHandler, Container, OperatingSystem, Environment): RequestHandler */ - private $mapRequestHandler; - /** @var Maybe */ - private Maybe $notFound; - /** * @psalm-mutation-free * - * @param callable(OperatingSystem, Environment): array{OperatingSystem, Environment} $map - * @param callable(OperatingSystem, Environment): Builder $container + * @param \Closure(OperatingSystem, Environment): array{OperatingSystem, Environment} $map + * @param \Closure(OperatingSystem, Environment): Builder $container * @param Sequence $routes - * @param callable(RequestHandler, Container, OperatingSystem, Environment): RequestHandler $mapRequestHandler + * @param \Closure(RequestHandler, Container, OperatingSystem, Environment): RequestHandler $mapRequestHandler * @param Maybe $notFound */ private function __construct( - OperatingSystem $os, - callable $map, - callable $container, - Sequence $routes, - callable $mapRequestHandler, - Maybe $notFound, + private OperatingSystem $os, + private \Closure $map, + private \Closure $container, + private Sequence $routes, + private \Closure $mapRequestHandler, + private Maybe $notFound, ) { - $this->os = $os; - $this->map = $map; - $this->container = $container; - $this->routes = $routes; - $this->mapRequestHandler = $mapRequestHandler; - $this->notFound = $notFound; } /** diff --git a/src/Application/Cli.php b/src/Application/Cli.php index 1d87ec6..c707a9b 100644 --- a/src/Application/Cli.php +++ b/src/Application/Cli.php @@ -29,34 +29,20 @@ */ final class Cli implements Implementation { - private OperatingSystem $os; - private Environment $env; - /** @var callable(OperatingSystem, Environment): Builder */ - private $container; - /** @var Sequence */ - private Sequence $commands; - /** @var callable(Command, Container, OperatingSystem, Environment): Command */ - private $mapCommand; - /** * @psalm-mutation-free * - * @param callable(OperatingSystem, Environment): Builder $container + * @param \Closure(OperatingSystem, Environment): Builder $container * @param Sequence $commands - * @param callable(Command, Container, OperatingSystem, Environment): Command $mapCommand + * @param \Closure(Command, Container, OperatingSystem, Environment): Command $mapCommand */ private function __construct( - OperatingSystem $os, - Environment $env, - callable $container, - Sequence $commands, - callable $mapCommand, + private OperatingSystem $os, + private Environment $env, + private \Closure $container, + private Sequence $commands, + private \Closure $mapCommand, ) { - $this->os = $os; - $this->env = $env; - $this->container = $container; - $this->commands = $commands; - $this->mapCommand = $mapCommand; } /** @@ -217,7 +203,7 @@ public function run($input) $env, ); $commands = $this->commands->map(static fn($command) => new Defer( - $command, + \Closure::fromCallable($command), $container, $os, $env, diff --git a/src/Application/Http.php b/src/Application/Http.php index b7f3a02..9508942 100644 --- a/src/Application/Http.php +++ b/src/Application/Http.php @@ -31,39 +31,22 @@ */ final class Http implements Implementation { - private OperatingSystem $os; - private Environment $env; - /** @var callable(OperatingSystem, Environment): Builder */ - private $container; - /** @var Sequence */ - private Sequence $routes; - /** @var callable(RequestHandler, Container, OperatingSystem, Environment): RequestHandler */ - private $mapRequestHandler; - /** @var Maybe */ - private Maybe $notFound; - /** * @psalm-mutation-free * - * @param callable(OperatingSystem, Environment): Builder $container + * @param \Closure(OperatingSystem, Environment): Builder $container * @param Sequence $routes - * @param callable(RequestHandler, Container, OperatingSystem, Environment): RequestHandler $mapRequestHandler + * @param \Closure(RequestHandler, Container, OperatingSystem, Environment): RequestHandler $mapRequestHandler * @param Maybe $notFound */ private function __construct( - OperatingSystem $os, - Environment $env, - callable $container, - Sequence $routes, - callable $mapRequestHandler, - Maybe $notFound, + private OperatingSystem $os, + private Environment $env, + private \Closure $container, + private Sequence $routes, + private \Closure $mapRequestHandler, + private Maybe $notFound, ) { - $this->os = $os; - $this->env = $env; - $this->container = $container; - $this->routes = $routes; - $this->mapRequestHandler = $mapRequestHandler; - $this->notFound = $notFound; } /** diff --git a/src/Cli/Command/Defer.php b/src/Cli/Command/Defer.php index 03d2f76..6438792 100644 --- a/src/Cli/Command/Defer.php +++ b/src/Cli/Command/Defer.php @@ -16,31 +16,19 @@ */ final class Defer implements Command { - /** @var callable(Container, OperatingSystem, Environment): Command */ - private $build; - private Container $locate; - private OperatingSystem $os; - private Environment $env; - /** @var callable(Command): Command */ - private $map; private ?Command $command = null; /** - * @param callable(Container, OperatingSystem, Environment): Command $build - * @param callable(Command): Command $map + * @param \Closure(Container, OperatingSystem, Environment): Command $build + * @param \Closure(Command): Command $map */ public function __construct( - callable $build, - Container $locate, - OperatingSystem $os, - Environment $env, - callable $map, + private \Closure $build, + private Container $locate, + private OperatingSystem $os, + private Environment $env, + private \Closure $map, ) { - $this->build = $build; - $this->locate = $locate; - $this->os = $os; - $this->env = $env; - $this->map = $map; } #[\Override] diff --git a/src/Environment.php b/src/Environment.php index c14e2b4..318f7b0 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -15,15 +15,11 @@ */ final class Environment { - /** @var Map */ - private Map $variables; - /** * @param Map $variables */ - private function __construct(Map $variables) + private function __construct(private Map $variables) { - $this->variables = $variables; } /** diff --git a/src/Http/Router.php b/src/Http/Router.php index f3dab7b..09b17f9 100644 --- a/src/Http/Router.php +++ b/src/Http/Router.php @@ -23,19 +23,14 @@ */ final class Router implements RequestHandler { - /** @var Sequence */ - private Sequence $routes; - /** @var Maybe<\Closure(ServerRequest): Response> */ - private Maybe $notFound; - /** * @param Sequence $routes * @param Maybe<\Closure(ServerRequest): Response> $notFound */ - public function __construct(Sequence $routes, Maybe $notFound) - { - $this->routes = $routes; - $this->notFound = $notFound; + public function __construct( + private Sequence $routes, + private Maybe $notFound, + ) { } #[\Override] diff --git a/src/Http/Routes.php b/src/Http/Routes.php index e7c6653..1bfe116 100644 --- a/src/Http/Routes.php +++ b/src/Http/Routes.php @@ -14,15 +14,11 @@ */ final class Routes { - /** @var Sequence */ - private Sequence $routes; - /** * @param Sequence $routes */ - private function __construct(Sequence $routes) + private function __construct(private Sequence $routes) { - $this->routes = $routes; } /** diff --git a/src/Http/Service.php b/src/Http/Service.php index ab4de0a..0a326c1 100644 --- a/src/Http/Service.php +++ b/src/Http/Service.php @@ -15,13 +15,10 @@ final class Service { - private Container $container; - private Ref $service; - - private function __construct(Container $container, Ref $service) - { - $this->container = $container; - $this->service = $service; + private function __construct( + private Container $container, + private Ref $service, + ) { } public function __invoke(ServerRequest $request, Variables $variables): Response diff --git a/src/Http/To.php b/src/Http/To.php index a281eb4..2bd9c03 100644 --- a/src/Http/To.php +++ b/src/Http/To.php @@ -17,11 +17,8 @@ final class To { - private Service $service; - - private function __construct(Service $service) + private function __construct(private Service $service) { - $this->service = $service; } public function __invoke( diff --git a/src/Middleware/Optional.php b/src/Middleware/Optional.php index 8e42f10..257209c 100644 --- a/src/Middleware/Optional.php +++ b/src/Middleware/Optional.php @@ -10,19 +10,14 @@ final class Optional implements Middleware { - /** @var class-string */ - private string $middleware; - /** @var callable(): Middleware */ - private $factory; - /** * @param class-string $middleware - * @param callable(): Middleware $factory + * @param \Closure(): Middleware $factory */ - private function __construct(string $middleware, callable $factory) - { - $this->middleware = $middleware; - $this->factory = $factory; + private function __construct( + private string $middleware, + private \Closure $factory, + ) { } #[\Override] @@ -45,7 +40,7 @@ public static function of(string $middleware, ?callable $factory = null): self { return new self( $middleware, - $factory ?? static fn() => new $middleware, + \Closure::fromCallable($factory ?? static fn() => new $middleware), ); } }