Skip to content

Commit cb04a6e

Browse files
committed
1 parent a0fc384 commit cb04a6e

16 files changed

+256
-0
lines changed

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,12 @@ public function testBug4513(): void
305305
$this->assertCount(0, $errors);
306306
}
307307

308+
public function testBug1871(): void
309+
{
310+
$errors = $this->runAnalyse(__DIR__ . '/data/bug-1871.php');
311+
$this->assertCount(0, $errors);
312+
}
313+
308314
/**
309315
* @param string $file
310316
* @return \PHPStan\Analyser\Error[]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Bug1871;
4+
5+
interface I {}
6+
7+
class A implements I {}
8+
9+
function(): void {
10+
$objects = [
11+
new A()
12+
];
13+
14+
foreach($objects as $object) {
15+
var_dump(is_subclass_of($object, '\C'));
16+
}
17+
};

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,9 @@ public function testBug4432(): void
253253
$this->analyse([__DIR__ . '/data/bug-4432.php'], []);
254254
}
255255

256+
public function testBug1664(): void
257+
{
258+
$this->analyse([__DIR__ . '/data/bug-1664.php'], []);
259+
}
260+
256261
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Bug1664;
4+
5+
class A
6+
{
7+
public function a()
8+
{
9+
$responses = [
10+
'foo',
11+
42,
12+
'bar',
13+
];
14+
15+
return $responses[array_rand($responses)];
16+
}
17+
}

tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,11 @@ public function testBug3994(): void
385385
$this->analyse([__DIR__ . '/data/bug-3994.php'], []);
386386
}
387387

388+
public function testBug1613(): void
389+
{
390+
$this->checkAlwaysTrueCheckTypeFunctionCall = true;
391+
$this->treatPhpDocTypesAsCertain = true;
392+
$this->analyse([__DIR__ . '/data/bug-1613.php'], []);
393+
}
394+
388395
}

tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,4 +438,16 @@ public function testBug2675(): void
438438
$this->analyse([__DIR__ . '/data/bug-2675.php'], []);
439439
}
440440

441+
public function testBug2220(): void
442+
{
443+
$this->checkAlwaysTrueStrictComparison = true;
444+
$this->analyse([__DIR__ . '/data/bug-2220.php'], []);
445+
}
446+
447+
public function testBug1707(): void
448+
{
449+
$this->checkAlwaysTrueStrictComparison = true;
450+
$this->analyse([__DIR__ . '/data/bug-1707.php'], []);
451+
}
452+
441453
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Bug1613;
4+
5+
class TestClass
6+
{
7+
public function test(string $index)
8+
{
9+
$array = [
10+
"123" => "test"
11+
];
12+
return array_key_exists($index, $array);
13+
}
14+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Bug1707;
4+
5+
class Test
6+
{
7+
public function foo(): void
8+
{
9+
$values = ['a' => 1, 'b' => 2];
10+
$keys = ['a', 'b', 'c', 'd'];
11+
12+
foreach ($keys as $key) {
13+
if(array_key_exists($key, $values)){
14+
unset($values[$key]);
15+
}
16+
17+
if(0 === \count($values)) {
18+
break;
19+
}
20+
}
21+
22+
}
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Bug2220;
4+
5+
class HelloWorld
6+
{
7+
/**
8+
* @var string
9+
*/
10+
private $privateModule;
11+
12+
public function sayHello(): void
13+
{
14+
$resource = $this->getResource();
15+
16+
if ($resource === "{$this->privateModule}:abcdef") {
17+
$this->abc();
18+
} elseif ($resource === "{$this->privateModule}:xyz") {
19+
$this->abc();
20+
}
21+
}
22+
23+
private function abc(): void {}
24+
25+
private function getResource(): string { return 'string'; }
26+
}

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,10 @@ public function testBug2268(): void
486486
$this->analyse([__DIR__ . '/data/bug-2268.php'], []);
487487
}
488488

489+
public function testBug2434(): void
490+
{
491+
require_once __DIR__ . '/data/bug-2434.php';
492+
$this->analyse([__DIR__ . '/data/bug-2434.php'], []);
493+
}
494+
489495
}

0 commit comments

Comments
 (0)