Skip to content

Commit

Permalink
Merge pull request #8485 from doctrine/2.8.x-merge-up-into-2.9.x_602d…
Browse files Browse the repository at this point in the history
…59a0aa86b9.63081052

Merge release 2.8.2 into 2.9.x
  • Loading branch information
greg0ire committed Feb 17, 2021
2 parents e2e59e9 + 49864a7 commit 0ae53a6
Show file tree
Hide file tree
Showing 431 changed files with 5,426 additions and 2,126 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/tests export-ignore
/tools export-ignore
/docs export-ignore
/.github export-ignore
.gitattributes export-ignore
.gitignore export-ignore
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/coding-standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ jobs:
- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"

- name: "Install git-phpcs"
run: "wget https://github.com/diff-sniffer/git/releases/download/0.3.2/git-phpcs.phar"
- name: "Install diff-sniffer"
run: "wget https://github.com/diff-sniffer/diff-sniffer/releases/download/0.5.1/diff-sniffer.phar"

- name: "Fetch head branch"
run: "git remote set-branches --add origin $GITHUB_BASE_REF && git fetch origin $GITHUB_BASE_REF"

- name: "Run git-phpcs"
run: "php git-phpcs.phar origin/$GITHUB_BASE_REF...$GITHUB_SHA --report=checkstyle | cs2pr"
- name: "Run diff-sniffer"
run: "php diff-sniffer.phar origin/$GITHUB_BASE_REF...$GITHUB_SHA --report=checkstyle | cs2pr"

- name: "Run phpcbf"
run: "vendor/bin/phpcbf"
Expand Down
32 changes: 20 additions & 12 deletions lib/Doctrine/ORM/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Doctrine\ORM\Internal\Hydration\IterableResult;
use Doctrine\ORM\Mapping\MappingException as ORMMappingException;
use Doctrine\ORM\Query\Parameter;
use Doctrine\ORM\Query\QueryException;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\Persistence\Mapping\MappingException;
use Traversable;
Expand Down Expand Up @@ -793,7 +794,7 @@ public function getResult($hydrationMode = self::HYDRATE_OBJECT)
*
* Alias for execute(null, HYDRATE_ARRAY).
*
* @return array
* @return array<int,mixed>
*/
public function getArrayResult()
{
Expand All @@ -805,7 +806,7 @@ public function getArrayResult()
*
* Alias for execute(null, HYDRATE_SCALAR).
*
* @return array
* @return array<int,mixed>
*/
public function getScalarResult()
{
Expand Down Expand Up @@ -935,7 +936,7 @@ public function hasHint($name)
/**
* Return the key value map of query hints that are currently set.
*
* @return array
* @return array<string,mixed>
*/
public function getHints()
{
Expand All @@ -948,8 +949,8 @@ public function getHints()
*
* @deprecated
*
* @param ArrayCollection|array|null $parameters The query parameters.
* @param string|int|null $hydrationMode The hydration mode to use.
* @param ArrayCollection|mixed[]|null $parameters The query parameters.
* @param string|int|null $hydrationMode The hydration mode to use.
*
* @return IterableResult
*/
Expand Down Expand Up @@ -1000,7 +1001,12 @@ public function toIterable(iterable $parameters = [], $hydrationMode = null): it
$this->setParameters($parameters);
}

$rsm = $this->getResultSetMapping();
$rsm = $this->getResultSetMapping();

if ($rsm->isMixed && count($rsm->scalarMappings) > 0) {
throw QueryException::iterateWithMixedResultNotAllowed();
}

$stmt = $this->_doExecute();

return $this->_em->newHydrator($this->_hydrationMode)->toIterable($stmt, $rsm, $this->_hints);
Expand Down Expand Up @@ -1028,8 +1034,8 @@ public function execute($parameters = null, $hydrationMode = null)
/**
* Execute query ignoring second level cache.
*
* @param ArrayCollection|array|null $parameters
* @param string|int|null $hydrationMode
* @param ArrayCollection|mixed[]|null $parameters
* @param string|int|null $hydrationMode
*
* @return mixed
*
Expand Down Expand Up @@ -1089,8 +1095,8 @@ private function executeIgnoreQueryCache($parameters = null, $hydrationMode = nu
/**
* Load from second level cache or executes the query and put into cache.
*
* @param ArrayCollection|array|null $parameters
* @param string|int|null $hydrationMode
* @param ArrayCollection|mixed[]|null $parameters
* @param string|int|null $hydrationMode
*
* @return mixed
*
Expand Down Expand Up @@ -1232,9 +1238,11 @@ protected function getHash()
$query = $this->getSQL();
$hints = $this->getHints();
$params = array_map(function (Parameter $parameter) {
$value = $parameter->getValue();

// Small optimization
// Does not invoke processParameterValue for scalar values
if (is_scalar($value = $parameter->getValue())) {
// Does not invoke processParameterValue for scalar value
if (is_scalar($value)) {
return $value;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/ORM/Cache/AssociationCacheEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AssociationCacheEntry implements CacheEntry
/**
* READ-ONLY: Public only for performance reasons, it should be considered immutable.
*
* @var array The entity identifier
* @var array<string, mixed> The entity identifier
*/
public $identifier;

Expand All @@ -40,8 +40,8 @@ class AssociationCacheEntry implements CacheEntry
public $class;

/**
* @param string $class The entity class.
* @param array $identifier The entity identifier.
* @param string $class The entity class.
* @param array<string, mixed> $identifier The entity identifier.
*/
public function __construct($class, array $identifier)
{
Expand All @@ -54,7 +54,7 @@ public function __construct($class, array $identifier)
*
* This method allow Doctrine\Common\Cache\PhpFileCache compatibility
*
* @param array $values array containing property values
* @param array<string, mixed> $values array containing property values
*
* @return AssociationCacheEntry
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Cache/CacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function buildCollectionHydrator(EntityManagerInterface $em, array $mappi
/**
* Build a cache region
*
* @param array $cache The cache configuration.
* @param array<string,mixed> $cache The cache configuration.
*
* @return Region The cache region.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Cache/CollectionCacheEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(array $identifiers)
*
* This method allows for Doctrine\Common\Cache\PhpFileCache compatibility
*
* @param array $values array containing property values
* @param array<string, mixed> $values array containing property values
*
* @return CollectionCacheEntry
*/
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/ORM/Cache/CollectionCacheKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CollectionCacheKey extends CacheKey
/**
* READ-ONLY: Public only for performance reasons, it should be considered immutable.
*
* @var array The owner entity identifier
* @var array<string, mixed> The owner entity identifier
*/
public $ownerIdentifier;

Expand All @@ -52,9 +52,9 @@ class CollectionCacheKey extends CacheKey
public $association;

/**
* @param string $entityClass The entity class.
* @param string $association The field name that represents the association.
* @param array $ownerIdentifier The identifier of the owning entity.
* @param string $entityClass The entity class.
* @param string $association The field name that represents the association.
* @param array<string, mixed> $ownerIdentifier The identifier of the owning entity.
*/
public function __construct($entityClass, $association, array $ownerIdentifier)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Cache/CollectionHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function buildCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key
* @param CollectionCacheEntry $entry The cached collection entry.
* @param PersistentCollection $collection The collection to load the cache into.
*
* @return array
* @return mixed[]
*/
public function loadCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key, CollectionCacheEntry $entry, PersistentCollection $collection);
}
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Cache/DefaultCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ private function buildCollectionCacheKey(ClassMetadata $metadata, $association,
* @param ClassMetadata $metadata The entity metadata.
* @param mixed $identifier The entity identifier.
*
* @return array
* @return array<string, mixed>
*/
private function toIdentifierArray(ClassMetadata $metadata, $identifier)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Cache/DefaultCollectionHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ public function loadCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key,
$targetRegion = $targetPersister->getCacheRegion();
$list = [];

/** @var EntityCacheEntry[]|null $entityEntries */
$entityEntries = $targetRegion->getMultiple($entry);

if ($entityEntries === null) {
return null;
}

/** @var EntityCacheEntry[] $entityEntries */
foreach ($entityEntries as $index => $entityEntry) {
$list[$index] = $this->uow->createEntity($entityEntry->class, $entityEntry->resolveAssociationEntries($this->em), self::$hints);
}
Expand Down
13 changes: 8 additions & 5 deletions lib/Doctrine/ORM/Cache/DefaultQueryCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = []
$assocMetadata = $this->em->getClassMetadata($assoc['targetEntity']);

if ($assoc['type'] & ClassMetadata::TO_ONE) {
if (($assocEntry = $assocRegion->get($assocKey = new EntityCacheKey($assocMetadata->rootEntityName, $assoc['identifier']))) === null) {
$assocKey = new EntityCacheKey($assocMetadata->rootEntityName, $assoc['identifier']);
$assocEntry = $assocRegion->get($assocKey);

if ($assocEntry === null) {
if ($this->cacheLogger !== null) {
$this->cacheLogger->entityCacheMiss($assocRegion->getName(), $assocKey);
}
Expand Down Expand Up @@ -398,7 +401,7 @@ private function storeAssociationCache(QueryCacheKey $key, array $assoc, $assocV
* @param string $assocAlias
* @param object $entity
*
* @return array|object
* @return array<object>|object
*/
private function getAssociationValue(ResultSetMapping $rsm, $assocAlias, $entity)
{
Expand All @@ -422,10 +425,10 @@ private function getAssociationValue(ResultSetMapping $rsm, $assocAlias, $entity
}

/**
* @param mixed $value
* @param array $path
* @param mixed $value
* @param array<mixed> $path
*
* @return array|object|null
* @return array<object>|object|null
*/
private function getAssociationPathValue($value, array $path)
{
Expand Down
10 changes: 5 additions & 5 deletions lib/Doctrine/ORM/Cache/EntityCacheEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class EntityCacheEntry implements CacheEntry
/**
* READ-ONLY: Public only for performance reasons, it should be considered immutable.
*
* @var array The entity map data
* @var array<string,mixed> The entity map data
*/
public $data;

Expand All @@ -44,8 +44,8 @@ class EntityCacheEntry implements CacheEntry
public $class;

/**
* @param string $class The entity class.
* @param array $data The entity data.
* @param string $class The entity class.
* @param array<string,mixed> $data The entity data.
*/
public function __construct($class, array $data)
{
Expand All @@ -58,7 +58,7 @@ public function __construct($class, array $data)
*
* This method allow Doctrine\Common\Cache\PhpFileCache compatibility
*
* @param array $values array containing property values
* @param array<string,mixed> $values array containing property values
*
* @return EntityCacheEntry
*/
Expand All @@ -70,7 +70,7 @@ public static function __set_state(array $values)
/**
* Retrieves the entity data resolving cache entries
*
* @return array
* @return array<string, mixed>
*/
public function resolveAssociationEntries(EntityManagerInterface $em)
{
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Cache/EntityCacheKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class EntityCacheKey extends CacheKey
/**
* READ-ONLY: Public only for performance reasons, it should be considered immutable.
*
* @var array The entity identifier
* @var array<string, mixed> The entity identifier
*/
public $identifier;

Expand All @@ -45,8 +45,8 @@ class EntityCacheKey extends CacheKey
public $entityClass;

/**
* @param string $entityClass The entity class name. In a inheritance hierarchy it should always be the root entity class.
* @param array $identifier The entity identifier
* @param string $entityClass The entity class name. In a inheritance hierarchy it should always be the root entity class.
* @param array<string, mixed> $identifier The entity identifier
*/
public function __construct($entityClass, array $identifier)
{
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Cache/Logging/StatisticsCacheLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,23 @@ public function getRegionPutCount($regionName)
}

/**
* @return array
* @return array<string, int>
*/
public function getRegionsMiss()
{
return $this->cacheMissCountMap;
}

/**
* @return array
* @return array<string, int>
*/
public function getRegionsHit()
{
return $this->cacheHitCountMap;
}

/**
* @return array
* @return array<string, int>
*/
public function getRegionsPut()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,25 @@ public function getTargetEntityMetadata()
*/
public function loadCollectionCache(PersistentCollection $collection, CollectionCacheKey $key)
{
if (($cache = $this->region->get($key)) === null) {
return null;
}
$cache = $this->region->get($key);

if (($cache = $this->hydrator->loadCacheEntry($this->sourceEntity, $key, $cache, $collection)) === null) {
if ($cache === null) {
return null;
}

return $cache;
return $this->hydrator->loadCacheEntry($this->sourceEntity, $key, $cache, $collection);
}

/**
* {@inheritdoc}
*/
public function storeCollectionCache(CollectionCacheKey $key, $elements)
{
/** @var CachedEntityPersister $targetPersister */
$associationMapping = $this->sourceEntity->associationMappings[$key->association];
$targetPersister = $this->uow->getEntityPersister($this->targetEntity->rootEntityName);
$targetRegion = $targetPersister->getCacheRegion();
$targetHydrator = $targetPersister->getEntityHydrator();
assert($targetPersister instanceof CachedEntityPersister);
$targetRegion = $targetPersister->getCacheRegion();
$targetHydrator = $targetPersister->getEntityHydrator();

// Only preserve ordering if association configured it
if (! (isset($associationMapping['indexBy']) && $associationMapping['indexBy'])) {
Expand Down

0 comments on commit 0ae53a6

Please sign in to comment.