Skip to content

Commit

Permalink
Fixed issue with ArrayAccess stub
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 17, 2020
1 parent c7ec02e commit ab85120
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion stubs/ArrayObject.stub
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface ArrayAccess
public function offsetGet($offset);

/**
* @param TKey $offset
* @param TKey|null $offset
* @param TValue $value
* @return void
*/
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Rules/Arrays/OffsetAccessAssignmentRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,10 @@ public function testInheritDocTemplateTypeResolution(): void
$this->analyse([__DIR__ . '/data/inherit-doc-template-type-resolution.php'], []);
}

public function testAssignNewOffsetToStubbedClass(): void
{
$this->checkUnionTypes = true;
$this->analyse([__DIR__ . '/data/new-offset-stub.php'], []);
}

}
15 changes: 15 additions & 0 deletions tests/PHPStan/Rules/Arrays/data/new-offset-stub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace NewOffsetStub;

/**
* @phpstan-implements \ArrayAccess<int, \stdClass>
*/
abstract class Foo implements \ArrayAccess
{

}

function (Foo $foo): void {
$foo[] = new \stdClass();
};
2 changes: 1 addition & 1 deletion tests/PHPStan/Rules/Methods/data/bug-2950.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function offsetGet($offset): float
}

/**
* @param int $offset
* @param int|null $offset
* @param float $value
*/
public function offsetSet($offset, $value): void
Expand Down

0 comments on commit ab85120

Please sign in to comment.