Skip to content

Commit efb6ae9

Browse files
committed
misc
1 parent 3adffe1 commit efb6ae9

5 files changed

Lines changed: 51 additions & 55 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"composer/xdebug-handler": "^3.0.5",
1919
"entropy/entropy": "^0.4",
2020
"fidry/cpu-core-counter": "^1.3",
21-
"friendsofphp/php-cs-fixer": "^3.95.5",
21+
"friendsofphp/php-cs-fixer": "^3.95.10",
2222
"nette/utils": "^4.1",
2323
"react/child-process": "^0.6.7",
2424
"react/event-loop": "^1.6",

phpstan.neon

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
parameters:
22
level: 8
33

4-
# reportUnmatchedIgnoredErrors: false
5-
6-
# requires exact closure types
7-
checkMissingCallableSignature: true
8-
9-
# symplify - see https://github.com/symplify/phpstan-rules#usage
10-
symplify:
11-
pathStrings: true
12-
134
paths:
145
- packages
156
- src
@@ -23,6 +14,10 @@ parameters:
2314
- '*/Source/*'
2415
- '*/Fixture/*'
2516

17+
# see https://github.com/symplify/phpstan-rules#usage
18+
symplify:
19+
pathStrings: true
20+
2621
# see https://github.com/tomasVotruba/unused-public
2722
unused_public:
2823
methods: true
@@ -32,23 +27,16 @@ parameters:
3227
# see https://github.com/TomasVotruba/type-coverage
3328
type_coverage:
3429
return: 99
35-
param: 94.4
30+
param: 99
3631
property: 99
3732

3833
bootstrapFiles:
3934
- tests/bootstrap.php
4035

41-
treatPhpDocTypesAsCertain: true
36+
treatPhpDocTypesAsCertain: false
4237

4338
ignoreErrors:
44-
# set above
45-
-
46-
path: src/Parallel/Application/ParallelFileProcessor.php
47-
message: '#Cannot call method (.*?)\(\) on Symplify\\EasyCodingStandard\\Parallel\\ValueObject\\ProcessPool\|null#'
48-
49-
- '#Method Symplify\\EasyCodingStandard\\Application\\SingleFileProcessor\:\:processFilePath\(\) should return array\{file_diffs\?\: array<Symplify\\EasyCodingStandard\\ValueObject\\Error\\FileDiff>, coding_standard_errors\?\: array<Symplify\\EasyCodingStandard\\SniffRunner\\ValueObject\\Error\\CodingStandardError>\} but returns array<(.*?), array<Symplify\\EasyCodingStandard\\SniffRunner\\ValueObject\\Error\\CodingStandardError\|Symplify\\EasyCodingStandard\\ValueObject\\Error\\FileDiff>>#'
50-
51-
# false positive on custom config tets
39+
# on purpose to override a config
5240
-
5341
message: '#Missing call to parent\:\:setUp\(\) method#'
5442
paths:
@@ -65,10 +53,6 @@ parameters:
6553
# overly detailed
6654
- '#PHPDoc tag @var with type string\|false is not subtype of native type non\-empty\-string\|false#'
6755

68-
# array validation on purpose
69-
- '#Call to static method Webmozart\\Assert\\Assert\:\:allString\(\) with (non-empty-array|list|array)<string> will always evaluate to true#'
70-
- '#Call to static method Webmozart\\Assert\\Assert\:\:allIsArray\(\) with array<class\-string<PHP_CodeSniffer\\Sniffs\\Sniff\|PhpCsFixer\\Fixer\\FixerInterface>, array<mixed>> will always evaluate to true#'
71-
7256
# hack to autoload contants
7357
- '#Call to new PHP_CodeSniffer\\Util\\Tokens\(\) on a separate line has no effect#'
7458

@@ -77,11 +61,6 @@ parameters:
7761
identifier: smaller.alwaysFalse
7862
path: src/Configuration/ConfigInitializer.php
7963

80-
# false positive
81-
-
82-
identifier: offsetAssign.dimType
83-
path: src/Console/Output/JsonOutputFormatter.php
84-
8564
# coding-standard: runtime-defined PHP_CodeSniffer/php-cs-fixer token constants
8665
- '#Constant T_OPEN_CURLY_BRACKET|T_START_NOWDOC not found#'
8766

@@ -92,8 +71,3 @@ parameters:
9271
-
9372
message: '#Comparison operation ">\=" between int<\d+, \d+> and (.*?) is always true#'
9473
path: packages/coding-standard/src/TokenAnalyzer/DocblockRelatedParamNamesResolver.php
95-
96-
# coding-standard: intentional null removal
97-
-
98-
message: '#Parameter \#1 \$array \(array<int, PhpCsFixer\\Tokenizer\\Token>\) to function array_filter does not contain falsy values, the array will always stay the same#'
99-
path: packages/coding-standard/src/TokenRunner/Traverser/TokenReverser.php

src/Application/SingleFileProcessor.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public function processFilePath(string $filePath, Configuration $configuration):
2828
return [];
2929
}
3030

31-
$errorsAndDiffs = [];
31+
$fileDiffs = [];
32+
$codingStandardErrors = [];
3233

3334
$this->changedFilesDetector->addFilePath($filePath);
3435
$fileProcessors = $this->fileProcessorCollector->getFileProcessors();
@@ -43,14 +44,27 @@ public function processFilePath(string $filePath, Configuration $configuration):
4344
continue;
4445
}
4546

46-
$errorsAndDiffs = [...$errorsAndDiffs, ...$currentErrorsAndFileDiffs];
47+
$fileDiffs = [...$fileDiffs, ...($currentErrorsAndFileDiffs['file_diffs'] ?? [])];
48+
$codingStandardErrors = [
49+
...$codingStandardErrors,
50+
...($currentErrorsAndFileDiffs['coding_standard_errors'] ?? []),
51+
];
4752
}
4853

4954
// invalidate broken file, to analyse in next run too
50-
if ($errorsAndDiffs !== []) {
55+
if ($fileDiffs !== [] || $codingStandardErrors !== []) {
5156
$this->changedFilesDetector->invalidateFilePath($filePath);
5257
}
5358

59+
$errorsAndDiffs = [];
60+
if ($fileDiffs !== []) {
61+
$errorsAndDiffs['file_diffs'] = $fileDiffs;
62+
}
63+
64+
if ($codingStandardErrors !== []) {
65+
$errorsAndDiffs['coding_standard_errors'] = $codingStandardErrors;
66+
}
67+
5468
return $errorsAndDiffs;
5569
}
5670
}

src/Console/Output/JsonOutputFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function createJsonContent(ErrorAndDiffResult $errorAndDiffResult, bool $
7676
}
7777

7878
/**
79-
* @return array{totals: array{errors: int, diffs: int}, files: string[]}
79+
* @return array{totals: array{errors: int, diffs: int}, files: array<string, array<string, list<array<string, mixed>>>>}
8080
*/
8181
private function createBaseErrorsJson(ErrorAndDiffResult $errorAndDiffResult): array
8282
{

src/Parallel/Application/ParallelFileProcessor.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@
3434
*
3535
* https://github.com/phpstan/phpstan-src/commit/b84acd2e3eadf66189a64fdbc6dd18ff76323f67#diff-7f625777f1ce5384046df08abffd6c911cfbb1cfc8fcb2bdeaf78f337689e3e2R150
3636
*/
37-
final class ParallelFileProcessor
37+
final readonly class ParallelFileProcessor
3838
{
3939
private const int SYSTEM_ERROR_LIMIT = 50;
4040

41-
private ProcessPool|null $processPool = null;
42-
4341
public function __construct(
44-
private readonly WorkerCommandLineFactory $workerCommandLineFactory,
42+
private WorkerCommandLineFactory $workerCommandLineFactory,
4543
) {
4644
}
4745

@@ -70,24 +68,32 @@ public function check(
7068
$systemErrors = [];
7169

7270
$tcpServer = new TcpServer('127.0.0.1:0', $streamSelectLoop);
73-
$this->processPool = new ProcessPool($tcpServer);
71+
$processPool = new ProcessPool($tcpServer);
7472

75-
$tcpServer->on(ReactEvent::CONNECTION, function (ConnectionInterface $connection) use (&$jobs): void {
73+
$tcpServer->on(ReactEvent::CONNECTION, function (ConnectionInterface $connection) use (
74+
&$jobs,
75+
$processPool
76+
): void {
7677
$inDecoder = new Decoder($connection, true, 512, 0, 4 * 1024 * 1024);
7778
$outEncoder = new Encoder($connection);
7879

79-
$inDecoder->on(ReactEvent::DATA, function (array $data) use (&$jobs, $inDecoder, $outEncoder): void {
80+
$inDecoder->on(ReactEvent::DATA, function (array $data) use (
81+
&$jobs,
82+
$inDecoder,
83+
$outEncoder,
84+
$processPool
85+
): void {
8086
$action = $data[ReactCommand::ACTION];
8187
if ($action !== Action::HELLO) {
8288
return;
8389
}
8490

8591
$processIdentifier = $data[Option::PARALLEL_IDENTIFIER];
86-
$parallelProcess = $this->processPool->getProcess($processIdentifier);
92+
$parallelProcess = $processPool->getProcess($processIdentifier);
8793
$parallelProcess->bindConnection($inDecoder, $outEncoder);
8894

8995
if ($jobs === []) {
90-
$this->processPool->quitProcess($processIdentifier);
96+
$processPool->quitProcess($processIdentifier);
9197
return;
9298
}
9399

@@ -112,13 +118,14 @@ public function check(
112118
$handleErrorCallable = function (Throwable $throwable) use (
113119
&$systemErrors,
114120
&$systemErrorsCount,
115-
&$reachedSystemErrorsCountLimit
121+
&$reachedSystemErrorsCountLimit,
122+
$processPool
116123
): void {
117124
$systemErrors[] = new SystemError($throwable->getLine(), $throwable->getMessage(), $throwable->getFile());
118125

119126
++$systemErrorsCount;
120127
$reachedSystemErrorsCountLimit = true;
121-
$this->processPool->quitAll();
128+
$processPool->quitAll();
122129
};
123130

124131
$timeoutInSeconds = SimpleParameterProvider::getIntParameter(Option::PARALLEL_TIMEOUT_IN_SECONDS);
@@ -161,7 +168,8 @@ function (array $json) use (
161168
$postFileCallback,
162169
&$systemErrorsCount,
163170
&$reachedInternalErrorsCountLimit,
164-
$processIdentifier
171+
$processIdentifier,
172+
$processPool
165173
): void {
166174
// decode arrays to objects
167175
foreach ($json[Bridge::SYSTEM_ERRORS] as $jsonError) {
@@ -186,11 +194,11 @@ function (array $json) use (
186194
$systemErrorsCount += $json[Bridge::SYSTEM_ERRORS_COUNT];
187195
if ($systemErrorsCount >= self::SYSTEM_ERROR_LIMIT) {
188196
$reachedInternalErrorsCountLimit = true;
189-
$this->processPool->quitAll();
197+
$processPool->quitAll();
190198
}
191199

192200
if ($jobs === []) {
193-
$this->processPool->quitProcess($processIdentifier);
201+
$processPool->quitProcess($processIdentifier);
194202
return;
195203
}
196204

@@ -205,8 +213,8 @@ function (array $json) use (
205213
$handleErrorCallable,
206214

207215
// 3. callable on exit
208-
function ($exitCode, string $stdErr) use (&$systemErrors, $processIdentifier): void {
209-
$this->processPool->tryQuitProcess($processIdentifier);
216+
function ($exitCode, string $stdErr) use (&$systemErrors, $processIdentifier, $processPool): void {
217+
$processPool->tryQuitProcess($processIdentifier);
210218
if ($exitCode === ExitCode::SUCCESS) {
211219
return;
212220
}
@@ -219,7 +227,7 @@ function ($exitCode, string $stdErr) use (&$systemErrors, $processIdentifier): v
219227
}
220228
);
221229

222-
$this->processPool->attachProcess($processIdentifier, $parallelProcess);
230+
$processPool->attachProcess($processIdentifier, $parallelProcess);
223231
}
224232

225233
$streamSelectLoop->run();

0 commit comments

Comments
 (0)