Skip to content

Commit

Permalink
Merge pull request #10084 from greg0ire/drop-collections-1
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Oct 10, 2022
2 parents 55d58dd + dc2bd9e commit 5367ce8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 114 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -23,7 +23,7 @@
"php": "^8.1",
"composer-runtime-api": "^2",
"ext-ctype": "*",
"doctrine/collections": "^1.5 || ^2.0",
"doctrine/collections": "^2.0",
"doctrine/common": "^3.3",
"doctrine/dbal": "^3.4",
"doctrine/deprecations": "^0.5.3 || ^1",
Expand Down
35 changes: 11 additions & 24 deletions lib/Doctrine/ORM/LazyCriteriaCollection.php
Expand Up @@ -7,6 +7,7 @@
use Doctrine\Common\Collections\AbstractLazyCollection;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\ReadableCollection;
use Doctrine\Common\Collections\Selectable;
use Doctrine\ORM\Persisters\Entity\EntityPersister;

Expand All @@ -25,19 +26,12 @@
*/
class LazyCriteriaCollection extends AbstractLazyCollection implements Selectable
{
/** @var EntityPersister */
protected $entityPersister;
private int|null $count = null;

/** @var Criteria */
protected $criteria;

/** @var int|null */
private $count;

public function __construct(EntityPersister $entityPersister, Criteria $criteria)
{
$this->entityPersister = $entityPersister;
$this->criteria = $criteria;
public function __construct(
protected EntityPersister $entityPersister,
protected Criteria $criteria,
) {
}

/**
Expand All @@ -59,10 +53,8 @@ public function count(): int

/**
* check if collection is empty without loading it
*
* @return bool TRUE if the collection is empty, FALSE otherwise.
*/
public function isEmpty()
public function isEmpty(): bool
{
if ($this->isInitialized()) {
return $this->collection->isEmpty();
Expand All @@ -78,7 +70,7 @@ public function isEmpty()
*
* @template TMaybeContained
*/
public function contains($element)
public function contains(mixed $element): bool
{
if ($this->isInitialized()) {
return $this->collection->contains($element);
Expand All @@ -87,21 +79,16 @@ public function contains($element)
return $this->entityPersister->exists($element, $this->criteria);
}

/**
* {@inheritDoc}
*/
public function matching(Criteria $criteria)
/** @return ReadableCollection<TKey, TValue>&Selectable<TKey, TValue> */
public function matching(Criteria $criteria): ReadableCollection
{
$this->initialize();
assert($this->collection instanceof Selectable);

return $this->collection->matching($criteria);
}

/**
* {@inheritDoc}
*/
protected function doInitialize()
protected function doInitialize(): void
{
$elements = $this->entityPersister->loadCriteria($this->criteria);
$this->collection = new ArrayCollection($elements);
Expand Down

0 comments on commit 5367ce8

Please sign in to comment.