Skip to content

Commit

Permalink
Bleeding edge - detect stub file added multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 8, 2021
1 parent d586b93 commit 4a82eec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions conf/bleedingEdge.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ parameters:
unusedClassElements: true
readComposerPhpVersion: true
dateTimeInstantiation: true
detectDuplicateStubFiles: true
stubFiles:
- ../stubs/SplObjectStorage.stub
6 changes: 4 additions & 2 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ parameters:
unusedClassElements: false
readComposerPhpVersion: false
dateTimeInstantiation: false
detectDuplicateStubFiles: false
fileExtensions:
- php
checkAlwaysTrueCheckTypeFunctionCall: false
Expand Down Expand Up @@ -165,8 +166,9 @@ parametersSchema:
nullCoalesce: bool(),
fileWhitespace: bool(),
unusedClassElements: bool(),
readComposerPhpVersion: bool()
dateTimeInstantiation: bool()
readComposerPhpVersion: bool(),
dateTimeInstantiation: bool(),
detectDuplicateStubFiles: bool()
])
fileExtensions: listOf(string())
checkAlwaysTrueCheckTypeFunctionCall: bool()
Expand Down
12 changes: 12 additions & 0 deletions src/Command/CommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,19 @@ public static function begin(
throw new \PHPStan\Command\InceptionNotSuccessfulException();
}

$alreadyAddedStubFiles = [];
foreach ($container->getParameter('stubFiles') as $stubFile) {
if (
$container->getParameter('featureToggles')['detectDuplicateStubFiles']
&& array_key_exists($stubFile, $alreadyAddedStubFiles)
) {
$errorOutput->writeLineFormatted(sprintf('Stub file %s is added multiple times.', $stubFile));

throw new \PHPStan\Command\InceptionNotSuccessfulException();
}

$alreadyAddedStubFiles[$stubFile] = true;

if (is_file($stubFile)) {
continue;
}
Expand Down

0 comments on commit 4a82eec

Please sign in to comment.