Skip to content

Commit

Permalink
Cs fixes1 (#8475)
Browse files Browse the repository at this point in the history
* Housekeeping: CS Query, AbstractQuery, NativeQuery.

* Housekeeping: phpcs TreeWalker

* Housekeeping: CS Doctrine\ORM\EntityManager

* Housekeeping: CS Doctrine\ORM\Cache

* Upgrade git-phpcs

* Drop unused method parameter

* Describe types more precisely

Co-authored-by: Grégoire Paris <[email protected]>
  • Loading branch information
beberlei and greg0ire authored Feb 14, 2021
1 parent c7f39eb commit f833222
Show file tree
Hide file tree
Showing 26 changed files with 209 additions and 192 deletions.
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
24 changes: 13 additions & 11 deletions lib/Doctrine/ORM/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,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 @@ -807,7 +807,7 @@ public function getArrayResult()
*
* Alias for execute(null, HYDRATE_SCALAR).
*
* @return array
* @return array<int,mixed>
*/
public function getScalarResult()
{
Expand Down Expand Up @@ -937,7 +937,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 @@ -950,8 +950,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 @@ -1024,8 +1024,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 @@ -1083,8 +1083,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 @@ -1224,9 +1224,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
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ abstract class AbstractEntityPersister implements CachedEntityPersister
/**
* Associations configured as FETCH_EAGER, as well as all inverse one-to-one associations.
*
* @var array|null
* @var array<string>|null
*/
protected $joinedAssociations;

Expand Down Expand Up @@ -364,7 +364,9 @@ public function load(array $criteria, $entity = null, $assoc = null, array $hint
return $result[0];
}

if (($result = $this->persister->load($criteria, $entity, $assoc, $hints, $lockMode, $limit, $orderBy)) === null) {
$result = $this->persister->load($criteria, $entity, $assoc, $hints, $lockMode, $limit, $orderBy);

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

Expand Down Expand Up @@ -617,8 +619,8 @@ public function refresh(array $id, $entity, $lockMode = null)
}

/**
* @param array $association
* @param array $ownerId
* @param array<string, mixed> $association
* @param array<string, mixed> $ownerId
*
* @return CollectionCacheKey
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Cache/QueryCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function put(QueryCacheKey $key, ResultSetMapping $rsm, $result, array $h
/**
* @param mixed[] $hints
*
* @return array|null
* @return mixed[]|null
*/
public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = []);

Expand Down
Loading

0 comments on commit f833222

Please sign in to comment.