Skip to content

Commit 9a1ce42

Browse files
authored
Merge branch refs/heads/1.12.x into 2.0.x
2 parents fe7e1f5 + 7697398 commit 9a1ce42

File tree

6 files changed

+165
-0
lines changed

6 files changed

+165
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Bug5077;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @param array<int, array<string, int|string>> $array
9+
*/
10+
function test(array &$array): void
11+
{
12+
$array[] = ['test' => rand(), 'p' => 'test'];
13+
}
14+
15+
function (): void {
16+
$array = [];
17+
$array['key'] = [];
18+
19+
assertType('array{key: array{}}', $array);
20+
assertType('array{}', $array['key']);
21+
22+
test($array['key']);
23+
assertType('array{key: array<int, array<string, int|string>>}', $array);
24+
assertType('array<int, array<string, int|string>>', $array['key']);
25+
26+
test($array['key']);
27+
assertType('array{key: array<int, array<string, int|string>>}', $array);
28+
assertType('array<int, array<string, int|string>>', $array['key']);
29+
30+
test($array['key']);
31+
assertType('array{key: array<int, array<string, int|string>>}', $array);
32+
assertType('array<int, array<string, int|string>>', $array['key']);
33+
};

tests/PHPStan/Rules/DeadCode/UnusedPrivatePropertyRuleTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,18 @@ public function testBug8781(): void
314314
$this->analyse([__DIR__ . '/data/bug-8781.php'], []);
315315
}
316316

317+
public function testBug9361(): void
318+
{
319+
$this->alwaysWrittenTags = [];
320+
$this->alwaysReadTags = [];
321+
$this->analyse([__DIR__ . '/data/bug-9361.php'], []);
322+
}
323+
324+
public function testBug7251(): void
325+
{
326+
$this->alwaysWrittenTags = [];
327+
$this->alwaysReadTags = [];
328+
$this->analyse([__DIR__ . '/data/bug-7251.php'], []);
329+
}
330+
317331
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Bug7251;
4+
5+
class Foo
6+
{
7+
private $bar;
8+
9+
public function doStuff()
10+
{
11+
$this->setToOne($this->bar);
12+
}
13+
14+
private function setToOne(&$var)
15+
{
16+
$var = 1;
17+
}
18+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace Bug9361;
4+
5+
class Option
6+
{
7+
/**
8+
* @var mixed
9+
*/
10+
private $Bound;
11+
12+
/**
13+
* @param mixed $var
14+
* @return $this
15+
*/
16+
public function bind(&$var)
17+
{
18+
$this->Bound = &$var;
19+
20+
return $this;
21+
}
22+
23+
/**
24+
* @param mixed $value
25+
* @return $this
26+
*/
27+
public function setValue($value)
28+
{
29+
if ($this->Bound !== $value) {
30+
$this->Bound = $value;
31+
}
32+
33+
return $this;
34+
}
35+
}
36+
37+
class Command
38+
{
39+
/**
40+
* @var mixed
41+
*/
42+
private $Value;
43+
44+
/**
45+
* @return Option[]
46+
*/
47+
public function getOptions()
48+
{
49+
return [
50+
(new Option())->bind($this->Value),
51+
];
52+
}
53+
54+
public function run(): void
55+
{
56+
$value = $this->Value;
57+
}
58+
}

tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,4 +623,23 @@ public function testBug11275(): void
623623
]);
624624
}
625625

626+
public function testBug11617(): void
627+
{
628+
$this->checkExplicitMixed = true;
629+
$this->analyse([__DIR__ . '/data/bug-11617.php'], [
630+
[
631+
'Property Bug11617\HelloWorld::$params (array<string, string>) does not accept array<int|string, array|string>.',
632+
14,
633+
],
634+
[
635+
'Property Bug11617\HelloWorld::$params (array<string, string>) does not accept array<int|string, array|string>.',
636+
16,
637+
],
638+
[
639+
'Property Bug11617\HelloWorld::$params (array<string, string>) does not accept array<int|string, array|string>.',
640+
21,
641+
],
642+
]);
643+
}
644+
626645
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Bug11617;
4+
5+
class HelloWorld
6+
{
7+
/**
8+
* @var array<string, string>
9+
*/
10+
private $params;
11+
12+
public function sayHello(string $query): void
13+
{
14+
\parse_str($query, $this->params);
15+
\parse_str($query, $tmp);
16+
$this->params = $tmp;
17+
18+
/** @var array<string, string> $foo */
19+
$foo = [];
20+
\parse_str($query, $foo);
21+
$this->params = $foo;
22+
}
23+
}

0 commit comments

Comments
 (0)