From 36bd63866473e58c306984d1b2daaee217f1e0d5 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 26 Jul 2021 20:11:31 +0200 Subject: [PATCH] Add ReturnTypeWillChange where necessary --- .github/workflows/coding-standards.yml | 2 +- .github/workflows/static-analysis.yml | 4 ++-- lib/Doctrine/Common/Collections/AbstractLazyCollection.php | 7 +++++++ lib/Doctrine/Common/Collections/ArrayCollection.php | 7 +++++++ phpstan.neon.dist | 3 +++ psalm.xml.dist | 7 +++++++ 6 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 5768a4e72..84d639f82 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -19,7 +19,7 @@ jobs: strategy: matrix: php-version: - - "7.4" + - "8.0" steps: - name: "Checkout" diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 912067c96..f0a0ce9e6 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -19,7 +19,7 @@ jobs: strategy: matrix: php-version: - - "7.4" + - "8.0" steps: - name: "Checkout code" @@ -44,7 +44,7 @@ jobs: strategy: matrix: php-version: - - "7.4" + - "8.0" steps: - name: "Checkout code" diff --git a/lib/Doctrine/Common/Collections/AbstractLazyCollection.php b/lib/Doctrine/Common/Collections/AbstractLazyCollection.php index aa9444000..726e009ef 100644 --- a/lib/Doctrine/Common/Collections/AbstractLazyCollection.php +++ b/lib/Doctrine/Common/Collections/AbstractLazyCollection.php @@ -3,6 +3,7 @@ namespace Doctrine\Common\Collections; use Closure; +use ReturnTypeWillChange; use Traversable; /** @@ -30,6 +31,7 @@ abstract class AbstractLazyCollection implements Collection * * @return int */ + #[ReturnTypeWillChange] public function count() { $this->initialize(); @@ -282,6 +284,7 @@ public function slice($offset, $length = null) * * @psalm-return Traversable */ + #[ReturnTypeWillChange] public function getIterator() { $this->initialize(); @@ -296,6 +299,7 @@ public function getIterator() * * @psalm-param TKey $offset */ + #[ReturnTypeWillChange] public function offsetExists($offset) { $this->initialize(); @@ -312,6 +316,7 @@ public function offsetExists($offset) * * @psalm-param TKey $offset */ + #[ReturnTypeWillChange] public function offsetGet($offset) { $this->initialize(); @@ -326,6 +331,7 @@ public function offsetGet($offset) * * @psalm-param TKey $offset */ + #[ReturnTypeWillChange] public function offsetSet($offset, $value) { $this->initialize(); @@ -337,6 +343,7 @@ public function offsetSet($offset, $value) * * @psalm-param TKey $offset */ + #[ReturnTypeWillChange] public function offsetUnset($offset) { $this->initialize(); diff --git a/lib/Doctrine/Common/Collections/ArrayCollection.php b/lib/Doctrine/Common/Collections/ArrayCollection.php index ff4825524..0f1bdd659 100644 --- a/lib/Doctrine/Common/Collections/ArrayCollection.php +++ b/lib/Doctrine/Common/Collections/ArrayCollection.php @@ -5,6 +5,7 @@ use ArrayIterator; use Closure; use Doctrine\Common\Collections\Expr\ClosureExpressionVisitor; +use ReturnTypeWillChange; use Traversable; use function array_filter; @@ -172,6 +173,7 @@ public function removeElement($element) * * @psalm-param TKey $offset */ + #[ReturnTypeWillChange] public function offsetExists($offset) { return $this->containsKey($offset); @@ -184,6 +186,7 @@ public function offsetExists($offset) * * @psalm-param TKey $offset */ + #[ReturnTypeWillChange] public function offsetGet($offset) { return $this->get($offset); @@ -194,6 +197,7 @@ public function offsetGet($offset) * * {@inheritDoc} */ + #[ReturnTypeWillChange] public function offsetSet($offset, $value) { if (! isset($offset)) { @@ -212,6 +216,7 @@ public function offsetSet($offset, $value) * * @psalm-param TKey $offset */ + #[ReturnTypeWillChange] public function offsetUnset($offset) { $this->remove($offset); @@ -284,6 +289,7 @@ public function getValues() * * @return int */ + #[ReturnTypeWillChange] public function count() { return count($this->elements); @@ -327,6 +333,7 @@ public function isEmpty() * * @psalm-return Traversable */ + #[ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->elements); diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 83a502e0e..9fa9195a8 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -12,3 +12,6 @@ parameters: - message: '~Array \(array\\) 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./' diff --git a/psalm.xml.dist b/psalm.xml.dist index 7bd9d53c4..3b5d11113 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -54,5 +54,12 @@ + + + + + + +