Skip to content

Commit 99c831c

Browse files
committed
[BE] Detect duplicate stub classes and functions
1 parent 739cb8d commit 99c831c

File tree

5 files changed

+7
-14
lines changed

5 files changed

+7
-14
lines changed

changelog-2.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ Bleeding edge (TODO move to other sections)
5151
* Report `instanceof` of classes covered by backward compatibility promise but where the assumption might change (https://github.com/phpstan/phpstan-src/commit/996bc69fa977aa64f601bd82b8a0ae39be0cbeef)
5252
* Add `@readonly` rule that disallows default values ([#1391](https://github.com/phpstan/phpstan-src/pull/1391)), thanks @herndlm!
5353
* MissingMagicSerializationMethodsRule ([#1711](https://github.com/phpstan/phpstan-src/pull/1711)), #7482, thanks @staabm!
54-
* Stub files validation - detect duplicate classes and functions (https://github.com/phpstan/phpstan-src/commit/ddf8d5c3859c2c75c20f525a0e2ca8b99032373a, https://github.com/phpstan/phpstan-src/commit/17e4b74335e5235d7cd6708eb687a774a0eeead4)
5554
* Change `curl_setopt` function signature based on 2nd arg ([#1719](https://github.com/phpstan/phpstan-src/pull/1719)), thanks @staabm!
5655
* Empty `skipCheckGenericClasses` (https://github.com/phpstan/phpstan-src/commit/28c2c79b16cac6ba6b01f1b4d211541dd49d8a77)
5756
* Validate inline PHPDoc `@var` tag type against native type (https://github.com/phpstan/phpstan-src/commit/a69e3bc2f1e87f6da1e65d7935f1cc36bd5c42fe)
@@ -128,6 +127,7 @@ Improvements 🔧
128127
* Stricter ++/-- operator check ([#3255](https://github.com/phpstan/phpstan-src/pull/3255)), thanks @schlndh!
129128
* Check mixed in binary operator ([#3231](https://github.com/phpstan/phpstan-src/pull/3231)), #7538, #10440, thanks @schlndh!
130129
* Check mixed in unary operator ([#3253](https://github.com/phpstan/phpstan-src/pull/3253)), thanks @schlndh!
130+
* Stub files validation - detect duplicate classes and functions (https://github.com/phpstan/phpstan-src/commit/ddf8d5c3859c2c75c20f525a0e2ca8b99032373a, https://github.com/phpstan/phpstan-src/commit/17e4b74335e5235d7cd6708eb687a774a0eeead4)
131131

132132
Bugfixes 🐛
133133
=====================

conf/bleedingEdge.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ parameters:
2222
nullContextForVoidReturningFunctions: true
2323
unescapeStrings: true
2424
alwaysCheckTooWideReturnTypeFinalMethods: true
25-
duplicateStubs: true
2625
logicalXor: true
2726
betterNoop: true
2827
alwaysTrueAlwaysReported: true

conf/config.neon

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ parameters:
4343
nullContextForVoidReturningFunctions: false
4444
unescapeStrings: false
4545
alwaysCheckTooWideReturnTypeFinalMethods: false
46-
duplicateStubs: false
4746
logicalXor: false
4847
betterNoop: false
4948
alwaysTrueAlwaysReported: false
@@ -426,8 +425,6 @@ services:
426425

427426
-
428427
class: PHPStan\PhpDoc\StubValidator
429-
arguments:
430-
duplicateStubs: %featureToggles.duplicateStubs%
431428

432429
-
433430
class: PHPStan\PhpDoc\SocketSelectStubFilesExtension

conf/parametersSchema.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ parametersSchema:
4949
nullContextForVoidReturningFunctions: bool()
5050
unescapeStrings: bool()
5151
alwaysCheckTooWideReturnTypeFinalMethods: bool()
52-
duplicateStubs: bool()
5352
logicalXor: bool()
5453
betterNoop: bool()
5554
alwaysTrueAlwaysReported: bool()

src/PhpDoc/StubValidator.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ final class StubValidator
9595

9696
public function __construct(
9797
private DerivativeContainerFactory $derivativeContainerFactory,
98-
private bool $duplicateStubs,
9998
)
10099
{
101100
}
@@ -188,6 +187,8 @@ private function getRuleRegistry(Container $container): RuleRegistry
188187
$mixinCheck = $container->getByType(MixinCheck::class);
189188
$methodTagCheck = new MethodTagCheck($reflectionProvider, $classNameCheck, $genericObjectTypeCheck, $missingTypehintCheck, $unresolvableTypeHelper, true, true);
190189
$propertyTagCheck = new PropertyTagCheck($reflectionProvider, $classNameCheck, $genericObjectTypeCheck, $missingTypehintCheck, $unresolvableTypeHelper, true, true);
190+
$reflector = $container->getService('stubReflector');
191+
$relativePathHelper = $container->getService('simpleRelativePathHelper');
191192

192193
$rules = [
193194
// level 0
@@ -247,14 +248,11 @@ private function getRuleRegistry(Container $container): RuleRegistry
247248
new MissingMethodReturnTypehintRule($missingTypehintCheck),
248249
new MissingPropertyTypehintRule($missingTypehintCheck),
249250
new MissingMethodSelfOutTypeRule($missingTypehintCheck),
250-
];
251251

252-
if ($this->duplicateStubs) {
253-
$reflector = $container->getService('stubReflector');
254-
$relativePathHelper = $container->getService('simpleRelativePathHelper');
255-
$rules[] = new DuplicateClassDeclarationRule($reflector, $relativePathHelper);
256-
$rules[] = new DuplicateFunctionDeclarationRule($reflector, $relativePathHelper);
257-
}
252+
// duplicate stubs
253+
new DuplicateClassDeclarationRule($reflector, $relativePathHelper),
254+
new DuplicateFunctionDeclarationRule($reflector, $relativePathHelper),
255+
];
258256

259257
return new DirectRuleRegistry($rules);
260258
}

0 commit comments

Comments
 (0)