Skip to content

Commit 4a82eec

Browse files
committed
Bleeding edge - detect stub file added multiple times
1 parent d586b93 commit 4a82eec

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

conf/bleedingEdge.neon

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ parameters:
88
unusedClassElements: true
99
readComposerPhpVersion: true
1010
dateTimeInstantiation: true
11+
detectDuplicateStubFiles: true
1112
stubFiles:
1213
- ../stubs/SplObjectStorage.stub

conf/config.neon

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ parameters:
2121
unusedClassElements: false
2222
readComposerPhpVersion: false
2323
dateTimeInstantiation: false
24+
detectDuplicateStubFiles: false
2425
fileExtensions:
2526
- php
2627
checkAlwaysTrueCheckTypeFunctionCall: false
@@ -165,8 +166,9 @@ parametersSchema:
165166
nullCoalesce: bool(),
166167
fileWhitespace: bool(),
167168
unusedClassElements: bool(),
168-
readComposerPhpVersion: bool()
169-
dateTimeInstantiation: bool()
169+
readComposerPhpVersion: bool(),
170+
dateTimeInstantiation: bool(),
171+
detectDuplicateStubFiles: bool()
170172
])
171173
fileExtensions: listOf(string())
172174
checkAlwaysTrueCheckTypeFunctionCall: bool()

src/Command/CommandHelper.php

+12
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,19 @@ public static function begin(
385385
throw new \PHPStan\Command\InceptionNotSuccessfulException();
386386
}
387387

388+
$alreadyAddedStubFiles = [];
388389
foreach ($container->getParameter('stubFiles') as $stubFile) {
390+
if (
391+
$container->getParameter('featureToggles')['detectDuplicateStubFiles']
392+
&& array_key_exists($stubFile, $alreadyAddedStubFiles)
393+
) {
394+
$errorOutput->writeLineFormatted(sprintf('Stub file %s is added multiple times.', $stubFile));
395+
396+
throw new \PHPStan\Command\InceptionNotSuccessfulException();
397+
}
398+
399+
$alreadyAddedStubFiles[$stubFile] = true;
400+
389401
if (is_file($stubFile)) {
390402
continue;
391403
}

0 commit comments

Comments
 (0)