Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to doctrine/coding-standard 10.0 on 3.0.x #10011

Merged
merged 6 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"require-dev": {
"doctrine/annotations": "^1.13",
"doctrine/coding-standard": "^9.0.2",
"doctrine/coding-standard": "^10.0",
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "1.8.2",
"phpunit/phpunit": "^9.5",
Expand Down
66 changes: 29 additions & 37 deletions lib/Doctrine/ORM/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ abstract class AbstractQuery
/**
* The user-specified ResultSetMapping to use.
*/
protected ?ResultSetMapping $_resultSetMapping = null;
protected ResultSetMapping|null $_resultSetMapping = null;

/**
* The map of query hints.
Expand All @@ -105,14 +105,14 @@ abstract class AbstractQuery
*/
protected string|int $_hydrationMode = self::HYDRATE_OBJECT;

protected ?QueryCacheProfile $_queryCacheProfile = null;
protected QueryCacheProfile|null $_queryCacheProfile = null;

/**
* Whether or not expire the result cache.
*/
protected bool $_expireResultCache = false;

protected ?QueryCacheProfile $_hydrationCacheProfile = null;
protected QueryCacheProfile|null $_hydrationCacheProfile = null;

/**
* Whether to use second level cache, if available.
Expand All @@ -124,16 +124,16 @@ abstract class AbstractQuery
/**
* Second level cache region name.
*/
protected ?string $cacheRegion = null;
protected string|null $cacheRegion = null;

/**
* Second level query cache mode.
*
* @psalm-var Cache::MODE_*|null
*/
protected ?int $cacheMode = null;
protected int|null $cacheMode = null;

protected ?CacheLogger $cacheLogger = null;
protected CacheLogger|null $cacheLogger = null;

protected int $lifetime = 0;

Expand All @@ -144,7 +144,7 @@ public function __construct(
/**
* The entity manager used by this query object.
*/
protected EntityManagerInterface $em
protected EntityManagerInterface $em,
) {
$this->parameters = new ArrayCollection();
$this->_hints = $em->getConfiguration()->getDefaultQueryHints();
Expand All @@ -169,17 +169,13 @@ public function setCacheable(bool $cacheable): static
return $this;
}

/**
* @return bool TRUE if the query results are enabled for second level cache, FALSE otherwise.
*/
/** @return bool TRUE if the query results are enabled for second level cache, FALSE otherwise. */
public function isCacheable(): bool
{
return $this->cacheable;
}

/**
* @return $this
*/
/** @return $this */
public function setCacheRegion(string $cacheRegion): static
{
$this->cacheRegion = $cacheRegion;
Expand All @@ -192,14 +188,12 @@ public function setCacheRegion(string $cacheRegion): static
*
* @return string|null The cache region name; NULL indicates the default region.
*/
public function getCacheRegion(): ?string
public function getCacheRegion(): string|null
{
return $this->cacheRegion;
}

/**
* @return bool TRUE if the query cache and second level cache are enabled, FALSE otherwise.
*/
/** @return bool TRUE if the query cache and second level cache are enabled, FALSE otherwise. */
protected function isCacheEnabled(): bool
{
return $this->cacheable && $this->hasCache;
Expand All @@ -222,10 +216,8 @@ public function setLifetime(int $lifetime): static
return $this;
}

/**
* @psalm-return Cache::MODE_*|null
*/
public function getCacheMode(): ?int
/** @psalm-return Cache::MODE_*|null */
public function getCacheMode(): int|null
{
return $this->cacheMode;
}
Expand Down Expand Up @@ -288,7 +280,7 @@ public function getParameters(): ArrayCollection
*
* @return Parameter|null The value of the bound parameter, or NULL if not available.
*/
public function getParameter(int|string $key): ?Parameter
public function getParameter(int|string $key): Parameter|null
{
$key = Parameter::normalizeName($key);

Expand Down Expand Up @@ -450,7 +442,7 @@ public function setResultSetMapping(ResultSetMapping $rsm): static
/**
* Gets the ResultSetMapping used for hydration.
*/
protected function getResultSetMapping(): ?ResultSetMapping
protected function getResultSetMapping(): ResultSetMapping|null
{
return $this->_resultSetMapping;
}
Expand Down Expand Up @@ -486,7 +478,7 @@ private function translateNamespaces(ResultSetMapping $rsm): void
* $query->setHydrationCacheProfile(new QueryCacheProfile());
* $query->setHydrationCacheProfile(new QueryCacheProfile($lifetime, $resultKey));
*/
public function setHydrationCacheProfile(?QueryCacheProfile $profile): static
public function setHydrationCacheProfile(QueryCacheProfile|null $profile): static
{
if ($profile === null) {
$this->_hydrationCacheProfile = null;
Expand All @@ -506,7 +498,7 @@ public function setHydrationCacheProfile(?QueryCacheProfile $profile): static
return $this;
}

public function getHydrationCacheProfile(): ?QueryCacheProfile
public function getHydrationCacheProfile(): QueryCacheProfile|null
{
return $this->_hydrationCacheProfile;
}
Expand All @@ -519,7 +511,7 @@ public function getHydrationCacheProfile(): ?QueryCacheProfile
*
* @return $this
*/
public function setResultCacheProfile(?QueryCacheProfile $profile): static
public function setResultCacheProfile(QueryCacheProfile|null $profile): static
{
if ($profile === null) {
$this->_queryCacheProfile = null;
Expand All @@ -542,7 +534,7 @@ public function setResultCacheProfile(?QueryCacheProfile $profile): static
/**
* Defines a cache driver to be used for caching result sets and implicitly enables caching.
*/
public function setResultCache(?CacheItemPoolInterface $resultCache): static
public function setResultCache(CacheItemPoolInterface|null $resultCache): static
{
if ($resultCache === null) {
if ($this->_queryCacheProfile) {
Expand All @@ -568,7 +560,7 @@ public function setResultCache(?CacheItemPoolInterface $resultCache): static
*
* @return $this
*/
public function enableResultCache(?int $lifetime = null, ?string $resultCacheId = null): static
public function enableResultCache(int|null $lifetime = null, string|null $resultCacheId = null): static
{
$this->setResultCacheLifetime($lifetime);
$this->setResultCacheId($resultCacheId);
Expand All @@ -595,7 +587,7 @@ public function disableResultCache(): static
*
* @return $this
*/
public function setResultCacheLifetime(?int $lifetime): static
public function setResultCacheLifetime(int|null $lifetime): static
{
$lifetime = (int) $lifetime;

Expand Down Expand Up @@ -639,7 +631,7 @@ public function getExpireResultCache(): bool
return $this->_expireResultCache;
}

public function getQueryCacheProfile(): ?QueryCacheProfile
public function getQueryCacheProfile(): QueryCacheProfile|null
{
return $this->_queryCacheProfile;
}
Expand Down Expand Up @@ -854,7 +846,7 @@ public function getHints(): array
*/
public function toIterable(
ArrayCollection|array $parameters = [],
string|int|null $hydrationMode = null
string|int|null $hydrationMode = null,
): iterable {
if ($hydrationMode !== null) {
$this->setHydrationMode($hydrationMode);
Expand Down Expand Up @@ -886,7 +878,7 @@ public function toIterable(
*/
public function execute(
ArrayCollection|array|null $parameters = null,
string|int|null $hydrationMode = null
string|int|null $hydrationMode = null,
): mixed {
if ($this->cacheable && $this->isCacheEnabled()) {
return $this->executeUsingQueryCache($parameters, $hydrationMode);
Expand All @@ -903,7 +895,7 @@ public function execute(
*/
private function executeIgnoreQueryCache(
ArrayCollection|array|null $parameters = null,
string|int|null $hydrationMode = null
string|int|null $hydrationMode = null,
): mixed {
if ($hydrationMode !== null) {
$this->setHydrationMode($hydrationMode);
Expand Down Expand Up @@ -974,7 +966,7 @@ private function getHydrationCache(): CacheItemPoolInterface
*/
private function executeUsingQueryCache(
ArrayCollection|array|null $parameters = null,
string|int|null $hydrationMode = null
string|int|null $hydrationMode = null,
): mixed {
$rsm = $this->getResultSetMapping();
if ($rsm === null) {
Expand All @@ -986,7 +978,7 @@ private function executeUsingQueryCache(
$this->getHash(),
$this->lifetime,
$this->cacheMode ?: Cache::MODE_NORMAL,
$this->getTimestampKey()
$this->getTimestampKey(),
);

$result = $queryCache->get($queryKey, $rsm, $this->_hints);
Expand All @@ -1013,7 +1005,7 @@ private function executeUsingQueryCache(
return $result;
}

private function getTimestampKey(): ?TimestampCacheKey
private function getTimestampKey(): TimestampCacheKey|null
{
assert($this->_resultSetMapping !== null);
$entityName = reset($this->_resultSetMapping->aliasMap);
Expand Down Expand Up @@ -1060,7 +1052,7 @@ protected function getHydrationCacheId(): array
* If this is not explicitly set by the developer then a hash is automatically
* generated for you.
*/
public function setResultCacheId(?string $id): static
public function setResultCacheId(string|null $id): static
{
if (! $this->_queryCacheProfile) {
return $this->setResultCacheProfile(new QueryCacheProfile(0, $id));
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/ORM/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ interface Cache
*/
public const MODE_REFRESH = 4;

public function getEntityCacheRegion(string $className): ?Region;
public function getEntityCacheRegion(string $className): Region|null;

public function getCollectionCacheRegion(string $className, string $association): ?Region;
public function getCollectionCacheRegion(string $className, string $association): Region|null;

/**
* Determine whether the cache contains data for the given entity "instance".
Expand Down Expand Up @@ -90,7 +90,7 @@ public function containsQuery(string $regionName): bool;
/**
* Evicts all cached query results under the given name, or default query cache if the region name is NULL.
*/
public function evictQueryRegion(?string $regionName = null): void;
public function evictQueryRegion(string|null $regionName = null): void;

/**
* Evict data from all query regions.
Expand All @@ -102,5 +102,5 @@ public function evictQueryRegions(): void;
*
* @param string|null $regionName Query cache region name, or default query cache if the region name is NULL.
*/
public function getQueryCache(?string $regionName = null): QueryCache;
public function getQueryCache(string|null $regionName = null): QueryCache;
}
14 changes: 7 additions & 7 deletions lib/Doctrine/ORM/Cache/CacheConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
*/
class CacheConfiguration
{
private ?CacheFactory $cacheFactory = null;
private ?RegionsConfiguration $regionsConfig = null;
private ?CacheLogger $cacheLogger = null;
private ?QueryCacheValidator $queryValidator = null;
private CacheFactory|null $cacheFactory = null;
private RegionsConfiguration|null $regionsConfig = null;
private CacheLogger|null $cacheLogger = null;
private QueryCacheValidator|null $queryValidator = null;

public function getCacheFactory(): ?CacheFactory
public function getCacheFactory(): CacheFactory|null
{
return $this->cacheFactory;
}
Expand All @@ -26,7 +26,7 @@ public function setCacheFactory(CacheFactory $factory): void
$this->cacheFactory = $factory;
}

public function getCacheLogger(): ?CacheLogger
public function getCacheLogger(): CacheLogger|null
{
return $this->cacheLogger;
}
Expand All @@ -49,7 +49,7 @@ public function setRegionsConfiguration(RegionsConfiguration $regionsConfig): vo
public function getQueryValidator(): QueryCacheValidator
{
return $this->queryValidator ??= new TimestampQueryCacheValidator(
$this->cacheFactory->getTimestampRegion()
$this->cacheFactory->getTimestampRegion(),
);
}

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 @@ -32,7 +32,7 @@ public function buildCachedCollectionPersister(EntityManagerInterface $em, Colle
/**
* Build a query cache based on the given region name
*/
public function buildQueryCache(EntityManagerInterface $em, ?string $regionName = null): QueryCache;
public function buildQueryCache(EntityManagerInterface $em, string|null $regionName = null): QueryCache;

/**
* Build an entity hydrator
Expand Down
4 changes: 1 addition & 3 deletions lib/Doctrine/ORM/Cache/CollectionCacheEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ class CollectionCacheEntry implements CacheEntry
*/
public array $identifiers;

/**
* @param CacheKey[] $identifiers List of entity identifiers hold by the collection
*/
/** @param CacheKey[] $identifiers List of entity identifiers hold by the collection */
public function __construct(array $identifiers)
{
$this->identifiers = $identifiers;
Expand Down
10 changes: 3 additions & 7 deletions lib/Doctrine/ORM/Cache/CollectionHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@
*/
interface CollectionHydrator
{
/**
* @param mixed[]|Collection $collection The collection.
*/
/** @param mixed[]|Collection $collection The collection. */
public function buildCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key, array|Collection $collection): CollectionCacheEntry;

/**
* @return mixed[]|null
*/
public function loadCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key, CollectionCacheEntry $entry, PersistentCollection $collection): ?array;
/** @return mixed[]|null */
public function loadCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key, CollectionCacheEntry $entry, PersistentCollection $collection): array|null;
}
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Cache/ConcurrentRegion.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface ConcurrentRegion extends Region
*
* @throws LockException Indicates a problem accessing the region.
*/
public function lock(CacheKey $key): ?Lock;
public function lock(CacheKey $key): Lock|null;

/**
* Attempts to read unlock the mapping for the given key.
Expand Down
Loading