Skip to content

Commit

Permalink
Evaluate breakage induced by doctrine/collection
Browse files Browse the repository at this point in the history
In doctrine/orm, we implement/inherit types defined in
doctrine/collection, which makes compatibility with collection v3 extra
difficult.

It would be possible albeit to implement a backwards-compatible layer
with traits, the alternative being to revert the return type additions
and postpone them to Collections v3.
  • Loading branch information
greg0ire committed Sep 27, 2022
1 parent 6e8afee commit 494f186
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 38 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"composer-runtime-api": "^2",
"ext-ctype": "*",
"doctrine/cache": "^1.12.1 || ^2.1.1",
"doctrine/collections": "^1.5",
"doctrine/collections": "^1.5 || 2.0.x@dev",
"doctrine/common": "^3.0.3",
"doctrine/dbal": "^2.13.1 || ^3.2",
"doctrine/deprecations": "^0.5.3 || ^1",
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/EntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use BadMethodCallException;
use Doctrine\Common\Collections\AbstractLazyCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\ReadableCollection;
use Doctrine\Common\Collections\Selectable;
use Doctrine\Common\Persistence\PersistentObject;
use Doctrine\DBAL\LockMode;
Expand Down Expand Up @@ -326,7 +327,7 @@ protected function getClassMetadata()
* @return AbstractLazyCollection
* @psalm-return AbstractLazyCollection<int, T>&Selectable<int, T>
*/
public function matching(Criteria $criteria)
public function matching(Criteria $criteria): ReadableCollection
{
$persister = $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName);

Expand Down
16 changes: 6 additions & 10 deletions lib/Doctrine/ORM/LazyCriteriaCollection.php
Original file line number Diff line number Diff line change
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;
use ReturnTypeWillChange;
Expand Down Expand Up @@ -43,11 +44,8 @@ public function __construct(EntityPersister $entityPersister, Criteria $criteria

/**
* Do an efficient count on the collection
*
* @return int
*/
#[ReturnTypeWillChange]
public function count()
public function count(): int
{
if ($this->isInitialized()) {
return $this->collection->count();
Expand All @@ -66,7 +64,7 @@ public function count()
*
* @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 @@ -80,10 +78,8 @@ public function isEmpty()
*
* @param object $element
* @psalm-param TValue $element
*
* @return bool
*/
public function contains($element)
public function contains($element): bool
{
if ($this->isInitialized()) {
return $this->collection->contains($element);
Expand All @@ -95,7 +91,7 @@ public function contains($element)
/**
* {@inheritDoc}
*/
public function matching(Criteria $criteria)
public function matching(Criteria $criteria): ReadableCollection
{
$this->initialize();
assert($this->collection instanceof Selectable);
Expand All @@ -106,7 +102,7 @@ public function matching(Criteria $criteria)
/**
* {@inheritDoc}
*/
protected function doInitialize()
protected function doInitialize(): void
{
$elements = $this->entityPersister->loadCriteria($this->criteria);
$this->collection = new ArrayCollection($elements);
Expand Down
14 changes: 5 additions & 9 deletions lib/Doctrine/ORM/PersistentCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public function setInitialized($bool): void
/**
* {@inheritdoc}
*/
public function remove($key)
public function remove($key): mixed
{
// TODO: If the keys are persistent as well (not yet implemented)
// and the collection is not initialized and orphanRemoval is
Expand Down Expand Up @@ -408,7 +408,7 @@ public function contains($element): bool
/**
* {@inheritdoc}
*/
public function get($key)
public function get($key): mixed
{
if (
! $this->initialized
Expand Down Expand Up @@ -479,8 +479,7 @@ public function offsetExists($offset): bool
/**
* {@inheritdoc}
*/
#[ReturnTypeWillChange]
public function offsetGet($offset)
public function offsetGet($offset): mixed
{
return $this->get($offset);
}
Expand All @@ -501,13 +500,10 @@ public function offsetSet($offset, $value): void

/**
* {@inheritdoc}
*
* @return object|null
*/
#[ReturnTypeWillChange]
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
return $this->remove($offset);
$this->remove($offset);
}

public function isEmpty(): bool
Expand Down
8 changes: 3 additions & 5 deletions lib/Doctrine/ORM/Persisters/SqlExpressionVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ public function __construct(BasicEntityPersister $persister, ClassMetadata $clas

/**
* Converts a comparison expression into the target query language output.
*
* @return mixed
*/
public function walkComparison(Comparison $comparison)
public function walkComparison(Comparison $comparison): mixed
{
$field = $comparison->getField();
$value = $comparison->getValue()->getValue(); // shortcut for walkValue()
Expand All @@ -65,7 +63,7 @@ public function walkComparison(Comparison $comparison)
*
* @throws RuntimeException
*/
public function walkCompositeExpression(CompositeExpression $expr)
public function walkCompositeExpression(CompositeExpression $expr): mixed
{
$expressionList = [];

Expand All @@ -90,7 +88,7 @@ public function walkCompositeExpression(CompositeExpression $expr)
*
* @return string
*/
public function walkValue(Value $value)
public function walkValue(Value $value): mixed
{
return '?';
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Persisters/SqlValueVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SqlValueVisitor extends ExpressionVisitor
*
* {@inheritDoc}
*/
public function walkComparison(Comparison $comparison)
public function walkComparison(Comparison $comparison): mixed
{
$value = $this->getValueFromComparison($comparison);
$field = $comparison->getField();
Expand All @@ -48,7 +48,7 @@ public function walkComparison(Comparison $comparison)
*
* {@inheritDoc}
*/
public function walkCompositeExpression(CompositeExpression $expr)
public function walkCompositeExpression(CompositeExpression $expr): mixed
{
foreach ($expr->getExpressionList() as $child) {
$this->dispatch($child);
Expand All @@ -62,7 +62,7 @@ public function walkCompositeExpression(CompositeExpression $expr)
*
* {@inheritDoc}
*/
public function walkValue(Value $value)
public function walkValue(Value $value): mixed
{
return null;
}
Expand Down
12 changes: 3 additions & 9 deletions lib/Doctrine/ORM/Query/QueryExpressionVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ private static function convertComparisonOperator($criteriaOperator)
return self::$operatorMap[$criteriaOperator] ?? null;
}

/**
* {@inheritDoc}
*/
public function walkCompositeExpression(CompositeExpression $expr)
public function walkCompositeExpression(CompositeExpression $expr): mixed
{
$expressionList = [];

Expand All @@ -103,7 +100,7 @@ public function walkCompositeExpression(CompositeExpression $expr)
/**
* {@inheritDoc}
*/
public function walkComparison(Comparison $comparison)
public function walkComparison(Comparison $comparison): mixed
{
if (! isset($this->queryAliases[0])) {
throw new QueryException('No aliases are set before invoking walkComparison().');
Expand Down Expand Up @@ -197,10 +194,7 @@ public function walkComparison(Comparison $comparison)
}
}

/**
* {@inheritDoc}
*/
public function walkValue(Value $value)
public function walkValue(Value $value): mixed
{
return $value->getValue();
}
Expand Down

0 comments on commit 494f186

Please sign in to comment.