Skip to content

Commit 375f68e

Browse files
herndlmondrejmirtes
authored andcommitted
Allow togging discoveringSymbols tip
1 parent 9a0bfd2 commit 375f68e

File tree

123 files changed

+414
-184
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+414
-184
lines changed

conf/config.level0.neon

+45-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ rules:
2727
- PHPStan\Rules\Classes\ClassConstantRule
2828
- PHPStan\Rules\Classes\DuplicateDeclarationRule
2929
- PHPStan\Rules\Classes\EnumSanityRule
30-
- PHPStan\Rules\Classes\ExistingClassesInClassImplementsRule
31-
- PHPStan\Rules\Classes\ExistingClassesInEnumImplementsRule
32-
- PHPStan\Rules\Classes\ExistingClassesInInterfaceExtendsRule
33-
- PHPStan\Rules\Classes\ExistingClassInTraitUseRule
34-
- PHPStan\Rules\Classes\InstantiationRule
3530
- PHPStan\Rules\Classes\InstantiationCallableRule
3631
- PHPStan\Rules\Classes\InvalidPromotedPropertiesRule
3732
- PHPStan\Rules\Classes\LocalTypeAliasesRule
@@ -113,27 +108,67 @@ services:
113108
class: PHPStan\Rules\Classes\ExistingClassInClassExtendsRule
114109
tags:
115110
- phpstan.rules.rule
111+
arguments:
112+
discoveringSymbolsTip: %tips.discoveringSymbols%
113+
114+
-
115+
class: PHPStan\Rules\Classes\ExistingClassesInClassImplementsRule
116+
tags:
117+
- phpstan.rules.rule
118+
arguments:
119+
discoveringSymbolsTip: %tips.discoveringSymbols%
120+
121+
-
122+
class: PHPStan\Rules\Classes\ExistingClassesInEnumImplementsRule
123+
tags:
124+
- phpstan.rules.rule
125+
arguments:
126+
discoveringSymbolsTip: %tips.discoveringSymbols%
116127

117128
-
118129
class: PHPStan\Rules\Classes\ExistingClassInInstanceOfRule
119130
tags:
120131
- phpstan.rules.rule
121132
arguments:
122133
checkClassCaseSensitivity: %checkClassCaseSensitivity%
134+
discoveringSymbolsTip: %tips.discoveringSymbols%
135+
136+
-
137+
class: PHPStan\Rules\Classes\ExistingClassesInInterfaceExtendsRule
138+
tags:
139+
- phpstan.rules.rule
140+
arguments:
141+
discoveringSymbolsTip: %tips.discoveringSymbols%
142+
143+
-
144+
class: PHPStan\Rules\Classes\ExistingClassInTraitUseRule
145+
tags:
146+
- phpstan.rules.rule
147+
arguments:
148+
discoveringSymbolsTip: %tips.discoveringSymbols%
149+
150+
-
151+
class: PHPStan\Rules\Classes\InstantiationRule
152+
tags:
153+
- phpstan.rules.rule
154+
arguments:
155+
discoveringSymbolsTip: %tips.discoveringSymbols%
123156

124157
-
125158
class: PHPStan\Rules\Exceptions\CaughtExceptionExistenceRule
126159
tags:
127160
- phpstan.rules.rule
128161
arguments:
129162
checkClassCaseSensitivity: %checkClassCaseSensitivity%
163+
discoveringSymbolsTip: %tips.discoveringSymbols%
130164

131165
-
132166
class: PHPStan\Rules\Functions\CallToNonExistentFunctionRule
133167
tags:
134168
- phpstan.rules.rule
135169
arguments:
136170
checkFunctionNameCase: %checkFunctionNameCase%
171+
discoveringSymbolsTip: %tips.discoveringSymbols%
137172

138173
-
139174
class: PHPStan\Rules\Constants\OverridingConstantRule
@@ -165,13 +200,15 @@ services:
165200
- phpstan.rules.rule
166201
arguments:
167202
checkFunctionNameCase: %checkFunctionNameCase%
203+
discoveringSymbolsTip: %tips.discoveringSymbols%
168204

169205
-
170206
class: PHPStan\Rules\Namespaces\ExistingNamesInUseRule
171207
tags:
172208
- phpstan.rules.rule
173209
arguments:
174210
checkFunctionNameCase: %checkFunctionNameCase%
211+
discoveringSymbolsTip: %tips.discoveringSymbols%
175212

176213
-
177214
class: PHPStan\Rules\Properties\AccessPropertiesRule
@@ -182,6 +219,8 @@ services:
182219
class: PHPStan\Rules\Properties\AccessStaticPropertiesRule
183220
tags:
184221
- phpstan.rules.rule
222+
arguments:
223+
discoveringSymbolsTip: %tips.discoveringSymbols%
185224

186225
-
187226
class: PHPStan\Rules\Properties\ExistingClassesInPropertiesRule
@@ -190,6 +229,7 @@ services:
190229
arguments:
191230
checkClassCaseSensitivity: %checkClassCaseSensitivity%
192231
checkThisOnly: %checkThisOnly%
232+
discoveringSymbolsTip: %tips.discoveringSymbols%
193233

194234
-
195235
class: PHPStan\Rules\Functions\FunctionCallableRule

conf/config.level1.neon

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ parameters:
99

1010
rules:
1111
- PHPStan\Rules\Classes\UnusedConstructorParametersRule
12-
- PHPStan\Rules\Constants\ConstantRule
1312
- PHPStan\Rules\Functions\UnusedClosureUsesRule
1413
- PHPStan\Rules\Variables\EmptyRule
1514
- PHPStan\Rules\Variables\IssetRule
1615
- PHPStan\Rules\Variables\NullCoalesceRule
16+
17+
services:
18+
-
19+
class: PHPStan\Rules\Constants\ConstantRule
20+
tags:
21+
- phpstan.rules.rule
22+
arguments:
23+
discoveringSymbolsTip: %tips.discoveringSymbols%

conf/config.level2.neon

+3
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ services:
7777
class: PHPStan\Rules\PhpDoc\RequireExtendsCheck
7878
arguments:
7979
checkClassCaseSensitivity: %checkClassCaseSensitivity%
80+
discoveringSymbolsTip: %tips.discoveringSymbols%
8081

8182
-
8283
class: PHPStan\Rules\PhpDoc\RequireImplementsDefinitionTraitRule
8384
arguments:
8485
checkClassCaseSensitivity: %checkClassCaseSensitivity%
86+
discoveringSymbolsTip: %tips.discoveringSymbols%
8587
tags:
8688
- phpstan.rules.rule
8789

@@ -101,6 +103,7 @@ services:
101103
arguments:
102104
checkClassCaseSensitivity: %checkClassCaseSensitivity%
103105
checkMissingVarTagTypehint: %checkMissingVarTagTypehint%
106+
discoveringSymbolsTip: %tips.discoveringSymbols%
104107
tags:
105108
- phpstan.rules.rule
106109
-

conf/config.neon

+7
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ parameters:
8484
usePathConstantsAsConstantString: false
8585
rememberPossiblyImpureFunctionValues: true
8686
tips:
87+
discoveringSymbols: true
8788
treatPhpDocTypesAsCertain: true
8889
tipsOfTheDay: true
8990
reportMagicMethods: false
@@ -888,24 +889,28 @@ services:
888889
globalTypeAliases: %typeAliases%
889890
checkMissingTypehints: %checkMissingTypehints%
890891
checkClassCaseSensitivity: %checkClassCaseSensitivity%
892+
discoveringSymbolsTip: %tips.discoveringSymbols%
891893

892894
-
893895
class: PHPStan\Rules\Classes\MethodTagCheck
894896
arguments:
895897
checkClassCaseSensitivity: %checkClassCaseSensitivity%
896898
checkMissingTypehints: %checkMissingTypehints%
899+
discoveringSymbolsTip: %tips.discoveringSymbols%
897900

898901
-
899902
class: PHPStan\Rules\Classes\MixinCheck
900903
arguments:
901904
checkClassCaseSensitivity: %checkClassCaseSensitivity%
902905
checkMissingTypehints: %checkMissingTypehints%
906+
discoveringSymbolsTip: %tips.discoveringSymbols%
903907

904908
-
905909
class: PHPStan\Rules\Classes\PropertyTagCheck
906910
arguments:
907911
checkClassCaseSensitivity: %checkClassCaseSensitivity%
908912
checkMissingTypehints: %checkMissingTypehints%
913+
discoveringSymbolsTip: %tips.discoveringSymbols%
909914

910915
-
911916
class: PHPStan\Rules\Comparison\ConstantConditionRuleHelper
@@ -1005,6 +1010,7 @@ services:
10051010
class: PHPStan\Rules\Methods\StaticMethodCallCheck
10061011
arguments:
10071012
checkFunctionNameCase: %checkFunctionNameCase%
1013+
discoveringSymbolsTip: %tips.discoveringSymbols%
10081014
reportMagicMethods: %reportMagicMethods%
10091015

10101016
-
@@ -1096,6 +1102,7 @@ services:
10961102
checkExplicitMixed: %checkExplicitMixed%
10971103
checkImplicitMixed: %checkImplicitMixed%
10981104
checkBenevolentUnionTypes: %checkBenevolentUnionTypes%
1105+
discoveringSymbolsTip: %tips.discoveringSymbols%
10991106

11001107
-
11011108
class: PHPStan\Rules\UnusedFunctionParametersCheck

conf/parametersSchema.neon

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ parametersSchema:
6363
inferPrivatePropertyTypeFromConstructor: bool()
6464

6565
tips: structure([
66+
discoveringSymbols: bool()
6667
treatPhpDocTypesAsCertain: bool()
6768
])
6869
tipsOfTheDay: bool()

src/PhpDoc/StubValidator.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,23 @@ private function getRuleRegistry(Container $container): RuleRegistry
194194
$genericCallableRuleHelper = $container->getByType(GenericCallableRuleHelper::class);
195195
$methodTagTemplateTypeCheck = $container->getByType(MethodTagTemplateTypeCheck::class);
196196
$mixinCheck = $container->getByType(MixinCheck::class);
197-
$methodTagCheck = new MethodTagCheck($reflectionProvider, $classNameCheck, $genericObjectTypeCheck, $missingTypehintCheck, $unresolvableTypeHelper, true, true);
198-
$propertyTagCheck = new PropertyTagCheck($reflectionProvider, $classNameCheck, $genericObjectTypeCheck, $missingTypehintCheck, $unresolvableTypeHelper, true, true);
197+
$discoveringSymbolsTip = $container->getParameter('tips')['discoveringSymbols'];
198+
$methodTagCheck = new MethodTagCheck($reflectionProvider, $classNameCheck, $genericObjectTypeCheck, $missingTypehintCheck, $unresolvableTypeHelper, true, true, $discoveringSymbolsTip);
199+
$propertyTagCheck = new PropertyTagCheck($reflectionProvider, $classNameCheck, $genericObjectTypeCheck, $missingTypehintCheck, $unresolvableTypeHelper, true, true, $discoveringSymbolsTip);
199200
$reflector = $container->getService('stubReflector');
200201
$relativePathHelper = $container->getService('simpleRelativePathHelper');
201202
$assertRuleHelper = $container->getByType(AssertRuleHelper::class);
202203
$conditionalReturnTypeRuleHelper = $container->getByType(ConditionalReturnTypeRuleHelper::class);
203204

204205
$rules = [
205206
// level 0
206-
new ExistingClassesInClassImplementsRule($classNameCheck, $reflectionProvider),
207-
new ExistingClassesInInterfaceExtendsRule($classNameCheck, $reflectionProvider),
208-
new ExistingClassInClassExtendsRule($classNameCheck, $reflectionProvider),
209-
new ExistingClassInTraitUseRule($classNameCheck, $reflectionProvider),
207+
new ExistingClassesInClassImplementsRule($classNameCheck, $reflectionProvider, $discoveringSymbolsTip),
208+
new ExistingClassesInInterfaceExtendsRule($classNameCheck, $reflectionProvider, $discoveringSymbolsTip),
209+
new ExistingClassInClassExtendsRule($classNameCheck, $reflectionProvider, $discoveringSymbolsTip),
210+
new ExistingClassInTraitUseRule($classNameCheck, $reflectionProvider, $discoveringSymbolsTip),
210211
new ExistingClassesInTypehintsRule($functionDefinitionCheck),
211212
new \PHPStan\Rules\Functions\ExistingClassesInTypehintsRule($functionDefinitionCheck),
212-
new ExistingClassesInPropertiesRule($reflectionProvider, $classNameCheck, $unresolvableTypeHelper, $phpVersion, true, false),
213+
new ExistingClassesInPropertiesRule($reflectionProvider, $classNameCheck, $unresolvableTypeHelper, $phpVersion, true, false, $discoveringSymbolsTip),
213214
new OverridingMethodRule(
214215
$phpVersion,
215216
new MethodSignatureRule($phpClassReflectionExtension, true, true),

src/Rules/Classes/ExistingClassInClassExtendsRule.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ final class ExistingClassInClassExtendsRule implements Rule
2020
public function __construct(
2121
private ClassNameCheck $classCheck,
2222
private ReflectionProvider $reflectionProvider,
23+
private bool $discoveringSymbolsTip,
2324
)
2425
{
2526
}
@@ -42,15 +43,19 @@ public function processNode(Node $node, Scope $scope): array
4243
}
4344
if (!$this->reflectionProvider->hasClass($extendedClassName)) {
4445
if (!$scope->isInClassExists($extendedClassName)) {
45-
$messages[] = RuleErrorBuilder::message(sprintf(
46+
$errorBuilder = RuleErrorBuilder::message(sprintf(
4647
'%s extends unknown class %s.',
4748
$currentClassName !== null ? sprintf('Class %s', $currentClassName) : 'Anonymous class',
4849
$extendedClassName,
4950
))
5051
->identifier('class.notFound')
51-
->nonIgnorable()
52-
->discoveringSymbolsTip()
53-
->build();
52+
->nonIgnorable();
53+
54+
if ($this->discoveringSymbolsTip) {
55+
$errorBuilder->discoveringSymbolsTip();
56+
}
57+
58+
$messages[] = $errorBuilder->build();
5459
}
5560
} else {
5661
$reflection = $this->reflectionProvider->getClass($extendedClassName);

src/Rules/Classes/ExistingClassInInstanceOfRule.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function __construct(
2626
private ReflectionProvider $reflectionProvider,
2727
private ClassNameCheck $classCheck,
2828
private bool $checkClassCaseSensitivity,
29+
private bool $discoveringSymbolsTip,
2930
)
3031
{
3132
}
@@ -69,12 +70,16 @@ public function processNode(Node $node, Scope $scope): array
6970
return [];
7071
}
7172

73+
$errorBuilder = RuleErrorBuilder::message(sprintf('Class %s not found.', $name))
74+
->identifier('class.notFound')
75+
->line($class->getStartLine());
76+
77+
if ($this->discoveringSymbolsTip) {
78+
$errorBuilder->discoveringSymbolsTip();
79+
}
80+
7281
return [
73-
RuleErrorBuilder::message(sprintf('Class %s not found.', $name))
74-
->identifier('class.notFound')
75-
->line($class->getStartLine())
76-
->discoveringSymbolsTip()
77-
->build(),
82+
$errorBuilder->build(),
7883
];
7984
}
8085

src/Rules/Classes/ExistingClassInTraitUseRule.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ final class ExistingClassInTraitUseRule implements Rule
2222
public function __construct(
2323
private ClassNameCheck $classCheck,
2424
private ReflectionProvider $reflectionProvider,
25+
private bool $discoveringSymbolsTip,
2526
)
2627
{
2728
}
@@ -64,11 +65,15 @@ public function processNode(Node $node, Scope $scope): array
6465
foreach ($node->traits as $trait) {
6566
$traitName = (string) $trait;
6667
if (!$this->reflectionProvider->hasClass($traitName)) {
67-
$messages[] = RuleErrorBuilder::message(sprintf('%s uses unknown trait %s.', $currentName, $traitName))
68+
$errorBuilder = RuleErrorBuilder::message(sprintf('%s uses unknown trait %s.', $currentName, $traitName))
6869
->identifier('trait.notFound')
69-
->nonIgnorable()
70-
->discoveringSymbolsTip()
71-
->build();
70+
->nonIgnorable();
71+
72+
if ($this->discoveringSymbolsTip) {
73+
$errorBuilder->discoveringSymbolsTip();
74+
}
75+
76+
$messages[] = $errorBuilder->build();
7277
} else {
7378
$reflection = $this->reflectionProvider->getClass($traitName);
7479
if ($reflection->isClass()) {

src/Rules/Classes/ExistingClassesInClassImplementsRule.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ final class ExistingClassesInClassImplementsRule implements Rule
2121
public function __construct(
2222
private ClassNameCheck $classCheck,
2323
private ReflectionProvider $reflectionProvider,
24+
private bool $discoveringSymbolsTip,
2425
)
2526
{
2627
}
@@ -45,15 +46,19 @@ public function processNode(Node $node, Scope $scope): array
4546
$implementedClassName = (string) $implements;
4647
if (!$this->reflectionProvider->hasClass($implementedClassName)) {
4748
if (!$scope->isInClassExists($implementedClassName)) {
48-
$messages[] = RuleErrorBuilder::message(sprintf(
49+
$errorBuilder = RuleErrorBuilder::message(sprintf(
4950
'%s implements unknown interface %s.',
5051
$currentClassName !== null ? sprintf('Class %s', $currentClassName) : 'Anonymous class',
5152
$implementedClassName,
5253
))
5354
->identifier('interface.notFound')
54-
->nonIgnorable()
55-
->discoveringSymbolsTip()
56-
->build();
55+
->nonIgnorable();
56+
57+
if ($this->discoveringSymbolsTip) {
58+
$errorBuilder->discoveringSymbolsTip();
59+
}
60+
61+
$messages[] = $errorBuilder->build();
5762
}
5863
} else {
5964
$reflection = $this->reflectionProvider->getClass($implementedClassName);

src/Rules/Classes/ExistingClassesInEnumImplementsRule.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ final class ExistingClassesInEnumImplementsRule implements Rule
2121
public function __construct(
2222
private ClassNameCheck $classCheck,
2323
private ReflectionProvider $reflectionProvider,
24+
private bool $discoveringSymbolsTip,
2425
)
2526
{
2627
}
@@ -42,15 +43,19 @@ public function processNode(Node $node, Scope $scope): array
4243
$implementedClassName = (string) $implements;
4344
if (!$this->reflectionProvider->hasClass($implementedClassName)) {
4445
if (!$scope->isInClassExists($implementedClassName)) {
45-
$messages[] = RuleErrorBuilder::message(sprintf(
46+
$errorBuilder = RuleErrorBuilder::message(sprintf(
4647
'Enum %s implements unknown interface %s.',
4748
$currentEnumName,
4849
$implementedClassName,
4950
))
5051
->identifier('interface.notFound')
51-
->nonIgnorable()
52-
->discoveringSymbolsTip()
53-
->build();
52+
->nonIgnorable();
53+
54+
if ($this->discoveringSymbolsTip) {
55+
$errorBuilder->discoveringSymbolsTip();
56+
}
57+
58+
$messages[] = $errorBuilder->build();
5459
}
5560
} else {
5661
$reflection = $this->reflectionProvider->getClass($implementedClassName);

0 commit comments

Comments
 (0)