Skip to content

Commit

Permalink
Fixed stub types for SplFixedArray
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Jul 23, 2021
1 parent da3790e commit cacc8bb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
8 changes: 4 additions & 4 deletions stubs/ArrayObject.stub
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ class ArrayObject implements IteratorAggregate, ArrayAccess

/**
* @template TValue
* @implements Iterator<int, TValue>
* @implements IteratorAggregate<int, TValue>
* @implements ArrayAccess<int, TValue>
* @implements Iterator<int, TValue|null>
* @implements IteratorAggregate<int, TValue|null>
* @implements ArrayAccess<int, TValue|null>
*/
class SplFixedArray implements Iterator, IteratorAggregate, ArrayAccess, Countable
{
Expand All @@ -102,7 +102,7 @@ class SplFixedArray implements Iterator, IteratorAggregate, ArrayAccess, Countab
public static function fromArray(array $array, bool $save_indexes = true): SplFixedArray { }

/**
* @return array<int, TValue>
* @return array<int, TValue|null>
*/
public function toArray(): array { }
}
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5129.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-4970.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5322.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/splfixedarray-iterator-types.php');
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tests/PHPStan/Analyser/data/splfixedarray-iterator-types.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

class HelloWorld
{
/**
* @var int[]|\SplFixedArray
* @phpstan-var \SplFixedArray<int>
*/
public $array;

public function dump() : void{
foreach($this->array as $id => $v){
\PHPStan\Testing\assertType('int|null', $this->array[$id]);
\PHPStan\Testing\assertType('int|null', $v);
}
}
}

0 comments on commit cacc8bb

Please sign in to comment.