Skip to content

Commit

Permalink
Merge pull request #313 from VincentLanglet/lazyCollection
Browse files Browse the repository at this point in the history
Update phpdoc of the AbstractLazyCollection
  • Loading branch information
malarzm authored Aug 15, 2022
2 parents ff49ca8 + e732b16 commit 1269d42
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 9 additions & 2 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 LogicException;
use ReturnTypeWillChange;
use Traversable;

Expand All @@ -18,8 +19,8 @@ abstract class AbstractLazyCollection implements Collection
/**
* The backed collection to use
*
* @psalm-var Collection<TKey,T>
* @var Collection<mixed>
* @psalm-var Collection<TKey,T>|null
* @var Collection<mixed>|null
*/
protected $collection;

Expand Down Expand Up @@ -356,6 +357,8 @@ public function isInitialized()
* Initialize the collection
*
* @return void
*
* @psalm-assert Collection<TKey,T> $this->collection
*/
protected function initialize()
{
Expand All @@ -365,6 +368,10 @@ protected function initialize()

$this->doInitialize();
$this->initialized = true;

if ($this->collection === null) {
throw new LogicException('You must initialize the collection property in the doInitialize() method.');
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ parameters:
-
message: '~Parameter #1 \$key of method Doctrine\\Common\\Collections\\ArrayCollection<TKey of \(int\|string\),T>::set\(\) expects TKey of \(int\|string\), int\|string given\.~'
path: 'lib/Doctrine/Common/Collections/ArrayCollection.php'
-
message: '~Cannot call method .* on Doctrine\\Common\\Collections\\Collection<TKey of \(int\|string\), T>\|null\.~'
path: 'lib/Doctrine/Common/Collections/AbstractLazyCollection.php'

0 comments on commit 1269d42

Please sign in to comment.