Skip to content

Commit

Permalink
fix: Mark array_shift as having side effects
Browse files Browse the repository at this point in the history
  • Loading branch information
ryium committed Nov 10, 2022
1 parent 582a9cb commit 37b4a74
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions bin/functionMetadata_original.php
Expand Up @@ -36,6 +36,7 @@
'array_replace' => ['hasSideEffects' => false],
'array_replace_recursive' => ['hasSideEffects' => false],
'array_reverse' => ['hasSideEffects' => false],
'array_shift' => ['hasSideEffects' => true],
'array_slice' => ['hasSideEffects' => false],
'array_sum' => ['hasSideEffects' => false],
'array_udiff' => ['hasSideEffects' => false],
Expand Down
1 change: 1 addition & 0 deletions resources/functionMetadata.php
Expand Up @@ -702,6 +702,7 @@
'array_replace_recursive' => ['hasSideEffects' => false],
'array_reverse' => ['hasSideEffects' => false],
'array_search' => ['hasSideEffects' => false],
'array_shift' => ['hasSideEffects' => true],
'array_slice' => ['hasSideEffects' => false],
'array_sum' => ['hasSideEffects' => false],
'array_udiff' => ['hasSideEffects' => false],
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Expand Up @@ -1127,6 +1127,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/static-has-method.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/mixed-to-number.php');
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Variables/data/bug-8113.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8084.php');
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/PHPStan/Analyser/data/bug-8084.php
@@ -0,0 +1,16 @@
<?php

namespace Bug8084;

use function array_shift;
use function PHPStan\Testing\assertType;

class Bug8084
{
public function run(array $arr): void
{
/** @var array{a: 0, b?: 1} $arr */
assertType('0', array_shift($arr) ?? throw new \Exception());
assertType('1|null', array_shift($arr));
}
}

0 comments on commit 37b4a74

Please sign in to comment.