Skip to content

Commit b2371e9

Browse files
authored
Merge branch refs/heads/2.1.x into 2.2.x
2 parents a1b440f + 63cb407 commit b2371e9

5 files changed

Lines changed: 118 additions & 3 deletions

File tree

src/Analyser/MutatingScope.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3431,13 +3431,19 @@ private function intersectConditionalExpressions(array $otherConditionalExpressi
34313431
}
34323432

34333433
$otherHolders = $otherConditionalExpressions[$exprString];
3434-
foreach (array_keys($holders) as $key) {
3434+
$intersectedHolders = [];
3435+
foreach ($holders as $key => $holder) {
34353436
if (!array_key_exists($key, $otherHolders)) {
3436-
continue 2;
3437+
continue;
34373438
}
3439+
$intersectedHolders[$key] = $holder;
3440+
}
3441+
3442+
if (count($intersectedHolders) === 0) {
3443+
continue;
34383444
}
34393445

3440-
$newConditionalExpressions[$exprString] = $holders;
3446+
$newConditionalExpressions[$exprString] = $intersectedHolders;
34413447
}
34423448

34433449
return $newConditionalExpressions;

tests/.claude/settings.local.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"WebFetch(domain:phpbench.readthedocs.io)"
5+
]
6+
}
7+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug14269;
4+
5+
use PHPStan\TrinaryLogic;
6+
use function PHPStan\Testing\assertVariableCertainty;
7+
8+
class Package
9+
{
10+
11+
public function isMultiDay(): bool
12+
{
13+
return true;
14+
}
15+
16+
/**
17+
* @return string[]
18+
*/
19+
public function getWorkspaces(): array
20+
{
21+
return [];
22+
}
23+
24+
/**
25+
* @return int[]|null
26+
*/
27+
public function getService(): ?array
28+
{
29+
return [];
30+
}
31+
32+
}
33+
34+
class ReturnsSelf
35+
{
36+
37+
public function subtract(): self
38+
{
39+
return $this;
40+
}
41+
42+
}
43+
44+
function doFoo(Package $package, ReturnsSelf $s): void {
45+
if (!$package->isMultiDay()) {
46+
$packageDurationInMinutes = 60;
47+
}
48+
49+
foreach ($package->getWorkspaces() as $workplace) {
50+
$availableIntervals = $s->subtract();
51+
if ($package->getService() !== null && !$package->isMultiDay()) {
52+
assertVariableCertainty(TrinaryLogic::createYes(), $packageDurationInMinutes);
53+
continue;
54+
}
55+
56+
$availableIntervals = $package->isMultiDay()
57+
? 'aaa'
58+
: 'bbb';
59+
}
60+
}

tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,16 @@ public function testBug7699(): void
201201
$this->analyse([__DIR__ . '/data/bug-7699.php'], []);
202202
}
203203

204+
public function testBug4284(): void
205+
{
206+
$this->treatPhpDocTypesAsCertain = true;
207+
$this->analyse([__DIR__ . '/data/bug-4284.php'], [
208+
[
209+
'If condition is always true.',
210+
25,
211+
'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%</>.',
212+
],
213+
]);
214+
}
215+
204216
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug4284;
4+
5+
class HelloWorld
6+
{
7+
/** @param mixed[] $browser */
8+
public function sayHello(array $browser): void
9+
{
10+
$browserName = '';
11+
$upgradeBrowserLink = '';
12+
13+
if ($browser['name'] === 1) {
14+
$browserName = '123';
15+
$upgradeBrowserLink = '456';
16+
} elseif ($browser['name'] === 2) {
17+
$browserName = '789';
18+
$upgradeBrowserLink = '123';
19+
}
20+
21+
if ($browserName && $upgradeBrowserLink) {
22+
//
23+
}
24+
if ($browserName) {
25+
if ($upgradeBrowserLink) {
26+
//
27+
}
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)