Skip to content

Commit

Permalink
Merge pull request #277 from derrabus/bugfix/return-type-will-change
Browse files Browse the repository at this point in the history
Add ReturnTypeWillChange where necessary
  • Loading branch information
greg0ire authored Aug 4, 2021
2 parents 6a9fc01 + 36bd638 commit a382560
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"

steps:
- name: "Checkout"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"

steps:
- name: "Checkout code"
Expand All @@ -44,7 +44,7 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"

steps:
- name: "Checkout code"
Expand Down
7 changes: 7 additions & 0 deletions lib/Doctrine/Common/Collections/AbstractLazyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Doctrine\Common\Collections;

use Closure;
use ReturnTypeWillChange;
use Traversable;

/**
Expand Down Expand Up @@ -30,6 +31,7 @@ abstract class AbstractLazyCollection implements Collection
*
* @return int
*/
#[ReturnTypeWillChange]
public function count()
{
$this->initialize();
Expand Down Expand Up @@ -281,6 +283,7 @@ public function slice($offset, $length = null)
* @return Traversable<int|string, mixed>
* @psalm-return Traversable<TKey,T>
*/
#[ReturnTypeWillChange]
public function getIterator()
{
$this->initialize();
Expand All @@ -295,6 +298,7 @@ public function getIterator()
*
* @return bool
*/
#[ReturnTypeWillChange]
public function offsetExists($offset)
{
$this->initialize();
Expand All @@ -310,6 +314,7 @@ public function offsetExists($offset)
*
* @return mixed
*/
#[ReturnTypeWillChange]
public function offsetGet($offset)
{
$this->initialize();
Expand All @@ -323,6 +328,7 @@ public function offsetGet($offset)
* @param mixed $value
* @psalm-param TKey $offset
*/
#[ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
$this->initialize();
Expand All @@ -334,6 +340,7 @@ public function offsetSet($offset, $value)
*
* @psalm-param TKey $offset
*/
#[ReturnTypeWillChange]
public function offsetUnset($offset)
{
$this->initialize();
Expand Down
7 changes: 7 additions & 0 deletions lib/Doctrine/Common/Collections/ArrayCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use ArrayIterator;
use Closure;
use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor;
use ReturnTypeWillChange;
use Traversable;

use function array_filter;
Expand Down Expand Up @@ -170,6 +171,7 @@ public function removeElement($element)
*
* @return bool
*/
#[ReturnTypeWillChange]
public function offsetExists($offset)
{
return $this->containsKey($offset);
Expand All @@ -182,6 +184,7 @@ public function offsetExists($offset)
*
* @psalm-param TKey $offset
*/
#[ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->get($offset);
Expand All @@ -192,6 +195,7 @@ public function offsetGet($offset)
*
* {@inheritDoc}
*/
#[ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if (! isset($offset)) {
Expand All @@ -210,6 +214,7 @@ public function offsetSet($offset, $value)
*
* @psalm-param TKey $offset
*/
#[ReturnTypeWillChange]
public function offsetUnset($offset)
{
$this->remove($offset);
Expand Down Expand Up @@ -282,6 +287,7 @@ public function getValues()
*
* @return int
*/
#[ReturnTypeWillChange]
public function count()
{
return count($this->elements);
Expand Down Expand Up @@ -324,6 +330,7 @@ public function isEmpty()
* @return Traversable<int|string, mixed>
* @psalm-return Traversable<TKey,T>
*/
#[ReturnTypeWillChange]
public function getIterator()
{
return new ArrayIterator($this->elements);
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ parameters:
-
message: '~Array \(array\<TKey of \(int\|string\), T\>\) does not accept key int\.~'
path: 'lib/Doctrine/Common/Collections/ArrayCollection.php'

# This class is new in PHP 8.1 and PHPStan does not know it yet.
- '/Attribute class ReturnTypeWillChange does not exist./'
7 changes: 7 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,12 @@
<file name="lib/Doctrine/Common/Collections/ArrayCollection.php"/>
</errorLevel>
</UnsafeGenericInstantiation>

<UndefinedAttributeClass>
<errorLevel type="suppress">
<!-- This class is new in PHP 8.1 and Psalm does not know it yet. -->
<referencedClass name="ReturnTypeWillChange"/>
</errorLevel>
</UndefinedAttributeClass>
</issueHandlers>
</psalm>

0 comments on commit a382560

Please sign in to comment.