chore: fix PSR-12 coding style violations using PHPCBF
Some checks are pending
CI / build (push) Waiting to run
Some checks are pending
CI / build (push) Waiting to run
This commit is contained in:
parent
41c8c9457c
commit
83c18bd82d
|
|
@ -32,7 +32,8 @@ class ListRoutesCommand
|
||||||
printf("%-10s | %-30s | %-20s | %-30s\n", "Method", "Path", "Name", "Handler");
|
printf("%-10s | %-30s | %-20s | %-30s\n", "Method", "Path", "Name", "Handler");
|
||||||
echo str_repeat("-", 100) . PHP_EOL;
|
echo str_repeat("-", 100) . PHP_EOL;
|
||||||
foreach ($output as $r) {
|
foreach ($output as $r) {
|
||||||
printf("%-10s | %-30s | %-20s | %-30s\n",
|
printf(
|
||||||
|
"%-10s | %-30s | %-20s | %-30s\n",
|
||||||
$r['method'],
|
$r['method'],
|
||||||
$r['path'],
|
$r['path'],
|
||||||
$r['name'] ?? '',
|
$r['name'] ?? '',
|
||||||
|
|
|
||||||
|
|
@ -25,76 +25,261 @@ class TestRouteCommand
|
||||||
$host = 'localhost'; // Default
|
$host = 'localhost'; // Default
|
||||||
|
|
||||||
// PSR-7 mock request
|
// PSR-7 mock request
|
||||||
$uri = new class($path, $host) implements UriInterface {
|
$uri = new class ($path, $host) implements UriInterface {
|
||||||
public function __construct(private $path, private $host) {}
|
public function __construct(private $path, private $host)
|
||||||
public function getScheme(): string { return 'http'; }
|
{
|
||||||
public function getAuthority(): string { return $this->host; }
|
}
|
||||||
public function getUserInfo(): string { return ''; }
|
public function getScheme(): string
|
||||||
public function getHost(): string { return $this->host; }
|
{
|
||||||
public function getPort(): ?int { return null; }
|
return 'http';
|
||||||
public function getPath(): string { return $this->path; }
|
}
|
||||||
public function getQuery(): string { return ''; }
|
public function getAuthority(): string
|
||||||
public function getFragment(): string { return ''; }
|
{
|
||||||
public function withScheme($scheme): UriInterface { return $this; }
|
return $this->host;
|
||||||
public function withUserInfo($user, $password = null): UriInterface { return $this; }
|
}
|
||||||
public function withHost($host): UriInterface { return $this; }
|
public function getUserInfo(): string
|
||||||
public function withPort($port): UriInterface { return $this; }
|
{
|
||||||
public function withPath($path): UriInterface { return $this; }
|
return '';
|
||||||
public function withQuery($query): UriInterface { return $this; }
|
}
|
||||||
public function withFragment($fragment): UriInterface { return $this; }
|
public function getHost(): string
|
||||||
public function __toString(): string { return "http://{$this->host}{$this->path}"; }
|
{
|
||||||
|
return $this->host;
|
||||||
|
}
|
||||||
|
public function getPort(): ?int
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public function getPath(): string
|
||||||
|
{
|
||||||
|
return $this->path;
|
||||||
|
}
|
||||||
|
public function getQuery(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
public function getFragment(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
public function withScheme($scheme): UriInterface
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function withUserInfo($user, $password = null): UriInterface
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function withHost($host): UriInterface
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function withPort($port): UriInterface
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function withPath($path): UriInterface
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function withQuery($query): UriInterface
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function withFragment($fragment): UriInterface
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function __toString(): string
|
||||||
|
{
|
||||||
|
return "http://{$this->host}{$this->path}";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$request = new class($method, $uri) implements ServerRequestInterface {
|
$request = new class ($method, $uri) implements ServerRequestInterface {
|
||||||
public function __construct(private $method, private $uri) {}
|
public function __construct(private $method, private $uri)
|
||||||
public function getProtocolVersion(): string { return '1.1'; }
|
{
|
||||||
public function withProtocolVersion($version): ServerRequestInterface { return $this; }
|
}
|
||||||
public function getHeaders(): array { return []; }
|
public function getProtocolVersion(): string
|
||||||
public function hasHeader($name): bool { return false; }
|
{
|
||||||
public function getHeader($name): array { return []; }
|
return '1.1';
|
||||||
public function getHeaderLine($name): string { return ''; }
|
}
|
||||||
public function withHeader($name, $value): ServerRequestInterface { return $this; }
|
public function withProtocolVersion($version): ServerRequestInterface
|
||||||
public function withAddedHeader($name, $value): ServerRequestInterface { return $this; }
|
{
|
||||||
public function withoutHeader($name): ServerRequestInterface { return $this; }
|
return $this;
|
||||||
public function getBody(): \Psr\Http\Message\StreamInterface { return $this->createMockStream(); }
|
}
|
||||||
public function withBody(\Psr\Http\Message\StreamInterface $body): ServerRequestInterface { return $this; }
|
public function getHeaders(): array
|
||||||
public function getRequestTarget(): string { return $this->uri->getPath(); }
|
{
|
||||||
public function withRequestTarget($requestTarget): ServerRequestInterface { return $this; }
|
return [];
|
||||||
public function getMethod(): string { return $this->method; }
|
}
|
||||||
public function withMethod($method): ServerRequestInterface { return $this; }
|
public function hasHeader($name): bool
|
||||||
public function getUri(): UriInterface { return $this->uri; }
|
{
|
||||||
public function withUri(UriInterface $uri, $preserveHost = false): ServerRequestInterface { return $this; }
|
return false;
|
||||||
public function getServerParams(): array { return []; }
|
}
|
||||||
public function getCookieParams(): array { return []; }
|
public function getHeader($name): array
|
||||||
public function withCookieParams(array $cookies): ServerRequestInterface { return $this; }
|
{
|
||||||
public function getQueryParams(): array { return []; }
|
return [];
|
||||||
public function withQueryParams(array $query): ServerRequestInterface { return $this; }
|
}
|
||||||
public function getUploadedFiles(): array { return []; }
|
public function getHeaderLine($name): string
|
||||||
public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface { return $this; }
|
{
|
||||||
public function getParsedBody(): null|array|object { return null; }
|
return '';
|
||||||
public function withParsedBody($data): ServerRequestInterface { return $this; }
|
}
|
||||||
public function getAttributes(): array { return []; }
|
public function withHeader($name, $value): ServerRequestInterface
|
||||||
public function getAttribute($name, $default = null): mixed { return $default; }
|
{
|
||||||
public function withAttribute($name, $value): ServerRequestInterface { return $this; }
|
return $this;
|
||||||
public function withoutAttribute($name): ServerRequestInterface { return $this; }
|
}
|
||||||
|
public function withAddedHeader($name, $value): ServerRequestInterface
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function withoutHeader($name): ServerRequestInterface
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function getBody(): \Psr\Http\Message\StreamInterface
|
||||||
|
{
|
||||||
|
return $this->createMockStream();
|
||||||
|
}
|
||||||
|
public function withBody(\Psr\Http\Message\StreamInterface $body): ServerRequestInterface
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function getRequestTarget(): string
|
||||||
|
{
|
||||||
|
return $this->uri->getPath();
|
||||||
|
}
|
||||||
|
public function withRequestTarget($requestTarget): ServerRequestInterface
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function getMethod(): string
|
||||||
|
{
|
||||||
|
return $this->method;
|
||||||
|
}
|
||||||
|
public function withMethod($method): ServerRequestInterface
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function getUri(): UriInterface
|
||||||
|
{
|
||||||
|
return $this->uri;
|
||||||
|
}
|
||||||
|
public function withUri(UriInterface $uri, $preserveHost = false): ServerRequestInterface
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function getServerParams(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
public function getCookieParams(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
public function withCookieParams(array $cookies): ServerRequestInterface
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function getQueryParams(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
public function withQueryParams(array $query): ServerRequestInterface
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function getUploadedFiles(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function getParsedBody(): null|array|object
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public function withParsedBody($data): ServerRequestInterface
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function getAttributes(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
public function getAttribute($name, $default = null): mixed
|
||||||
|
{
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
public function withAttribute($name, $value): ServerRequestInterface
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function withoutAttribute($name): ServerRequestInterface
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
private function createMockStream() {
|
private function createMockStream()
|
||||||
|
{
|
||||||
return new class implements \Psr\Http\Message\StreamInterface {
|
return new class implements \Psr\Http\Message\StreamInterface {
|
||||||
public function __toString(): string { return ''; }
|
public function __toString(): string
|
||||||
public function close(): void {}
|
{
|
||||||
public function detach() { return null; }
|
return '';
|
||||||
public function getSize(): ?int { return 0; }
|
}
|
||||||
public function tell(): int { return 0; }
|
public function close(): void
|
||||||
public function eof(): bool { return true; }
|
{
|
||||||
public function isSeekable(): bool { return false; }
|
}
|
||||||
public function seek($offset, $whence = SEEK_SET): void {}
|
public function detach()
|
||||||
public function rewind(): void {}
|
{
|
||||||
public function isWritable(): bool { return false; }
|
return null;
|
||||||
public function write($string): int { return 0; }
|
}
|
||||||
public function isReadable(): bool { return true; }
|
public function getSize(): ?int
|
||||||
public function read($length): string { return ''; }
|
{
|
||||||
public function getContents(): string { return ''; }
|
return 0;
|
||||||
public function getMetadata($key = null) { return $key ? null : []; }
|
}
|
||||||
|
public function tell(): int
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
public function eof(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public function isSeekable(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public function seek($offset, $whence = SEEK_SET): void
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public function rewind(): void
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public function isWritable(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public function write($string): int
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
public function isReadable(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public function read($length): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
public function getContents(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
public function getMetadata($key = null)
|
||||||
|
{
|
||||||
|
return $key ? null : [];
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@ class Config implements ArrayAccess, IteratorAggregate
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private array $options
|
private array $options
|
||||||
) {}
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a configuration value by key.
|
* Retrieves a configuration value by key.
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@ class MatchResult implements \JsonSerializable
|
||||||
private readonly RouteDefinition|null $route = null,
|
private readonly RouteDefinition|null $route = null,
|
||||||
private readonly array $parameters = [],
|
private readonly array $parameters = [],
|
||||||
private readonly array $diagnostics = []
|
private readonly array $diagnostics = []
|
||||||
) {}
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
public function isFound(): bool
|
public function isFound(): bool
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,8 @@ class ModuleLoader
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly Config $config,
|
private readonly Config $config,
|
||||||
private readonly Router|RouteGroup $target
|
private readonly Router|RouteGroup $target
|
||||||
) {}
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads routes for a given module or modules.
|
* Loads routes for a given module or modules.
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,8 @@ final class Route
|
||||||
private readonly string $method,
|
private readonly string $method,
|
||||||
private readonly string $path,
|
private readonly string $path,
|
||||||
private readonly mixed $handler
|
private readonly mixed $handler
|
||||||
) {}
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the HTTP method of this route.
|
* Gets the HTTP method of this route.
|
||||||
|
|
|
||||||
|
|
@ -65,13 +65,29 @@ class RouteDefinition implements \JsonSerializable, \Serializable
|
||||||
private array $defaults = [],
|
private array $defaults = [],
|
||||||
private string|null $module = null,
|
private string|null $module = null,
|
||||||
private array $attributes = []
|
private array $attributes = []
|
||||||
) {}
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
public function getMethod(): string { return $this->method; }
|
public function getMethod(): string
|
||||||
public function getPattern(): string { return $this->pattern; }
|
{
|
||||||
public function getPath(): string { return $this->path; }
|
return $this->method;
|
||||||
public function getHandler(): mixed { return $this->handler; }
|
}
|
||||||
public function getName(): ?string { return $this->name; }
|
public function getPattern(): string
|
||||||
|
{
|
||||||
|
return $this->pattern;
|
||||||
|
}
|
||||||
|
public function getPath(): string
|
||||||
|
{
|
||||||
|
return $this->path;
|
||||||
|
}
|
||||||
|
public function getHandler(): mixed
|
||||||
|
{
|
||||||
|
return $this->handler;
|
||||||
|
}
|
||||||
|
public function getName(): ?string
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
public function name(string $name): self
|
public function name(string $name): self
|
||||||
{
|
{
|
||||||
|
|
@ -79,7 +95,10 @@ class RouteDefinition implements \JsonSerializable, \Serializable
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMiddleware(): array { return $this->middleware; }
|
public function getMiddleware(): array
|
||||||
|
{
|
||||||
|
return $this->middleware;
|
||||||
|
}
|
||||||
|
|
||||||
public function middleware(string|array $middleware): self
|
public function middleware(string|array $middleware): self
|
||||||
{
|
{
|
||||||
|
|
@ -91,7 +110,10 @@ class RouteDefinition implements \JsonSerializable, \Serializable
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getValidation(): array { return $this->validation; }
|
public function getValidation(): array
|
||||||
|
{
|
||||||
|
return $this->validation;
|
||||||
|
}
|
||||||
|
|
||||||
public function valid(array|string $param, array|string $rules = []): self
|
public function valid(array|string $param, array|string $rules = []): self
|
||||||
{
|
{
|
||||||
|
|
@ -105,7 +127,10 @@ class RouteDefinition implements \JsonSerializable, \Serializable
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDefaults(): array { return $this->defaults; }
|
public function getDefaults(): array
|
||||||
|
{
|
||||||
|
return $this->defaults;
|
||||||
|
}
|
||||||
|
|
||||||
public function default(string $param, mixed $value): self
|
public function default(string $param, mixed $value): self
|
||||||
{
|
{
|
||||||
|
|
@ -113,9 +138,15 @@ class RouteDefinition implements \JsonSerializable, \Serializable
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getModule(): ?string { return $this->module; }
|
public function getModule(): ?string
|
||||||
|
{
|
||||||
|
return $this->module;
|
||||||
|
}
|
||||||
|
|
||||||
public function getAttributes(): array { return $this->attributes; }
|
public function getAttributes(): array
|
||||||
|
{
|
||||||
|
return $this->attributes;
|
||||||
|
}
|
||||||
|
|
||||||
public function attr(string $key, mixed $value): self
|
public function attr(string $key, mixed $value): self
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@ class RouteGroup
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private array $options = [],
|
private array $options = [],
|
||||||
private readonly Router|null $router = null
|
private readonly Router|null $router = null
|
||||||
) {}
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new route group with options and router.
|
* Creates a new route group with options and router.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue