Skip to content

Commit 9e108b2

Browse files
committed
Analyze autoloader and phpunit-hack file
1 parent 5dd03e4 commit 9e108b2

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

.github/workflows/php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
- name: "PHPCS"
5050
run: "php vendor/bin/phpcs src"
5151
- name: "PHPStan"
52-
run: "php vendor/bin/phpstan analyze src"
52+
run: "php vendor/bin/phpstan analyze"
5353
- name: "PHPUnit"
5454
run: "php vendor/bin/phpunit --debug"
5555

drupal-autoloader.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
use mglaman\PHPStanDrupal\Drupal\DrupalAutoloader;
44
use PHPStan\DependencyInjection\Container;
55

6-
assert($container instanceof Container);
7-
if ($container === NULL && !($container instanceof Container)) {
6+
if (!isset($container)) {
7+
throw new \PHPStan\ShouldNotHappenException('The autoloader did not receive the container.');
8+
}
9+
if (!$container instanceof Container) {
810
throw new \PHPStan\ShouldNotHappenException('The autoloader did not receive the container.');
911
}
1012

drupal-phpunit-hack.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@
1919

2020
// Inspired by Symfony's simple-phpunit remove typehints from TestCase.
2121
$alteredFile = $autoloader->findFile('PHPUnit\Framework\TestCase');
22+
if ($alteredFile === false) {
23+
return;
24+
}
2225
$phpunit_dir = dirname($alteredFile, 3);
2326
// Mutate TestCase code to make it compatible with Drupal 8 and 9 tests.
2427
$alteredCode = file_get_contents($alteredFile);
28+
if ($alteredCode === false) {
29+
throw new \PHPStan\ShouldNotHappenException("Found $alteredFile but could not get its contents to fix return types.");
30+
}
2531
$alteredCode = preg_replace('/^ ((?:protected|public)(?: static)? function \w+\(\)): void/m', ' $1', $alteredCode);
32+
assert($alteredCode !== null);
2633
$alteredCode = str_replace("__DIR__ . '/../Util/", "'$phpunit_dir/src/Util/", $alteredCode);
2734
// Only write when necessary.
2835
$filename = __DIR__ . '/tests/fixtures/TestCase.php';

phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ parameters:
55
level: 8
66
checkGenericClassInNonGenericObjectType: false
77
checkMissingIterableValueType: false
8+
paths:
9+
- src
10+
- drupal-phpunit-hack.php
11+
- drupal-autoloader.php

0 commit comments

Comments
 (0)