Skip to content

Commit 32acf00

Browse files
Revert "Improvement"
This reverts commit 6af082c.
1 parent 6af082c commit 32acf00

4 files changed

Lines changed: 10 additions & 41 deletions

File tree

src/Analyser/MutatingScope.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,9 +3266,8 @@ public function filterByTruthyValue(Expr $expr): self
32663266

32673267
$specifiedTypes = $this->typeSpecifier->specifyTypesInCondition($this, $expr, TypeSpecifierContext::createTruthy());
32683268
if ($specifiedTypes->shouldSpecifyOnly()) {
3269-
[$markerExpr, $markerValue] = $this->unwrapSpecifyOnlyMarker($expr, true);
32703269
$specifiedTypes = $specifiedTypes->unionWith(
3271-
$this->typeSpecifier->create($markerExpr, new ConstantBooleanType($markerValue), TypeSpecifierContext::createTrue(), $this),
3270+
$this->typeSpecifier->create($expr, new ConstantBooleanType(true), TypeSpecifierContext::createTrue(), $this),
32723271
);
32733272
}
32743273
$scope = $this->filterBySpecifiedTypes($specifiedTypes);
@@ -3289,9 +3288,8 @@ public function filterByFalseyValue(Expr $expr): self
32893288

32903289
$specifiedTypes = $this->typeSpecifier->specifyTypesInCondition($this, $expr, TypeSpecifierContext::createFalsey());
32913290
if ($specifiedTypes->shouldSpecifyOnly()) {
3292-
[$markerExpr, $markerValue] = $this->unwrapSpecifyOnlyMarker($expr, false);
32933291
$specifiedTypes = $specifiedTypes->unionWith(
3294-
$this->typeSpecifier->create($markerExpr, new ConstantBooleanType($markerValue), TypeSpecifierContext::createTrue(), $this),
3292+
$this->typeSpecifier->create($expr, new ConstantBooleanType(false), TypeSpecifierContext::createTrue(), $this),
32953293
);
32963294
}
32973295
$scope = $this->filterBySpecifiedTypes($specifiedTypes);
@@ -3300,24 +3298,6 @@ public function filterByFalseyValue(Expr $expr): self
33003298
return $scope;
33013299
}
33023300

3303-
/**
3304-
* Strips BooleanNot wrappers from a specifyOnly condition so the boolean
3305-
* result marker is stored for the underlying call (e.g. `array_key_exists(...)`)
3306-
* rather than for the negated form (`!array_key_exists(...)`). The negated form
3307-
* is then derived from the inner value instead of being capped at bool.
3308-
*
3309-
* @return array{Expr, bool}
3310-
*/
3311-
private function unwrapSpecifyOnlyMarker(Expr $expr, bool $value): array
3312-
{
3313-
while ($expr instanceof Expr\BooleanNot) {
3314-
$expr = $expr->expr;
3315-
$value = !$value;
3316-
}
3317-
3318-
return [$expr, $value];
3319-
}
3320-
33213301
/**
33223302
* @return static
33233303
*/

src/Rules/Methods/MethodCallWithPossiblyRenamedNamedArgumentRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public function processNode(Node $node, NodeCallbackInvoker&Scope&CollectedDataE
5151
continue;
5252
}
5353

54+
if (!array_key_exists($prototypeParameterName, $prototypeMethodCalls)) {
55+
continue;
56+
}
57+
5458
$callsWithParameter = $prototypeMethodCalls[$prototypeParameterName];
5559
foreach ($callsWithParameter as [$file, $line]) {
5660
$errors[] = RuleErrorBuilder::message(sprintf(

tests/PHPStan/Analyser/nsrt/bug-14705.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,8 @@ public function realpathElvisWithLoop(string $fileName, array $paths): void
128128
}
129129

130130
/**
131-
* Duplicate array_key_exists after an early-continue narrows both the negated
132-
* and the bare positive call.
133-
*
134-
* The condition is the BooleanNot `!array_key_exists(...)`. When the specifyOnly
135-
* duplicate-detection marker is stored, the BooleanNot wrapper is stripped so the
136-
* marker records the underlying `array_key_exists(...)` call as true. The negated
137-
* form is then derived from that inner value (false), and the bare positive call
138-
* reads the stored true directly.
131+
* Duplicate array_key_exists after an early-continue narrows the negated
132+
* call to false, while the non-negated call stays bool.
139133
*
140134
* @param array<string,string|array<int,string>> $theInput
141135
* @phpstan-param array{'name':string,'owners':array<int,string>} $theInput
@@ -148,7 +142,7 @@ public function arrayKeyExistsDuplicateInLoop(array $theInput, array $theTags):
148142
continue;
149143
}
150144
assertType('false', !array_key_exists($tag, $theInput));
151-
assertType('true', array_key_exists($tag, $theInput));
145+
assertType('bool', array_key_exists($tag, $theInput));
152146
}
153147
}
154148

tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -510,16 +510,7 @@ public function testNonEmptySpecifiedString(): void
510510
public function testBug14705(): void
511511
{
512512
$this->treatPhpDocTypesAsCertain = true;
513-
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-14705.php'], [
514-
[
515-
'Call to function array_key_exists() with \'name\'|\'owners\' and array{name: string, owners: array<int, string>} will always evaluate to true.',
516-
150,
517-
],
518-
[
519-
'Call to function array_key_exists() with \'name\'|\'owners\' and array{name: string, owners: array<int, string>} will always evaluate to true.',
520-
151,
521-
],
522-
]);
513+
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-14705.php'], []);
523514
}
524515

525516
#[RequiresPhp('>= 8.0')]

0 commit comments

Comments
 (0)