Skip to content
Merged
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: 9 additions & 3 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -3431,13 +3431,19 @@ private function intersectConditionalExpressions(array $otherConditionalExpressi
}

$otherHolders = $otherConditionalExpressions[$exprString];
foreach (array_keys($holders) as $key) {
$intersectedHolders = [];
foreach ($holders as $key => $holder) {
if (!array_key_exists($key, $otherHolders)) {
continue 2;
continue;
}
$intersectedHolders[$key] = $holder;
}

if (count($intersectedHolders) === 0) {
continue;
}

$newConditionalExpressions[$exprString] = $holders;
$newConditionalExpressions[$exprString] = $intersectedHolders;
}

return $newConditionalExpressions;
Expand Down
7 changes: 7 additions & 0 deletions tests/.claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"permissions": {
"allow": [
"WebFetch(domain:phpbench.readthedocs.io)"
]
}
}
60 changes: 60 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-14269.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php declare(strict_types = 1);

namespace Bug14269;

use PHPStan\TrinaryLogic;
use function PHPStan\Testing\assertVariableCertainty;

class Package
{

public function isMultiDay(): bool
{
return true;
}

/**
* @return string[]
*/
public function getWorkspaces(): array
{
return [];
}

/**
* @return int[]|null
*/
public function getService(): ?array
{
return [];
}

}

class ReturnsSelf
{

public function subtract(): self
{
return $this;
}

}

function doFoo(Package $package, ReturnsSelf $s): void {
if (!$package->isMultiDay()) {
$packageDurationInMinutes = 60;
}

foreach ($package->getWorkspaces() as $workplace) {
$availableIntervals = $s->subtract();
if ($package->getService() !== null && !$package->isMultiDay()) {
assertVariableCertainty(TrinaryLogic::createYes(), $packageDurationInMinutes);
continue;
}

$availableIntervals = $package->isMultiDay()
? 'aaa'
: 'bbb';
}
}
12 changes: 12 additions & 0 deletions tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,16 @@ public function testBug7699(): void
$this->analyse([__DIR__ . '/data/bug-7699.php'], []);
}

public function testBug4284(): void
{
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/bug-4284.php'], [
[
'If condition is always true.',
25,
'Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.',
],
]);
}

}
30 changes: 30 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-4284.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php declare(strict_types = 1);

namespace Bug4284;

class HelloWorld
{
/** @param mixed[] $browser */
public function sayHello(array $browser): void
{
$browserName = '';
$upgradeBrowserLink = '';

if ($browser['name'] === 1) {
$browserName = '123';
$upgradeBrowserLink = '456';
} elseif ($browser['name'] === 2) {
$browserName = '789';
$upgradeBrowserLink = '123';
}

if ($browserName && $upgradeBrowserLink) {
//
}
if ($browserName) {
if ($upgradeBrowserLink) {
//
}
}
}
}
Loading