Skip to content

Commit d580ca3

Browse files
committed
fix array_push()/array_pop()
1 parent 886ab5c commit d580ca3

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,6 +2684,10 @@ static function (): void {
26842684

26852685
$arrayArg = $expr->getArgs()[0]->value;
26862686
$scope = $scope->invalidateExpression($arrayArg)->assignExpression($arrayArg, $arrayType, $arrayNativeType);
2687+
2688+
if ($arrayArg instanceof PropertyFetch || $arrayArg instanceof StaticPropertyFetch) {
2689+
$nodeCallback(new PropertyAssignNode($arrayArg, new TypeExpr($scope->getType($arrayArg)), false), $scope);
2690+
}
26872691
}
26882692

26892693
if (

tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,4 +860,26 @@ public function testBug13438c(): void
860860
$this->analyse([__DIR__ . '/data/bug-13438c.php'], []);
861861
}
862862

863+
public function testBug13438d(): void
864+
{
865+
$this->checkExplicitMixed = true;
866+
$this->analyse([__DIR__ . '/data/bug-13438d.php'], [
867+
[
868+
'Property Bug13438d\Test::$queue (array{}) does not accept array{1}.',
869+
18,
870+
],
871+
]);
872+
}
873+
874+
public function testBug13438e(): void
875+
{
876+
$this->checkExplicitMixed = true;
877+
$this->analyse([__DIR__ . '/data/bug-13438e.php'], [
878+
[
879+
'Property Bug13438e\Test::$queue (array{}) does not accept array{1}.',
880+
18,
881+
],
882+
]);
883+
}
884+
863885
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Bug13438d;
4+
5+
class Test
6+
{
7+
/**
8+
* @param array{} $queue
9+
*/
10+
public function __construct(
11+
private array $queue,
12+
)
13+
{
14+
}
15+
16+
public function test1(): int
17+
{
18+
return array_push($this->queue, 1);
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Bug13438e;
4+
5+
class Test
6+
{
7+
/**
8+
* @param array{} $queue
9+
*/
10+
public function __construct(
11+
private array $queue,
12+
)
13+
{
14+
}
15+
16+
public function test1(): int
17+
{
18+
return array_unshift($this->queue, 1);
19+
}
20+
}

0 commit comments

Comments
 (0)