Skip to content

Commit 32564ee

Browse files
committed
[BE] Check unresolvable parameters
1 parent 8270b37 commit 32564ee

23 files changed

+12
-33
lines changed

changelog-2.0.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Major new features 🚀
1818
* Check preg_quote delimiter sanity (level 0) ([#3252](https://github.com/phpstan/phpstan-src/pull/3252)), #11338, thanks @staabm!
1919
* Rule for `call_user_func()` (level 5) ([#2479](https://github.com/phpstan/phpstan-src/pull/2479)), thanks @staabm!
2020
* ArrayUnpackingRule (level 3) ([#856](https://github.com/phpstan/phpstan-src/pull/856)), thanks @canvural!
21+
* Check unresolvable parameters (level 5) ([#1319](https://github.com/phpstan/phpstan-src/pull/1319)), thanks @rvanvelzen!
22+
* Enforce `@no-named-arguments` (level 5) (https://github.com/phpstan/phpstan-src/commit/74ba8c23696948f2647d880df72f375346f41010), #5968
2123
* Added previously absent type checks (level 0)
2224
* Check existing classes in `@phpstan-self-out` (https://github.com/phpstan/phpstan-src/commit/6838669976bf20232abde36ecdd52b1770fa50c9)
2325
* Check nonexistent classes in local type aliases (https://github.com/phpstan/phpstan-src/commit/2485b2e9c129e789ec3b2d7db81ca30f87c63911)
@@ -50,7 +52,6 @@ Bleeding edge (TODO move to other sections)
5052
* Specify explicit mixed array type via `is_array` ([#1191](https://github.com/phpstan/phpstan-src/pull/1191)), thanks @herndlm!
5153
* Rules for checking direct calls to `__construct()` (level 2) ([#1208](https://github.com/phpstan/phpstan-src/pull/1208)), #7022, thanks @muno92!
5254
* ConstantLooseComparisonRule - level 4 (https://github.com/phpstan/phpstan-src/commit/6ebf2361a3c831dd105a815521889428c295dc9f)
53-
* Unresolvable parameters ([#1319](https://github.com/phpstan/phpstan-src/pull/1319)), thanks @rvanvelzen!
5455
* Support `@readonly` property and `@immutable` class PHPDoc ([#1295](https://github.com/phpstan/phpstan-src/pull/1295), [#1335](https://github.com/phpstan/phpstan-src/pull/1335)), #4082, thanks @herndlm!
5556
* Move IllegalConstructorMethodCallRule and IllegalConstructorStaticCallRule to phpstan-strict-rules (https://github.com/phpstan/phpstan-src/commit/124b30f98c182193187be0b9c2e151e477429b7a, https://github.com/phpstan/phpstan-strict-rules/commit/0c82c96f2a55d8b91bbc7ee6512c94f68a206b43)
5657
* Add `@readonly` rule that disallows default values ([#1391](https://github.com/phpstan/phpstan-src/pull/1391)), thanks @herndlm!
@@ -82,7 +83,6 @@ Bleeding edge (TODO move to other sections)
8283
* [#3023](https://github.com/phpstan/phpstan-src/pull/3023), thanks @staabm!
8384
* CallToConstructorStatementWithoutSideEffectsRule - report class with no constructor (https://github.com/phpstan/phpstan-src/commit/b116d25a6e4ba6c09f59af6569d9e6f6fd20aff4)
8485
* Check if required file exists ([#3294](https://github.com/phpstan/phpstan-src/pull/3294)), #3397, thanks @Bellangelo!
85-
* Enforce `@no-named-arguments` (https://github.com/phpstan/phpstan-src/commit/74ba8c23696948f2647d880df72f375346f41010), #5968
8686
* Check too wide private property type (https://github.com/phpstan/phpstan-src/commit/7453f4f75fae3d635063589467842aae29d88b54)
8787
* Check `@param-immediately-invoked-callable` and `@param-later-invoked-callable` (https://github.com/phpstan/phpstan-src/commit/580a6add422f4e34191df9e7a77ba1655e914bda), #10932
8888
* Report useless return values of function calls like `var_export` without `$return=true` ([#3225](https://github.com/phpstan/phpstan-src/pull/3225)), #11320, thanks @staabm!

conf/bleedingEdge.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ parameters:
1010
strictUnnecessaryNullsafePropertyFetch: true
1111
looseComparison: true
1212
consistentConstructor: true
13-
checkUnresolvableParameterTypes: true
1413
readOnlyByPhpDoc: true
1514
missingMagicSerializationRule: true
1615
alwaysCheckTooWideReturnTypeFinalMethods: true

conf/config.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ parameters:
3131
strictUnnecessaryNullsafePropertyFetch: false
3232
looseComparison: false
3333
consistentConstructor: false
34-
checkUnresolvableParameterTypes: false
3534
readOnlyByPhpDoc: false
3635
missingMagicSerializationRule: false
3736
alwaysCheckTooWideReturnTypeFinalMethods: false
@@ -927,7 +926,6 @@ services:
927926
checkArgumentsPassedByReference: %checkArgumentsPassedByReference%
928927
checkExtraArguments: %checkExtraArguments%
929928
checkMissingTypehints: %checkMissingTypehints%
930-
checkUnresolvableParameterTypes: %featureToggles.checkUnresolvableParameterTypes%
931929

932930
-
933931
class: PHPStan\Rules\FunctionDefinitionCheck

conf/parametersSchema.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ parametersSchema:
3737
strictUnnecessaryNullsafePropertyFetch: bool(),
3838
looseComparison: bool(),
3939
consistentConstructor: bool()
40-
checkUnresolvableParameterTypes: bool()
4140
readOnlyByPhpDoc: bool()
4241
missingMagicSerializationRule: bool()
4342
alwaysCheckTooWideReturnTypeFinalMethods: bool()

src/Rules/FunctionCallParametersCheck.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public function __construct(
4646
private bool $checkArgumentsPassedByReference,
4747
private bool $checkExtraArguments,
4848
private bool $checkMissingTypehints,
49-
private bool $checkUnresolvableParameterTypes,
5049
)
5150
{
5251
}
@@ -290,7 +289,7 @@ public function check(
290289
}
291290
}
292291

293-
if (!$acceptsNamedArguments && $this->checkUnresolvableParameterTypes && isset($messages[14])) {
292+
if (!$acceptsNamedArguments && isset($messages[14])) {
294293
if ($argumentName !== null) {
295294
$errors[] = RuleErrorBuilder::message(sprintf($messages[14], sprintf('named argument $%s', $argumentName)))
296295
->identifier('argument.named')
@@ -311,10 +310,7 @@ public function check(
311310
if ($this->checkArgumentTypes) {
312311
$parameterType = TypeUtils::resolveLateResolvableTypes($parameter->getType());
313312

314-
if (
315-
!$parameter->passedByReference()->createsNewVariable()
316-
|| (!$isBuiltin && $this->checkUnresolvableParameterTypes) // bleeding edge only
317-
) {
313+
if (!$parameter->passedByReference()->createsNewVariable() || !$isBuiltin) {
318314
$accepts = $this->ruleLevelHelper->acceptsWithReason($parameterType, $argumentValueType, $scope->isDeclareStrictTypes());
319315

320316
if (!$accepts->result) {
@@ -332,8 +328,8 @@ public function check(
332328
}
333329
}
334330

335-
if ($this->checkUnresolvableParameterTypes
336-
&& $originalParameter !== null
331+
if (
332+
$originalParameter !== null
337333
&& isset($messages[13])
338334
&& !$this->unresolvableTypeHelper->containsUnresolvableType($originalParameter->getType())
339335
&& $this->unresolvableTypeHelper->containsUnresolvableType($parameterType)

src/Testing/TestCase.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
parameters:
22
inferPrivatePropertyTypeFromConstructor: true
3-
featureToggles:
4-
checkUnresolvableParameterTypes: true
53

64
services:
75
-

tests/PHPStan/Analyser/Bug9307CallMethodsRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected function getRule(): Rule
2626
$ruleLevelHelper = new RuleLevelHelper($reflectionProvider, true, false, true, true, false, false);
2727
return new CallMethodsRule(
2828
new MethodCallCheck($reflectionProvider, $ruleLevelHelper, true, true),
29-
new FunctionCallParametersCheck($ruleLevelHelper, new NullsafeCheck(), new PhpVersion(PHP_VERSION_ID), new UnresolvableTypeHelper(), new PropertyReflectionFinder(), true, true, true, true, true),
29+
new FunctionCallParametersCheck($ruleLevelHelper, new NullsafeCheck(), new PhpVersion(PHP_VERSION_ID), new UnresolvableTypeHelper(), new PropertyReflectionFinder(), true, true, true, true),
3030
);
3131
}
3232

tests/PHPStan/Rules/Classes/ClassAttributesRuleTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ protected function getRule(): Rule
3838
true,
3939
true,
4040
true,
41-
true,
4241
),
4342
new ClassNameCheck(
4443
new ClassCaseSensitivityCheck($reflectionProvider, false),

tests/PHPStan/Rules/Classes/ClassConstantAttributesRuleTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ protected function getRule(): Rule
3737
true,
3838
true,
3939
true,
40-
true,
4140
),
4241
new ClassNameCheck(
4342
new ClassCaseSensitivityCheck($reflectionProvider, false),

tests/PHPStan/Rules/Classes/ForbiddenNameCheckExtensionRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected function getRule(): Rule
2626
$reflectionProvider = $this->createReflectionProvider();
2727
return new InstantiationRule(
2828
$reflectionProvider,
29-
new FunctionCallParametersCheck(new RuleLevelHelper($reflectionProvider, true, false, true, false, false, false), new NullsafeCheck(), new PhpVersion(80000), new UnresolvableTypeHelper(), new PropertyReflectionFinder(), true, true, true, true, true),
29+
new FunctionCallParametersCheck(new RuleLevelHelper($reflectionProvider, true, false, true, false, false, false), new NullsafeCheck(), new PhpVersion(80000), new UnresolvableTypeHelper(), new PropertyReflectionFinder(), true, true, true, true),
3030
new ClassNameCheck(
3131
new ClassCaseSensitivityCheck($reflectionProvider, true),
3232
new ClassForbiddenNameCheck(self::getContainer()),

0 commit comments

Comments
 (0)