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
9 changes: 3 additions & 6 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@
*/
final class Application
{
/** @var Application\Implementation<I, O> */
private Application\Implementation $app;

/**
* @psalm-mutation-free
*
* @param Application\Implementation<I, O> $app
*/
private function __construct(Application\Implementation $app)
{
$this->app = $app;
private function __construct(
private Application\Implementation $app,
) {
}

/**
Expand Down
36 changes: 9 additions & 27 deletions src/Application/Async/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<callable(Routes, Container, OperatingSystem, Environment): Routes> */
private Sequence $routes;
/** @var callable(RequestHandler, Container, OperatingSystem, Environment): RequestHandler */
private $mapRequestHandler;
/** @var Maybe<callable(ServerRequest, Container, OperatingSystem, Environment): Response> */
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<callable(Routes, Container, OperatingSystem, Environment): Routes> $routes
* @param callable(RequestHandler, Container, OperatingSystem, Environment): RequestHandler $mapRequestHandler
* @param \Closure(RequestHandler, Container, OperatingSystem, Environment): RequestHandler $mapRequestHandler
* @param Maybe<callable(ServerRequest, Container, OperatingSystem, Environment): Response> $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;
}

/**
Expand Down
30 changes: 8 additions & 22 deletions src/Application/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,20 @@
*/
final class Cli implements Implementation
{
private OperatingSystem $os;
private Environment $env;
/** @var callable(OperatingSystem, Environment): Builder */
private $container;
/** @var Sequence<callable(Container, OperatingSystem, Environment): Command> */
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<callable(Container, OperatingSystem, Environment): Command> $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;
}

/**
Expand Down Expand Up @@ -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,
Expand Down
33 changes: 8 additions & 25 deletions src/Application/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,22 @@
*/
final class Http implements Implementation
{
private OperatingSystem $os;
private Environment $env;
/** @var callable(OperatingSystem, Environment): Builder */
private $container;
/** @var Sequence<callable(Routes, Container, OperatingSystem, Environment): Routes> */
private Sequence $routes;
/** @var callable(RequestHandler, Container, OperatingSystem, Environment): RequestHandler */
private $mapRequestHandler;
/** @var Maybe<callable(ServerRequest, Container, OperatingSystem, Environment): Response> */
private Maybe $notFound;

/**
* @psalm-mutation-free
*
* @param callable(OperatingSystem, Environment): Builder $container
* @param \Closure(OperatingSystem, Environment): Builder $container
* @param Sequence<callable(Routes, Container, OperatingSystem, Environment): Routes> $routes
* @param callable(RequestHandler, Container, OperatingSystem, Environment): RequestHandler $mapRequestHandler
* @param \Closure(RequestHandler, Container, OperatingSystem, Environment): RequestHandler $mapRequestHandler
* @param Maybe<callable(ServerRequest, Container, OperatingSystem, Environment): Response> $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;
}

/**
Expand Down
26 changes: 7 additions & 19 deletions src/Cli/Command/Defer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 1 addition & 5 deletions src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@
*/
final class Environment
{
/** @var Map<string, string> */
private Map $variables;

/**
* @param Map<string, string> $variables
*/
private function __construct(Map $variables)
private function __construct(private Map $variables)
{
$this->variables = $variables;
}

/**
Expand Down
13 changes: 4 additions & 9 deletions src/Http/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,14 @@
*/
final class Router implements RequestHandler
{
/** @var Sequence<Route|Under> */
private Sequence $routes;
/** @var Maybe<\Closure(ServerRequest): Response> */
private Maybe $notFound;

/**
* @param Sequence<Route|Under> $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]
Expand Down
6 changes: 1 addition & 5 deletions src/Http/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@
*/
final class Routes
{
/** @var Sequence<Route|Under> */
private Sequence $routes;

/**
* @param Sequence<Route|Under> $routes
*/
private function __construct(Sequence $routes)
private function __construct(private Sequence $routes)
{
$this->routes = $routes;
}

/**
Expand Down
11 changes: 4 additions & 7 deletions src/Http/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/Http/To.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
17 changes: 6 additions & 11 deletions src/Middleware/Optional.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,14 @@

final class Optional implements Middleware
{
/** @var class-string<Middleware> */
private string $middleware;
/** @var callable(): Middleware */
private $factory;

/**
* @param class-string<Middleware> $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]
Expand All @@ -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),
);
}
}
Loading