Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Analyser/TypeSpecifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -2605,9 +2605,19 @@
$leftTypes = $this->create($expr->left, $leftType, $context, $scope)->setRootExpr($expr);
$rightTypes = $this->create($expr->right, $rightType, $context, $scope)->setRootExpr($expr);

return $context->true()
$result = $context->true()

Check warning on line 2608 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrueTruthyFalseFalseyTypeSpecifierContextMutator": @@ @@ $leftTypes = $this->create($expr->left, $leftType, $context, $scope)->setRootExpr($expr); $rightTypes = $this->create($expr->right, $rightType, $context, $scope)->setRootExpr($expr); - $result = $context->true() + $result = $context->truthy() ? $leftTypes->unionWith($rightTypes) : $leftTypes->normalize($scope)->intersectWith($rightTypes->normalize($scope));

Check warning on line 2608 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrueTruthyFalseFalseyTypeSpecifierContextMutator": @@ @@ $leftTypes = $this->create($expr->left, $leftType, $context, $scope)->setRootExpr($expr); $rightTypes = $this->create($expr->right, $rightType, $context, $scope)->setRootExpr($expr); - $result = $context->true() + $result = $context->truthy() ? $leftTypes->unionWith($rightTypes) : $leftTypes->normalize($scope)->intersectWith($rightTypes->normalize($scope));
? $leftTypes->unionWith($rightTypes)
: $leftTypes->normalize($scope)->intersectWith($rightTypes->normalize($scope));

if (
!$context->null()
&& ($leftTypes->getSureTypes() !== [] || $leftTypes->getSureNotTypes() !== [])
&& ($rightTypes->getSureTypes() !== [] || $rightTypes->getSureNotTypes() !== [])
) {
$result = $result->unionWith($this->handleDefaultTruthyOrFalseyContext($context, $expr, $scope));
}

return $result;
}

public function resolveIdentical(Expr\BinaryOp\Identical $expr, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/TypeSpecifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,7 @@ public static function dataCondition(): iterable
[
'$float' => 'float',
'(int) $float' => 'int',
'$float == (int) $float' => '~0|0.0|\'\'|\'0\'|array{}|false|null',
],
[],
],
Expand Down
9 changes: 9 additions & 0 deletions tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1514,4 +1514,13 @@ public function testBug14117(): void
]);
}

public function testBug7718(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/bug-7718.php'], []);
}

}
11 changes: 11 additions & 0 deletions tests/PHPStan/Rules/Variables/data/bug-7718.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Bug7718;

if ($_GET['something'] == 'banana'){
$bananas = 1;
}

if ($_GET['something'] == 'banana'){
echo $bananas;
}
Loading