Skip to content

Commit 83efbcb

Browse files
committed
add strict rules for phpstan
1 parent a73e551 commit 83efbcb

15 files changed

Lines changed: 30 additions & 22 deletions

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"require-dev": {
2020
"friendsofphp/php-cs-fixer": "^3.87",
2121
"phpstan/phpstan": "^2.1",
22+
"phpstan/phpstan-strict-rules": "^2.0",
2223
"phpunit/phpunit": "^13.0",
2324
"symfony/process": "^7.3 || ^8"
2425
},

phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
includes:
2+
- vendor/phpstan/phpstan-strict-rules/rules.neon
3+
14
parameters:
25
level: 8
36
tmpDir: var/phpstan

src/Router/Compiler/RouteCompilerVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(
3030
public function visitRoute(Route $route): void
3131
{
3232
$canonicalPath = $this->getCanonicalPath($route->path);
33-
$isFile = preg_match('/\.\w+$/', $canonicalPath);
33+
$isFile = (bool) preg_match('/\.\w+$/', $canonicalPath);
3434
$distPath = rtrim($canonicalPath) . ($isFile ? '' : '/index.html');
3535
$type = new ControllerResource($route->controller, $route->parameters);
3636
$name = $route->name;

src/Server/Server.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ private function validatePath(string $path): void
139139

140140
private function validateHost(string $host): void
141141
{
142-
if (filter_var($host, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)) {
142+
if (filter_var($host, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) !== false) {
143143
return;
144144
}
145145

146-
if (filter_var($host, FILTER_VALIDATE_IP)) {
146+
if (filter_var($host, FILTER_VALIDATE_IP) !== false) {
147147
return;
148148
}
149149

tests/Functional/StasisProcessFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ public static function create(array $arguments = [], ?string $workdir = null): P
2121

2222
private static function getStasisPath(): string
2323
{
24-
/** @var string $kernelPath */
2524
$kernelPath = new \ReflectionClass(Kernel::class)->getFileName();
25+
26+
if ($kernelPath === false) {
27+
throw new \RuntimeException('Failed to get kernel path.');
28+
}
29+
2630
return dirname($kernelPath, 2) . '/bin/stasis';
2731
}
2832
}

tests/Unit/Console/ApplicationFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ApplicationFactoryTest extends TestCase
1212
{
1313
public function testCreateBuildsConfiguredApplication(): void
1414
{
15-
$kernel = $this->createStub(Kernel::class);
15+
$kernel = self::createStub(Kernel::class);
1616
$application = ApplicationFactory::create($kernel);
1717

1818
self::assertSame('Stasis', $application->getName(), 'Unexpected application name.');

tests/Unit/Console/Command/GenerateCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ class GenerateCommandTest extends TestCase
3131
#[\Override]
3232
public function setUp(): void
3333
{
34-
$this->kernel = $this->createStub(Kernel::class);
34+
$this->kernel = self::createStub(Kernel::class);
3535
$this->generator = $this->createMock(SiteGenerator::class);
3636
$this->compiler = $this->createMock(RouteCompiler::class);
3737
$this->routes = [];
38-
$this->stopwatch = $this->createStub(Stopwatch::class);
38+
$this->stopwatch = self::createStub(Stopwatch::class);
3939

4040
$this->command = new GenerateCommand(
4141
$this->generator,

tests/Unit/Console/Command/ServerCommandTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class ServerCommandTest extends TestCase
2727
#[\Override]
2828
public function setUp(): void
2929
{
30-
$this->kernel = $this->createStub(Kernel::class);
31-
$this->distribution = $this->createStub(LocalDistributionInterface::class);
32-
$this->serverFactory = $this->createStub(ServerFactory::class);
30+
$this->kernel = self::createStub(Kernel::class);
31+
$this->distribution = self::createStub(LocalDistributionInterface::class);
32+
$this->serverFactory = self::createStub(ServerFactory::class);
3333

3434
$this->command = new ServerCommand(
3535
$this->distribution,
@@ -172,8 +172,8 @@ public function testExecuteVerbose(): void
172172
public function testUnsupportedDistribution(): void
173173
{
174174
// plain distribution (not local) should fail
175-
$distribution = $this->createStub(DistributionInterface::class);
176-
$factory = $this->createStub(ServerFactory::class);
175+
$distribution = self::createStub(DistributionInterface::class);
176+
$factory = self::createStub(ServerFactory::class);
177177
$command = new ServerCommand($distribution, $factory);
178178

179179
$tester = new CommandTester($command);

tests/Unit/Console/CommandLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CommandLoaderTest extends TestCase
2222
#[\Override]
2323
public function setUp(): void
2424
{
25-
$this->kernel = $this->createStub(Kernel::class);
25+
$this->kernel = self::createStub(Kernel::class);
2626
$this->loader = new CommandLoader($this->kernel, [
2727
StubACommand::class,
2828
StubBCommand::class,

tests/Unit/EventDispatcher/EventTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function testAcceptMatchingListener(): void
3939
public function testAcceptNonMatchingListener(): void
4040
{
4141
$event = $this->getEvent();
42-
$listener = $this->createStub(ListenerInterface::class);
42+
$listener = self::createStub(ListenerInterface::class);
4343
$isAccepted = $event->accept($listener);
4444
self::assertFalse($isAccepted, 'Event should not be accepted by a non-matching listener.');
4545
}

0 commit comments

Comments
 (0)