Skip to content

Commit 2b2ae37

Browse files
Fix build (#121)
* Fixed compatibility with latest phpstan * Require nikic/php-parser * Fix RuleTestCase Co-authored-by: Josef Kříž <[email protected]>
1 parent d206fb4 commit 2b2ae37

File tree

3 files changed

+45
-30
lines changed

3 files changed

+45
-30
lines changed

composer.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
},
1919
"require": {
2020
"php": "^7.1",
21-
"phpstan/phpstan": "^0.12.0"
21+
"nikic/php-parser": "^4.4",
22+
"phpstan/phpstan": "^0.12.18"
2223
},
2324
"require-dev": {
24-
"jakub-onderka/php-console-highlighter": "0.4.0",
25-
"jakub-onderka/php-parallel-lint": "1.0.0",
2625
"nette/utils": "^3.0",
2726
"php-coveralls/php-coveralls": "^2.1",
28-
"phpstan/phpstan": "^0.12.0",
27+
"php-parallel-lint/php-console-highlighter": "^0.4.0",
28+
"php-parallel-lint/php-parallel-lint": "^1.2.0",
29+
"phpstan/phpstan": "^0.12.18",
2930
"phpstan/phpstan-nette": "^0.12.0",
3031
"phpstan/phpstan-phpunit": "^0.12.0",
3132
"phpstan/phpstan-strict-rules": "^0.12.0",
@@ -58,7 +59,7 @@
5859
"check:tests": "phpunit --coverage-text",
5960
"check:cs": "phpcs --extensions=php --encoding=utf-8 --tab-width=4 --colors --ignore=tests/*/data -sp src tests/src",
6061
"check:lint": "parallel-lint src tests/src",
61-
"check:types": "phpstan analyse -l max src tests",
62+
"check:types": "phpstan analyse --memory-limit=1G -l max src tests",
6263
"fix": "@fix:cs",
6364
"fix:cs": "phpcbf --extensions=php --encoding=utf-8 --tab-width=4 --colors --ignore=tests/*/data -sp src tests/src",
6465
"coveralls": "php-coveralls -v"

phpstan.neon.dist

-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ parameters:
1414

1515
ignoreErrors:
1616
- "#^Method Pepakriz\\\\PHPStanExceptionRules\\\\RuleTestCase\\:\\:getRule\\(\\) return type with generic interface PHPStan\\\\Rules\\\\Rule does not specify its types\\: TNodeType$#"
17-
-
18-
message: "#^Parameter \\#1 \\$rules of class PHPStan\\\\Rules\\\\Registry constructor expects array\\<PHPStan\\\\Rules\\\\Rule\\>, array\\<int, TRule of PHPStan\\\\Rules\\\\Rule\\> given\\.$#"
19-
count: 1
20-
path: tests/src/RuleTestCase.php
2117

2218
exceptionRules:
2319
reportUnusedCatchesOfUncheckedExceptions: true

tests/src/RuleTestCase.php

+39-21
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
use PhpParser\PrettyPrinter\Standard;
99
use PHPStan\Analyser\Analyser;
1010
use PHPStan\Analyser\Error;
11+
use PHPStan\Analyser\FileAnalyser;
1112
use PHPStan\Analyser\NodeScopeResolver;
1213
use PHPStan\Analyser\TypeSpecifier;
1314
use PHPStan\Broker\AnonymousClassNameHelper;
1415
use PHPStan\Cache\Cache;
16+
use PHPStan\Dependency\DependencyResolver;
1517
use PHPStan\File\FileHelper;
16-
use PHPStan\File\FuzzyRelativePathHelper;
18+
use PHPStan\File\SimpleRelativePathHelper;
1719
use PHPStan\PhpDoc\PhpDocNodeResolver;
1820
use PHPStan\PhpDoc\PhpDocStringResolver;
1921
use PHPStan\PhpDoc\TypeNodeResolverExtension;
@@ -31,7 +33,6 @@
3133
use function implode;
3234
use function sprintf;
3335
use function trim;
34-
use const DIRECTORY_SEPARATOR;
3536

3637
/**
3738
* @template TRule of \PHPStan\Rules\Rule
@@ -72,38 +73,50 @@ private function getAnalyser(): Analyser
7273
{
7374
if ($this->analyser === null) {
7475
$registry = new Registry([$this->getRule()]);
75-
7676
$broker = $this->createBroker();
7777
$printer = new Standard();
78-
$fileHelper = $this->getFileHelper();
78+
79+
$currentWorkingDirectory = $this->getCurrentWorkingDirectory();
80+
$fileHelper = new FileHelper($currentWorkingDirectory);
81+
$relativePathHelper = new SimpleRelativePathHelper($currentWorkingDirectory);
82+
$anonymousClassNameHelper = new AnonymousClassNameHelper($fileHelper, $relativePathHelper);
83+
7984
$typeSpecifier = $this->createTypeSpecifier(
8085
$printer,
8186
$broker,
8287
$this->getMethodTypeSpecifyingExtensions(),
8388
$this->getStaticMethodTypeSpecifyingExtensions()
8489
);
85-
$currentWorkingDirectory = $this->getCurrentWorkingDirectory();
86-
$this->analyser = new Analyser(
87-
$this->createScopeFactory($broker, $typeSpecifier),
90+
91+
$nodeScopeResolver = new NodeScopeResolver(
92+
$broker,
8893
$this->getParser(),
89-
$registry,
90-
new NodeScopeResolver(
91-
$broker,
94+
new FileTypeMapper(
9295
$this->getParser(),
93-
new FileTypeMapper($this->getParser(), self::getContainer()->getByType(PhpDocStringResolver::class), self::getContainer()->getByType(PhpDocNodeResolver::class), $this->createMock(Cache::class), new AnonymousClassNameHelper(new FileHelper($currentWorkingDirectory), new FuzzyRelativePathHelper($currentWorkingDirectory, DIRECTORY_SEPARATOR, []))),
94-
$fileHelper,
95-
$typeSpecifier,
96-
$this->shouldPolluteScopeWithLoopInitialAssignments(),
97-
$this->shouldPolluteCatchScopeWithTryAssignments(),
98-
$this->shouldPolluteScopeWithAlwaysIterableForeach(),
99-
[],
100-
[]
96+
self::getContainer()->getByType(PhpDocStringResolver::class),
97+
self::getContainer()->getByType(PhpDocNodeResolver::class),
98+
$this->createMock(Cache::class),
99+
$anonymousClassNameHelper
101100
),
102101
$fileHelper,
102+
$typeSpecifier,
103+
$this->shouldPolluteScopeWithLoopInitialAssignments(),
104+
$this->shouldPolluteCatchScopeWithTryAssignments(),
105+
$this->shouldPolluteScopeWithAlwaysIterableForeach(),
103106
[],
104-
true,
105-
50
107+
[]
106108
);
109+
110+
$fileAnalyser = new FileAnalyser(
111+
$this->createScopeFactory($broker, $typeSpecifier),
112+
$nodeScopeResolver,
113+
$this->getParser(),
114+
new DependencyResolver($broker),
115+
$fileHelper,
116+
$this->shouldReportUnmatchedIgnoredErrors()
117+
);
118+
119+
$this->analyser = new Analyser($fileAnalyser, $registry, $nodeScopeResolver, 50);
107120
}
108121

109122
return $this->analyser;
@@ -137,7 +150,7 @@ public function analyse(string $file): void
137150
{
138151
$file = $this->getFileHelper()->normalizePath($file);
139152
$expectedErrors = $this->parseExpectedErrors($file);
140-
$actualErrors = $this->getAnalyser()->analyse([$file], false);
153+
$actualErrors = $this->getAnalyser()->analyse([$file])->getUnorderedErrors();
141154

142155
$strictlyTypedSprintf = static function (int $line, string $message): string {
143156
return sprintf('%02d: %s', $line, $message);
@@ -210,4 +223,9 @@ protected function shouldPolluteScopeWithAlwaysIterableForeach(): bool
210223
return false;
211224
}
212225

226+
protected function shouldReportUnmatchedIgnoredErrors(): bool
227+
{
228+
return true;
229+
}
230+
213231
}

0 commit comments

Comments
 (0)