Skip to content

Commit 7697398

Browse files
committed
1 parent 9693201 commit 7697398

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
@@ -322,4 +322,18 @@ public function testBug8781(): void
322322
$this->analyse([__DIR__ . '/data/bug-8781.php'], []);
323323
}
324324

325+
public function testBug9361(): void
326+
{
327+
$this->alwaysWrittenTags = [];
328+
$this->alwaysReadTags = [];
329+
$this->analyse([__DIR__ . '/data/bug-9361.php'], []);
330+
}
331+
332+
public function testBug7251(): void
333+
{
334+
$this->alwaysWrittenTags = [];
335+
$this->alwaysReadTags = [];
336+
$this->analyse([__DIR__ . '/data/bug-7251.php'], []);
337+
}
338+
325339
}
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
@@ -645,4 +645,23 @@ public function testBug11275(): void
645645
]);
646646
}
647647

648+
public function testBug11617(): void
649+
{
650+
$this->checkExplicitMixed = true;
651+
$this->analyse([__DIR__ . '/data/bug-11617.php'], [
652+
[
653+
'Property Bug11617\HelloWorld::$params (array<string, string>) does not accept array<int|string, array|string>.',
654+
14,
655+
],
656+
[
657+
'Property Bug11617\HelloWorld::$params (array<string, string>) does not accept array<int|string, array|string>.',
658+
16,
659+
],
660+
[
661+
'Property Bug11617\HelloWorld::$params (array<string, string>) does not accept array<int|string, array|string>.',
662+
21,
663+
],
664+
]);
665+
}
666+
648667
}
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)