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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.87",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^13.0",
"symfony/process": "^7.3 || ^8"
},
Expand Down
8 changes: 8 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon

parameters:
level: 8
tmpDir: var/phpstan
Expand All @@ -6,6 +9,11 @@ parameters:
- tests

reportUnmatchedIgnoredErrors: true
checkDynamicProperties: true
reportNonIntStringArrayKey: true
checkMissingOverrideMethodAttribute: true
checkStrictPrintfPlaceholderTypes: true

ignoreErrors:
- identifier: missingType.iterableValue
path: tests/*Test.php
5 changes: 5 additions & 0 deletions src/Console/Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ class GenerateCommand extends Command implements CommandFactoryInterface
private const string DESCRIPTION = 'Generate static site from specified routes';
private const string OPTION_SYMLINK = 'symlink';

#[\Override]
public static function name(): string
{
return self::NAME;
}

#[\Override]
public static function description(): string
{
return self::DESCRIPTION;
}

#[\Override]
public static function create(Kernel $kernel): self
{
$container = $kernel->container();
Expand Down Expand Up @@ -66,6 +69,7 @@ public function __construct(
parent::__construct(self::NAME);
}

#[\Override]
protected function configure(): void
{
$this
Expand All @@ -75,6 +79,7 @@ protected function configure(): void
;
}

#[\Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
$symlink = $input->getOption(self::OPTION_SYMLINK);
Expand Down
7 changes: 7 additions & 0 deletions src/Console/Command/ServerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ class ServerCommand extends Command implements CommandFactoryInterface

private ?Server $server = null;

#[\Override]
public static function name(): string
{
return self::NAME;
}

#[\Override]
public static function description(): string
{
return self::DESCRIPTION;
}

#[\Override]
public static function create(Kernel $kernel): self
{
$distribution = $kernel->distribution();
Expand All @@ -54,17 +57,20 @@ public function __construct(
}

/** @return array<int> */
#[\Override]
public function getSubscribedSignals(): array
{
return [2, 15]; // SIGINT, SIGTERM
}

#[\Override]
public function handleSignal(int $signal, int|false $previousExitCode = 0): int|false
{
$this->server?->stop();
return false;
}

#[\Override]
protected function configure(): void
{
$this
Expand All @@ -75,6 +81,7 @@ protected function configure(): void
;
}

#[\Override]
protected function execute(InputInterface $input, OutputInterface $output): int
{
if (!$this->distribution instanceof LocalDistributionInterface) {
Expand Down
3 changes: 3 additions & 0 deletions src/Console/CommandLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function __construct(
}
}

#[\Override]
public function get(string $name): Command
{
$factory = $this->map[$name] ?? null;
Expand All @@ -39,11 +40,13 @@ public function get(string $name): Command
return $this->createLazyCommand($factory);
}

#[\Override]
public function has(string $name): bool
{
return isset($this->map[$name]);
}

#[\Override]
public function getNames(): array
{
return array_keys($this->map);
Expand Down
1 change: 1 addition & 0 deletions src/EventDispatcher/RouterConfig/RouterConfigEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function __construct(
private readonly RouteSourceCollection $sources,
) {}

#[\Override]
public function accept(ListenerInterface $listener): bool
{
if (!$listener instanceof RouterConfigListenerInterface) {
Expand Down
1 change: 1 addition & 0 deletions src/EventDispatcher/RouterReady/RouterReadyEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function __construct(
private readonly iterable $routes,
) {}

#[\Override]
public function accept(ListenerInterface $listener): bool
{
if (!$listener instanceof RouterReadyListenerInterface) {
Expand Down
5 changes: 5 additions & 0 deletions src/Generator/Distribution/FilesystemDistribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ public function __construct(string $distPath, Filesystem $filesystem = new Files
$this->filesystem = $filesystem;
}

#[\Override]
public function path(): string
{
return $this->basePath;
}

#[\Override]
public function clear(): void
{
try {
Expand All @@ -48,6 +50,7 @@ public function clear(): void
}
}

#[\Override]
public function write(string $path, $content): void
{
$fullPath = $this->getFullPath($path);
Expand All @@ -61,6 +64,7 @@ public function write(string $path, $content): void
}
}

#[\Override]
public function copy(string $sourcePath, string $destinationPath): void
{
if (!file_exists($sourcePath)) {
Expand All @@ -85,6 +89,7 @@ public function copy(string $sourcePath, string $destinationPath): void
}
}

#[\Override]
public function link(string $sourcePath, string $destinationPath): void
{
if (!file_exists($sourcePath)) {
Expand Down
3 changes: 3 additions & 0 deletions src/Generator/SiteGeneratorVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function __construct(
}
}

#[\Override]
public function visitController(ControllerResource $resource): void
{
$controller = $this->getController($resource->reference);
Expand All @@ -40,6 +41,7 @@ public function visitController(ControllerResource $resource): void
$this->distribution->write($path, $content);
}

#[\Override]
public function visitFile(FileResource $resource): void
{
if ($this->symlinkFiles) {
Expand All @@ -64,6 +66,7 @@ private function getController(ControllerInterface|string|\Closure $reference):
return new class ($reference) implements ControllerInterface {
public function __construct(private \Closure $closure) {}

#[\Override]
public function render(Router $router, array $parameters)
{
return ($this->closure)($router, $parameters);
Expand Down
1 change: 1 addition & 0 deletions src/Router/Compiler/CompiledRouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function add(CompiledRoute $route): self
/**
* @return \Generator<int, CompiledRoute>
*/
#[\Override]
public function getIterator(): \Traversable
{
return $this->all();
Expand Down
1 change: 1 addition & 0 deletions src/Router/Compiler/Resource/ControllerResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function __construct(
public array $parameters = [],
) {}

#[\Override]
public function accept(ResourceVisitorInterface $visitor): void
{
$visitor->visitController($this);
Expand Down
1 change: 1 addition & 0 deletions src/Router/Compiler/Resource/FileResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public function __construct(
public string $source,
) {}

#[\Override]
public function accept(ResourceVisitorInterface $visitor): void
{
$visitor->visitFile($this);
Expand Down
5 changes: 4 additions & 1 deletion src/Router/Compiler/RouteCompilerVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ public function __construct(
public readonly CompiledRouteCollection $routes = new CompiledRouteCollection(),
) {}

#[\Override]
public function visitRoute(Route $route): void
{
$canonicalPath = $this->getCanonicalPath($route->path);
$isFile = preg_match('/\.\w+$/', $canonicalPath);
$isFile = (bool) preg_match('/\.\w+$/', $canonicalPath);
$distPath = rtrim($canonicalPath) . ($isFile ? '' : '/index.html');
$type = new ControllerResource($route->controller, $route->parameters);
$name = $route->name;
Expand All @@ -38,6 +39,7 @@ public function visitRoute(Route $route): void
$this->routes->add($compiledRoute);
}

#[\Override]
public function visitGroup(Group $group): void
{
$path = $this->getCanonicalPath($group->path);
Expand All @@ -49,6 +51,7 @@ public function visitGroup(Group $group): void
}
}

#[\Override]
public function visitAsset(Asset $asset): void
{
$canonicalPath = $this->getCanonicalPath($asset->path);
Expand Down
1 change: 1 addition & 0 deletions src/Router/Route/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function __construct(
public ?string $name = null,
) {}

#[\Override]
public function accept(RouteVisitorInterface $visitor): void
{
$visitor->visitAsset($this);
Expand Down
1 change: 1 addition & 0 deletions src/Router/Route/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function __construct(
public iterable|RouteProviderInterface|string $routes = [],
) {}

#[\Override]
public function accept(RouteVisitorInterface $visitor): void
{
$visitor->visitGroup($this);
Expand Down
1 change: 1 addition & 0 deletions src/Router/Route/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function __construct(
public array $parameters = [],
) {}

#[\Override]
public function accept(RouteVisitorInterface $visitor): void
{
$visitor->visitRoute($this);
Expand Down
1 change: 1 addition & 0 deletions src/Router/Source/RouteSourceCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function add(RouteSource $source): void
/**
* @return \Generator<int, RouteInterface>
*/
#[\Override]
public function getIterator(): \Generator
{
foreach ($this->sources as $source) {
Expand Down
4 changes: 2 additions & 2 deletions src/Server/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ private function validatePath(string $path): void

private function validateHost(string $host): void
{
if (filter_var($host, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)) {
if (filter_var($host, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) !== false) {
return;
}

if (filter_var($host, FILTER_VALIDATE_IP)) {
if (filter_var($host, FILTER_VALIDATE_IP) !== false) {
return;
}

Expand Down
2 changes: 2 additions & 0 deletions src/ServiceLocator/NoContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class NoContainer implements ContainerInterface
{
#[\Override]
public function get(string $id): never
{
throw new class ($id) extends LogicException implements NotFoundExceptionInterface {
Expand All @@ -27,6 +28,7 @@ public function __construct(string $id)
};
}

#[\Override]
public function has(string $id): bool
{
return false;
Expand Down
3 changes: 3 additions & 0 deletions tests/Doubles/Console/StubACommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ class StubACommand extends Command implements CommandFactoryInterface
{
private const string NAME = 'test:a';

#[\Override]
public static function name(): string
{
return self::NAME;
}

#[\Override]
public static function description(): string
{
return 'Test command A';
}

#[\Override]
public static function create(Kernel $kernel): Command
{
return new self(self::NAME);
Expand Down
3 changes: 3 additions & 0 deletions tests/Doubles/Console/StubBCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ class StubBCommand extends Command implements CommandFactoryInterface
{
private const string NAME = 'test:b';

#[\Override]
public static function name(): string
{
return self::NAME;
}

#[\Override]
public static function description(): string
{
return 'Test command B';
}

#[\Override]
public static function create(Kernel $kernel): Command
{
return new self(self::NAME);
Expand Down
1 change: 1 addition & 0 deletions tests/Doubles/EventDispatcher/AbstractMockEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ abstract class AbstractMockEvent implements EventInterface
/** @return class-string<AbstractMockListener> */
abstract public function listenerClass(): string;

#[\Override]
public function accept(ListenerInterface $listener): bool
{
$this->acceptedWith[] = $listener::class;
Expand Down
1 change: 1 addition & 0 deletions tests/Doubles/EventDispatcher/MockEventA.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

final class MockEventA extends AbstractMockEvent
{
#[\Override]
public function listenerClass(): string
{
return MockListenerA::class;
Expand Down
1 change: 1 addition & 0 deletions tests/Doubles/EventDispatcher/MockEventB.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

final class MockEventB extends AbstractMockEvent
{
#[\Override]
public function listenerClass(): string
{
return MockListenerB::class;
Expand Down
Loading
Loading