From 09caeb27537fb8f3ed9a72d5869e5a64e1ab2ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Mon, 6 Feb 2023 20:21:04 +0100 Subject: [PATCH] Stop relying on underscores to indicate property visibility It conflicts with our coding standard. --- lib/Doctrine/ORM/AbstractQuery.php | 98 ++++++------ lib/Doctrine/ORM/Configuration.php | 128 ++++++++-------- .../Internal/Hydration/AbstractHydrator.php | 144 +++++++++--------- .../ORM/Internal/Hydration/ArrayHydrator.php | 2 +- .../ORM/Internal/Hydration/ObjectHydrator.php | 72 ++++----- .../Hydration/SimpleObjectHydrator.php | 22 +-- lib/Doctrine/ORM/NativeQuery.php | 2 +- lib/Doctrine/ORM/Query.php | 28 ++-- .../ORM/Query/Exec/AbstractSqlExecutor.php | 4 +- .../Query/Exec/MultiTableDeleteExecutor.php | 6 +- .../Query/Exec/MultiTableUpdateExecutor.php | 4 +- .../ORM/Query/Exec/SingleSelectExecutor.php | 4 +- .../Exec/SingleTableDeleteUpdateExecutor.php | 6 +- phpcs.xml.dist | 12 -- psalm-baseline.xml | 16 +- .../Doctrine/Tests/ORM/AbstractQueryTest.php | 2 +- 16 files changed, 268 insertions(+), 282 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index ccfd230c807..7470bc74f73 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -89,30 +89,30 @@ abstract class AbstractQuery /** * The user-specified ResultSetMapping to use. */ - protected ResultSetMapping|null $_resultSetMapping = null; + protected ResultSetMapping|null $resultSetMapping = null; /** * The map of query hints. * * @psalm-var array */ - protected array $_hints = []; + protected array $hints = []; /** * The hydration mode. * * @psalm-var string|AbstractQuery::HYDRATE_* */ - protected string|int $_hydrationMode = self::HYDRATE_OBJECT; + protected string|int $hydrationMode = self::HYDRATE_OBJECT; - protected QueryCacheProfile|null $_queryCacheProfile = null; + protected QueryCacheProfile|null $queryCacheProfile = null; /** * Whether or not expire the result cache. */ - protected bool $_expireResultCache = false; + protected bool $expireResultCache = false; - protected QueryCacheProfile|null $_hydrationCacheProfile = null; + protected QueryCacheProfile|null $hydrationCacheProfile = null; /** * Whether to use second level cache, if available. @@ -147,7 +147,7 @@ public function __construct( protected EntityManagerInterface $em, ) { $this->parameters = new ArrayCollection(); - $this->_hints = $em->getConfiguration()->getDefaultQueryHints(); + $this->hints = $em->getConfiguration()->getDefaultQueryHints(); $this->hasCache = $this->em->getConfiguration()->isSecondLevelCacheEnabled(); if ($this->hasCache) { @@ -260,7 +260,7 @@ public function free(): void { $this->parameters = new ArrayCollection(); - $this->_hints = $this->em->getConfiguration()->getDefaultQueryHints(); + $this->hints = $this->em->getConfiguration()->getDefaultQueryHints(); } /** @@ -434,7 +434,7 @@ private function processArrayParameterValue(array $value): array public function setResultSetMapping(ResultSetMapping $rsm): static { $this->translateNamespaces($rsm); - $this->_resultSetMapping = $rsm; + $this->resultSetMapping = $rsm; return $this; } @@ -444,7 +444,7 @@ public function setResultSetMapping(ResultSetMapping $rsm): static */ protected function getResultSetMapping(): ResultSetMapping|null { - return $this->_resultSetMapping; + return $this->resultSetMapping; } /** @@ -481,7 +481,7 @@ private function translateNamespaces(ResultSetMapping $rsm): void public function setHydrationCacheProfile(QueryCacheProfile|null $profile): static { if ($profile === null) { - $this->_hydrationCacheProfile = null; + $this->hydrationCacheProfile = null; return $this; } @@ -493,14 +493,14 @@ public function setHydrationCacheProfile(QueryCacheProfile|null $profile): stati } } - $this->_hydrationCacheProfile = $profile; + $this->hydrationCacheProfile = $profile; return $this; } public function getHydrationCacheProfile(): QueryCacheProfile|null { - return $this->_hydrationCacheProfile; + return $this->hydrationCacheProfile; } /** @@ -514,7 +514,7 @@ public function getHydrationCacheProfile(): QueryCacheProfile|null public function setResultCacheProfile(QueryCacheProfile|null $profile): static { if ($profile === null) { - $this->_queryCacheProfile = null; + $this->queryCacheProfile = null; return $this; } @@ -526,7 +526,7 @@ public function setResultCacheProfile(QueryCacheProfile|null $profile): static } } - $this->_queryCacheProfile = $profile; + $this->queryCacheProfile = $profile; return $this; } @@ -537,15 +537,15 @@ public function setResultCacheProfile(QueryCacheProfile|null $profile): static public function setResultCache(CacheItemPoolInterface|null $resultCache): static { if ($resultCache === null) { - if ($this->_queryCacheProfile) { - $this->_queryCacheProfile = new QueryCacheProfile($this->_queryCacheProfile->getLifetime(), $this->_queryCacheProfile->getCacheKey()); + if ($this->queryCacheProfile) { + $this->queryCacheProfile = new QueryCacheProfile($this->queryCacheProfile->getLifetime(), $this->queryCacheProfile->getCacheKey()); } return $this; } - $this->_queryCacheProfile = $this->_queryCacheProfile - ? $this->_queryCacheProfile->setResultCache($resultCache) + $this->queryCacheProfile = $this->queryCacheProfile + ? $this->queryCacheProfile->setResultCache($resultCache) : new QueryCacheProfile(0, null, $resultCache); return $this; @@ -575,7 +575,7 @@ public function enableResultCache(int|null $lifetime = null, string|null $result */ public function disableResultCache(): static { - $this->_queryCacheProfile = null; + $this->queryCacheProfile = null; return $this; } @@ -591,20 +591,20 @@ public function setResultCacheLifetime(int|null $lifetime): static { $lifetime = (int) $lifetime; - if ($this->_queryCacheProfile) { - $this->_queryCacheProfile = $this->_queryCacheProfile->setLifetime($lifetime); + if ($this->queryCacheProfile) { + $this->queryCacheProfile = $this->queryCacheProfile->setLifetime($lifetime); return $this; } - $this->_queryCacheProfile = new QueryCacheProfile($lifetime); + $this->queryCacheProfile = new QueryCacheProfile($lifetime); $cache = $this->em->getConfiguration()->getResultCache(); if (! $cache) { return $this; } - $this->_queryCacheProfile = $this->_queryCacheProfile->setResultCache($cache); + $this->queryCacheProfile = $this->queryCacheProfile->setResultCache($cache); return $this; } @@ -618,7 +618,7 @@ public function setResultCacheLifetime(int|null $lifetime): static */ public function expireResultCache(bool $expire = true): static { - $this->_expireResultCache = $expire; + $this->expireResultCache = $expire; return $this; } @@ -628,12 +628,12 @@ public function expireResultCache(bool $expire = true): static */ public function getExpireResultCache(): bool { - return $this->_expireResultCache; + return $this->expireResultCache; } public function getQueryCacheProfile(): QueryCacheProfile|null { - return $this->_queryCacheProfile; + return $this->queryCacheProfile; } /** @@ -644,7 +644,7 @@ public function getQueryCacheProfile(): QueryCacheProfile|null */ public function setFetchMode(string $class, string $assocName, int $fetchMode): static { - $this->_hints['fetchMode'][$class][$assocName] = $fetchMode; + $this->hints['fetchMode'][$class][$assocName] = $fetchMode; return $this; } @@ -660,7 +660,7 @@ public function setFetchMode(string $class, string $assocName, int $fetchMode): */ public function setHydrationMode(string|int $hydrationMode): static { - $this->_hydrationMode = $hydrationMode; + $this->hydrationMode = $hydrationMode; return $this; } @@ -672,7 +672,7 @@ public function setHydrationMode(string|int $hydrationMode): static */ public function getHydrationMode(): string|int { - return $this->_hydrationMode; + return $this->hydrationMode; } /** @@ -738,7 +738,7 @@ public function getOneOrNullResult(string|int|null $hydrationMode = null): mixed return null; } - if ($this->_hydrationMode !== self::HYDRATE_SINGLE_SCALAR && ! $result) { + if ($this->hydrationMode !== self::HYDRATE_SINGLE_SCALAR && ! $result) { return null; } @@ -770,7 +770,7 @@ public function getSingleResult(string|int|null $hydrationMode = null): mixed { $result = $this->execute(null, $hydrationMode); - if ($this->_hydrationMode !== self::HYDRATE_SINGLE_SCALAR && ! $result) { + if ($this->hydrationMode !== self::HYDRATE_SINGLE_SCALAR && ! $result) { throw new NoResultException(); } @@ -805,7 +805,7 @@ public function getSingleScalarResult(): mixed */ public function setHint(string $name, mixed $value): static { - $this->_hints[$name] = $value; + $this->hints[$name] = $value; return $this; } @@ -817,12 +817,12 @@ public function setHint(string $name, mixed $value): static */ public function getHint(string $name): mixed { - return $this->_hints[$name] ?? false; + return $this->hints[$name] ?? false; } public function hasHint(string $name): bool { - return isset($this->_hints[$name]); + return isset($this->hints[$name]); } /** @@ -832,7 +832,7 @@ public function hasHint(string $name): bool */ public function getHints(): array { - return $this->_hints; + return $this->hints; } /** @@ -867,7 +867,7 @@ public function toIterable( $stmt = $this->_doExecute(); - return $this->em->newHydrator($this->_hydrationMode)->toIterable($stmt, $rsm, $this->_hints); + return $this->em->newHydrator($this->hydrationMode)->toIterable($stmt, $rsm, $this->hints); } /** @@ -908,7 +908,7 @@ private function executeIgnoreQueryCache( $setCacheEntry = static function ($data): void { }; - if ($this->_hydrationCacheProfile !== null) { + if ($this->hydrationCacheProfile !== null) { [$cacheKey, $realCacheKey] = $this->getHydrationCacheId(); $cache = $this->getHydrationCache(); @@ -941,7 +941,7 @@ private function executeIgnoreQueryCache( throw new LogicException('Uninitialized result set mapping.'); } - $data = $this->em->newHydrator($this->_hydrationMode)->hydrateAll($stmt, $rsm, $this->_hints); + $data = $this->em->newHydrator($this->hydrationMode)->hydrateAll($stmt, $rsm, $this->hints); $setCacheEntry($data); @@ -950,9 +950,9 @@ private function executeIgnoreQueryCache( private function getHydrationCache(): CacheItemPoolInterface { - assert($this->_hydrationCacheProfile !== null); + assert($this->hydrationCacheProfile !== null); - $cache = $this->_hydrationCacheProfile->getResultCache(); + $cache = $this->hydrationCacheProfile->getResultCache(); assert($cache !== null); return $cache; @@ -981,7 +981,7 @@ private function executeUsingQueryCache( $this->getTimestampKey(), ); - $result = $queryCache->get($queryKey, $rsm, $this->_hints); + $result = $queryCache->get($queryKey, $rsm, $this->hints); if ($result !== null) { if ($this->cacheLogger) { @@ -992,7 +992,7 @@ private function executeUsingQueryCache( } $result = $this->executeIgnoreQueryCache($parameters, $hydrationMode); - $cached = $queryCache->put($queryKey, $rsm, $result, $this->_hints); + $cached = $queryCache->put($queryKey, $rsm, $result, $this->hints); if ($this->cacheLogger) { $this->cacheLogger->queryCacheMiss($queryCache->getRegion()->getName(), $queryKey); @@ -1007,8 +1007,8 @@ private function executeUsingQueryCache( private function getTimestampKey(): TimestampCacheKey|null { - assert($this->_resultSetMapping !== null); - $entityName = reset($this->_resultSetMapping->aliasMap); + assert($this->resultSetMapping !== null); + $entityName = reset($this->resultSetMapping->aliasMap); if (empty($entityName)) { return null; @@ -1056,11 +1056,11 @@ protected function getHydrationCacheId(): array */ public function setResultCacheId(string|null $id): static { - if (! $this->_queryCacheProfile) { + if (! $this->queryCacheProfile) { return $this->setResultCacheProfile(new QueryCacheProfile(0, $id)); } - $this->_queryCacheProfile = $this->_queryCacheProfile->setCacheKey($id); + $this->queryCacheProfile = $this->queryCacheProfile->setCacheKey($id); return $this; } @@ -1081,8 +1081,8 @@ public function __clone() { $this->parameters = new ArrayCollection(); - $this->_hints = []; - $this->_hints = $this->em->getConfiguration()->getDefaultQueryHints(); + $this->hints = []; + $this->hints = $this->em->getConfiguration()->getDefaultQueryHints(); } /** diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 87eaeb72161..782c070a791 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -42,14 +42,14 @@ class Configuration extends \Doctrine\DBAL\Configuration { /** @var mixed[] */ - protected array $_attributes = []; + protected array $attributes = []; /** * Sets the directory where Doctrine generates any necessary proxy class files. */ public function setProxyDir(string $dir): void { - $this->_attributes['proxyDir'] = $dir; + $this->attributes['proxyDir'] = $dir; } /** @@ -57,7 +57,7 @@ public function setProxyDir(string $dir): void */ public function getProxyDir(): string|null { - return $this->_attributes['proxyDir'] ?? null; + return $this->attributes['proxyDir'] ?? null; } /** @@ -68,7 +68,7 @@ public function getProxyDir(): string|null */ public function getAutoGenerateProxyClasses(): int { - return $this->_attributes['autoGenerateProxyClasses'] ?? ProxyFactory::AUTOGENERATE_ALWAYS; + return $this->attributes['autoGenerateProxyClasses'] ?? ProxyFactory::AUTOGENERATE_ALWAYS; } /** @@ -80,7 +80,7 @@ public function getAutoGenerateProxyClasses(): int */ public function setAutoGenerateProxyClasses(bool|int $autoGenerate): void { - $this->_attributes['autoGenerateProxyClasses'] = (int) $autoGenerate; + $this->attributes['autoGenerateProxyClasses'] = (int) $autoGenerate; } /** @@ -88,7 +88,7 @@ public function setAutoGenerateProxyClasses(bool|int $autoGenerate): void */ public function getProxyNamespace(): string|null { - return $this->_attributes['proxyNamespace'] ?? null; + return $this->attributes['proxyNamespace'] ?? null; } /** @@ -96,7 +96,7 @@ public function getProxyNamespace(): string|null */ public function setProxyNamespace(string $ns): void { - $this->_attributes['proxyNamespace'] = $ns; + $this->attributes['proxyNamespace'] = $ns; } /** @@ -107,7 +107,7 @@ public function setProxyNamespace(string $ns): void */ public function setMetadataDriverImpl(MappingDriver $driverImpl): void { - $this->_attributes['metadataDriverImpl'] = $driverImpl; + $this->attributes['metadataDriverImpl'] = $driverImpl; } /** @@ -117,7 +117,7 @@ public function setMetadataDriverImpl(MappingDriver $driverImpl): void */ public function setEntityNamespaces(array $entityNamespaces): void { - $this->_attributes['entityNamespaces'] = $entityNamespaces; + $this->attributes['entityNamespaces'] = $entityNamespaces; } /** @@ -127,7 +127,7 @@ public function setEntityNamespaces(array $entityNamespaces): void */ public function getEntityNamespaces(): array { - return $this->_attributes['entityNamespaces']; + return $this->attributes['entityNamespaces']; } /** @@ -135,7 +135,7 @@ public function getEntityNamespaces(): array */ public function getMetadataDriverImpl(): MappingDriver|null { - return $this->_attributes['metadataDriverImpl'] ?? null; + return $this->attributes['metadataDriverImpl'] ?? null; } /** @@ -143,7 +143,7 @@ public function getMetadataDriverImpl(): MappingDriver|null */ public function getQueryCache(): CacheItemPoolInterface|null { - return $this->_attributes['queryCache'] ?? null; + return $this->attributes['queryCache'] ?? null; } /** @@ -151,27 +151,27 @@ public function getQueryCache(): CacheItemPoolInterface|null */ public function setQueryCache(CacheItemPoolInterface $cache): void { - $this->_attributes['queryCache'] = $cache; + $this->attributes['queryCache'] = $cache; } public function getHydrationCache(): CacheItemPoolInterface|null { - return $this->_attributes['hydrationCache'] ?? null; + return $this->attributes['hydrationCache'] ?? null; } public function setHydrationCache(CacheItemPoolInterface $cache): void { - $this->_attributes['hydrationCache'] = $cache; + $this->attributes['hydrationCache'] = $cache; } public function getMetadataCache(): CacheItemPoolInterface|null { - return $this->_attributes['metadataCache'] ?? null; + return $this->attributes['metadataCache'] ?? null; } public function setMetadataCache(CacheItemPoolInterface $cache): void { - $this->_attributes['metadataCache'] = $cache; + $this->attributes['metadataCache'] = $cache; } /** @@ -186,7 +186,7 @@ public function setMetadataCache(CacheItemPoolInterface $cache): void */ public function addCustomStringFunction(string $name, string|callable $className): void { - $this->_attributes['customStringFunctions'][strtolower($name)] = $className; + $this->attributes['customStringFunctions'][strtolower($name)] = $className; } /** @@ -198,7 +198,7 @@ public function getCustomStringFunction(string $name): string|callable|null { $name = strtolower($name); - return $this->_attributes['customStringFunctions'][$name] ?? null; + return $this->attributes['customStringFunctions'][$name] ?? null; } /** @@ -231,7 +231,7 @@ public function setCustomStringFunctions(array $functions): void */ public function addCustomNumericFunction(string $name, string|callable $className): void { - $this->_attributes['customNumericFunctions'][strtolower($name)] = $className; + $this->attributes['customNumericFunctions'][strtolower($name)] = $className; } /** @@ -243,7 +243,7 @@ public function getCustomNumericFunction(string $name): string|callable|null { $name = strtolower($name); - return $this->_attributes['customNumericFunctions'][$name] ?? null; + return $this->attributes['customNumericFunctions'][$name] ?? null; } /** @@ -276,7 +276,7 @@ public function setCustomNumericFunctions(array $functions): void */ public function addCustomDatetimeFunction(string $name, string|callable $className): void { - $this->_attributes['customDatetimeFunctions'][strtolower($name)] = $className; + $this->attributes['customDatetimeFunctions'][strtolower($name)] = $className; } /** @@ -288,7 +288,7 @@ public function getCustomDatetimeFunction(string $name): string|callable|null { $name = strtolower($name); - return $this->_attributes['customDatetimeFunctions'][$name] ?? null; + return $this->attributes['customDatetimeFunctions'][$name] ?? null; } /** @@ -314,7 +314,7 @@ public function setCustomDatetimeFunctions(array $functions): void */ public function setTypedFieldMapper(TypedFieldMapper|null $typedFieldMapper): void { - $this->_attributes['typedFieldMapper'] = $typedFieldMapper; + $this->attributes['typedFieldMapper'] = $typedFieldMapper; } /** @@ -322,7 +322,7 @@ public function setTypedFieldMapper(TypedFieldMapper|null $typedFieldMapper): vo */ public function getTypedFieldMapper(): TypedFieldMapper|null { - return $this->_attributes['typedFieldMapper'] ?? null; + return $this->attributes['typedFieldMapper'] ?? null; } /** @@ -332,7 +332,7 @@ public function getTypedFieldMapper(): TypedFieldMapper|null */ public function setCustomHydrationModes(array $modes): void { - $this->_attributes['customHydrationModes'] = []; + $this->attributes['customHydrationModes'] = []; foreach ($modes as $modeName => $hydrator) { $this->addCustomHydrationMode($modeName, $hydrator); @@ -346,7 +346,7 @@ public function setCustomHydrationModes(array $modes): void */ public function getCustomHydrationMode(string $modeName): string|null { - return $this->_attributes['customHydrationModes'][$modeName] ?? null; + return $this->attributes['customHydrationModes'][$modeName] ?? null; } /** @@ -356,7 +356,7 @@ public function getCustomHydrationMode(string $modeName): string|null */ public function addCustomHydrationMode(string $modeName, string $hydrator): void { - $this->_attributes['customHydrationModes'][$modeName] = $hydrator; + $this->attributes['customHydrationModes'][$modeName] = $hydrator; } /** @@ -366,17 +366,17 @@ public function addCustomHydrationMode(string $modeName, string $hydrator): void */ public function setClassMetadataFactoryName(string $cmfName): void { - $this->_attributes['classMetadataFactoryName'] = $cmfName; + $this->attributes['classMetadataFactoryName'] = $cmfName; } /** @psalm-return class-string */ public function getClassMetadataFactoryName(): string { - if (! isset($this->_attributes['classMetadataFactoryName'])) { - $this->_attributes['classMetadataFactoryName'] = ClassMetadataFactory::class; + if (! isset($this->attributes['classMetadataFactoryName'])) { + $this->attributes['classMetadataFactoryName'] = ClassMetadataFactory::class; } - return $this->_attributes['classMetadataFactoryName']; + return $this->attributes['classMetadataFactoryName']; } /** @@ -387,7 +387,7 @@ public function getClassMetadataFactoryName(): string */ public function addFilter(string $name, string $className): void { - $this->_attributes['filters'][$name] = $className; + $this->attributes['filters'][$name] = $className; } /** @@ -399,7 +399,7 @@ public function addFilter(string $name, string $className): void */ public function getFilterClassName(string $name): string|null { - return $this->_attributes['filters'][$name] ?? null; + return $this->attributes['filters'][$name] ?? null; } /** @@ -415,7 +415,7 @@ public function setDefaultRepositoryClassName(string $className): void throw InvalidEntityRepository::fromClassName($className); } - $this->_attributes['defaultRepositoryClassName'] = $className; + $this->attributes['defaultRepositoryClassName'] = $className; } /** @@ -425,7 +425,7 @@ public function setDefaultRepositoryClassName(string $className): void */ public function getDefaultRepositoryClassName(): string { - return $this->_attributes['defaultRepositoryClassName'] ?? EntityRepository::class; + return $this->attributes['defaultRepositoryClassName'] ?? EntityRepository::class; } /** @@ -433,7 +433,7 @@ public function getDefaultRepositoryClassName(): string */ public function setNamingStrategy(NamingStrategy $namingStrategy): void { - $this->_attributes['namingStrategy'] = $namingStrategy; + $this->attributes['namingStrategy'] = $namingStrategy; } /** @@ -441,11 +441,11 @@ public function setNamingStrategy(NamingStrategy $namingStrategy): void */ public function getNamingStrategy(): NamingStrategy { - if (! isset($this->_attributes['namingStrategy'])) { - $this->_attributes['namingStrategy'] = new DefaultNamingStrategy(); + if (! isset($this->attributes['namingStrategy'])) { + $this->attributes['namingStrategy'] = new DefaultNamingStrategy(); } - return $this->_attributes['namingStrategy']; + return $this->attributes['namingStrategy']; } /** @@ -453,7 +453,7 @@ public function getNamingStrategy(): NamingStrategy */ public function setQuoteStrategy(QuoteStrategy $quoteStrategy): void { - $this->_attributes['quoteStrategy'] = $quoteStrategy; + $this->attributes['quoteStrategy'] = $quoteStrategy; } /** @@ -461,11 +461,11 @@ public function setQuoteStrategy(QuoteStrategy $quoteStrategy): void */ public function getQuoteStrategy(): QuoteStrategy { - if (! isset($this->_attributes['quoteStrategy'])) { - $this->_attributes['quoteStrategy'] = new DefaultQuoteStrategy(); + if (! isset($this->attributes['quoteStrategy'])) { + $this->attributes['quoteStrategy'] = new DefaultQuoteStrategy(); } - return $this->_attributes['quoteStrategy']; + return $this->attributes['quoteStrategy']; } /** @@ -473,7 +473,7 @@ public function getQuoteStrategy(): QuoteStrategy */ public function setEntityListenerResolver(EntityListenerResolver $resolver): void { - $this->_attributes['entityListenerResolver'] = $resolver; + $this->attributes['entityListenerResolver'] = $resolver; } /** @@ -481,11 +481,11 @@ public function setEntityListenerResolver(EntityListenerResolver $resolver): voi */ public function getEntityListenerResolver(): EntityListenerResolver { - if (! isset($this->_attributes['entityListenerResolver'])) { - $this->_attributes['entityListenerResolver'] = new DefaultEntityListenerResolver(); + if (! isset($this->attributes['entityListenerResolver'])) { + $this->attributes['entityListenerResolver'] = new DefaultEntityListenerResolver(); } - return $this->_attributes['entityListenerResolver']; + return $this->attributes['entityListenerResolver']; } /** @@ -493,7 +493,7 @@ public function getEntityListenerResolver(): EntityListenerResolver */ public function setRepositoryFactory(RepositoryFactory $repositoryFactory): void { - $this->_attributes['repositoryFactory'] = $repositoryFactory; + $this->attributes['repositoryFactory'] = $repositoryFactory; } /** @@ -501,31 +501,31 @@ public function setRepositoryFactory(RepositoryFactory $repositoryFactory): void */ public function getRepositoryFactory(): RepositoryFactory { - return $this->_attributes['repositoryFactory'] ?? new DefaultRepositoryFactory(); + return $this->attributes['repositoryFactory'] ?? new DefaultRepositoryFactory(); } public function isSecondLevelCacheEnabled(): bool { - return $this->_attributes['isSecondLevelCacheEnabled'] ?? false; + return $this->attributes['isSecondLevelCacheEnabled'] ?? false; } public function setSecondLevelCacheEnabled(bool $flag = true): void { - $this->_attributes['isSecondLevelCacheEnabled'] = $flag; + $this->attributes['isSecondLevelCacheEnabled'] = $flag; } public function setSecondLevelCacheConfiguration(CacheConfiguration $cacheConfig): void { - $this->_attributes['secondLevelCacheConfiguration'] = $cacheConfig; + $this->attributes['secondLevelCacheConfiguration'] = $cacheConfig; } public function getSecondLevelCacheConfiguration(): CacheConfiguration|null { - if (! isset($this->_attributes['secondLevelCacheConfiguration']) && $this->isSecondLevelCacheEnabled()) { - $this->_attributes['secondLevelCacheConfiguration'] = new CacheConfiguration(); + if (! isset($this->attributes['secondLevelCacheConfiguration']) && $this->isSecondLevelCacheEnabled()) { + $this->attributes['secondLevelCacheConfiguration'] = new CacheConfiguration(); } - return $this->_attributes['secondLevelCacheConfiguration'] ?? null; + return $this->attributes['secondLevelCacheConfiguration'] ?? null; } /** @@ -535,7 +535,7 @@ public function getSecondLevelCacheConfiguration(): CacheConfiguration|null */ public function getDefaultQueryHints(): array { - return $this->_attributes['defaultQueryHints'] ?? []; + return $this->attributes['defaultQueryHints'] ?? []; } /** @@ -545,7 +545,7 @@ public function getDefaultQueryHints(): array */ public function setDefaultQueryHints(array $defaultQueryHints): void { - $this->_attributes['defaultQueryHints'] = $defaultQueryHints; + $this->attributes['defaultQueryHints'] = $defaultQueryHints; } /** @@ -555,7 +555,7 @@ public function setDefaultQueryHints(array $defaultQueryHints): void */ public function getDefaultQueryHint(string $name): mixed { - return $this->_attributes['defaultQueryHints'][$name] ?? false; + return $this->attributes['defaultQueryHints'][$name] ?? false; } /** @@ -563,7 +563,7 @@ public function getDefaultQueryHint(string $name): mixed */ public function setDefaultQueryHint(string $name, mixed $value): void { - $this->_attributes['defaultQueryHints'][$name] = $value; + $this->attributes['defaultQueryHints'][$name] = $value; } /** @@ -573,7 +573,7 @@ public function setDefaultQueryHint(string $name, mixed $value): void */ public function getSchemaIgnoreClasses(): array { - return $this->_attributes['schemaIgnoreClasses'] ?? []; + return $this->attributes['schemaIgnoreClasses'] ?? []; } /** @@ -583,12 +583,12 @@ public function getSchemaIgnoreClasses(): array */ public function setSchemaIgnoreClasses(array $schemaIgnoreClasses): void { - $this->_attributes['schemaIgnoreClasses'] = $schemaIgnoreClasses; + $this->attributes['schemaIgnoreClasses'] = $schemaIgnoreClasses; } public function isLazyGhostObjectEnabled(): bool { - return $this->_attributes['isLazyGhostObjectEnabled'] ?? false; + return $this->attributes['isLazyGhostObjectEnabled'] ?? false; } public function setLazyGhostObjectEnabled(bool $flag): void @@ -607,6 +607,6 @@ public function setLazyGhostObjectEnabled(bool $flag): void ); } - $this->_attributes['isLazyGhostObjectEnabled'] = $flag; + $this->attributes['isLazyGhostObjectEnabled'] = $flag; } } diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index cd77aa532b8..67eb4bcf137 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -34,54 +34,52 @@ abstract class AbstractHydrator /** * The ResultSetMapping. */ - protected ResultSetMapping|null $_rsm = null; + protected ResultSetMapping|null $rsm = null; /** * The dbms Platform instance. */ - protected AbstractPlatform $_platform; + protected AbstractPlatform $platform; /** * The UnitOfWork of the associated EntityManager. */ - protected UnitOfWork $_uow; + protected UnitOfWork $uow; /** * Local ClassMetadata cache to avoid going to the EntityManager all the time. * * @var array> */ - protected array $_metadataCache = []; + protected array $metadataCache = []; /** * The cache used during row-by-row hydration. * * @var array */ - protected array $_cache = []; + protected array $cache = []; /** * The statement that provides the data to hydrate. */ - protected Result|null $_stmt = null; + protected Result|null $stmt = null; /** * The query hints. * * @var array */ - protected array $_hints = []; - - protected EntityManagerInterface $_em; + protected array $hints = []; /** * Initializes a new instance of a class derived from AbstractHydrator. */ public function __construct(protected EntityManagerInterface $em) { - $this->_em = $em; - $this->_platform = $em->getConnection()->getDatabasePlatform(); - $this->_uow = $em->getUnitOfWork(); + $this->em = $em; + $this->platform = $em->getConnection()->getDatabasePlatform(); + $this->uow = $em->getUnitOfWork(); } /** @@ -95,11 +93,11 @@ public function __construct(protected EntityManagerInterface $em) */ final public function toIterable(Result $stmt, ResultSetMapping $resultSetMapping, array $hints = []): Generator { - $this->_stmt = $stmt; - $this->_rsm = $resultSetMapping; - $this->_hints = $hints; + $this->stmt = $stmt; + $this->rsm = $resultSetMapping; + $this->hints = $hints; - $evm = $this->_em->getEventManager(); + $evm = $this->em->getEventManager(); $evm->addEventListener([Events::onClear], $this); @@ -133,20 +131,20 @@ final public function toIterable(Result $stmt, ResultSetMapping $resultSetMappin final protected function statement(): Result { - if ($this->_stmt === null) { + if ($this->stmt === null) { throw new LogicException('Uninitialized _stmt property'); } - return $this->_stmt; + return $this->stmt; } final protected function resultSetMapping(): ResultSetMapping { - if ($this->_rsm === null) { + if ($this->rsm === null) { throw new LogicException('Uninitialized _rsm property'); } - return $this->_rsm; + return $this->rsm; } /** @@ -156,11 +154,11 @@ final protected function resultSetMapping(): ResultSetMapping */ public function hydrateAll(Result $stmt, ResultSetMapping $resultSetMapping, array $hints = []): mixed { - $this->_stmt = $stmt; - $this->_rsm = $resultSetMapping; - $this->_hints = $hints; + $this->stmt = $stmt; + $this->rsm = $resultSetMapping; + $this->hints = $hints; - $this->_em->getEventManager()->addEventListener([Events::onClear], $this); + $this->em->getEventManager()->addEventListener([Events::onClear], $this); $this->prepare(); try { @@ -196,13 +194,13 @@ protected function cleanup(): void { $this->statement()->free(); - $this->_stmt = null; - $this->_rsm = null; - $this->_cache = []; - $this->_metadataCache = []; + $this->stmt = null; + $this->rsm = null; + $this->cache = []; + $this->metadataCache = []; $this - ->_em + ->em ->getEventManager() ->removeEventListener([Events::onClear], $this); } @@ -274,7 +272,7 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon $argIndex = $cacheKeyInfo['argIndex']; $objIndex = $cacheKeyInfo['objIndex']; $type = $cacheKeyInfo['type']; - $value = $type->convertToPHPValue($value, $this->_platform); + $value = $type->convertToPHPValue($value, $this->platform); if ($value !== null && isset($cacheKeyInfo['enumType'])) { $value = $this->buildEnum($value, $cacheKeyInfo['enumType']); @@ -286,7 +284,7 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon case isset($cacheKeyInfo['isScalar']): $type = $cacheKeyInfo['type']; - $value = $type->convertToPHPValue($value, $this->_platform); + $value = $type->convertToPHPValue($value, $this->platform); if ($value !== null && isset($cacheKeyInfo['enumType'])) { $value = $this->buildEnum($value, $cacheKeyInfo['enumType']); @@ -318,7 +316,7 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon } $rowData['data'][$dqlAlias][$fieldName] = $type - ? $type->convertToPHPValue($value, $this->_platform) + ? $type->convertToPHPValue($value, $this->platform) : $value; if ($rowData['data'][$dqlAlias][$fieldName] !== null && isset($cacheKeyInfo['enumType'])) { @@ -367,7 +365,7 @@ protected function gatherScalarRowData(array &$data): array // erroneous behavior exists since 2.0 and we're forced to keep compatibility. if (! isset($cacheKeyInfo['isScalar'])) { $type = $cacheKeyInfo['type']; - $value = $type ? $type->convertToPHPValue($value, $this->_platform) : $value; + $value = $type ? $type->convertToPHPValue($value, $this->platform) : $value; $fieldName = $cacheKeyInfo['dqlAlias'] . '_' . $fieldName; } @@ -388,89 +386,89 @@ protected function gatherScalarRowData(array &$data): array */ protected function hydrateColumnInfo(string $key): array|null { - if (isset($this->_cache[$key])) { - return $this->_cache[$key]; + if (isset($this->cache[$key])) { + return $this->cache[$key]; } switch (true) { // NOTE: Most of the times it's a field mapping, so keep it first!!! - case isset($this->_rsm->fieldMappings[$key]): - $classMetadata = $this->getClassMetadata($this->_rsm->declaringClasses[$key]); - $fieldName = $this->_rsm->fieldMappings[$key]; + case isset($this->rsm->fieldMappings[$key]): + $classMetadata = $this->getClassMetadata($this->rsm->declaringClasses[$key]); + $fieldName = $this->rsm->fieldMappings[$key]; $fieldMapping = $classMetadata->fieldMappings[$fieldName]; - $ownerMap = $this->_rsm->columnOwnerMap[$key]; + $ownerMap = $this->rsm->columnOwnerMap[$key]; $columnInfo = [ 'isIdentifier' => in_array($fieldName, $classMetadata->identifier, true), 'fieldName' => $fieldName, 'type' => Type::getType($fieldMapping['type']), 'dqlAlias' => $ownerMap, - 'enumType' => $this->_rsm->enumMappings[$key] ?? null, + 'enumType' => $this->rsm->enumMappings[$key] ?? null, ]; // the current discriminator value must be saved in order to disambiguate fields hydration, // should there be field name collisions - if ($classMetadata->parentClasses && isset($this->_rsm->discriminatorColumns[$ownerMap])) { - return $this->_cache[$key] = array_merge( + if ($classMetadata->parentClasses && isset($this->rsm->discriminatorColumns[$ownerMap])) { + return $this->cache[$key] = array_merge( $columnInfo, [ - 'discriminatorColumn' => $this->_rsm->discriminatorColumns[$ownerMap], + 'discriminatorColumn' => $this->rsm->discriminatorColumns[$ownerMap], 'discriminatorValue' => $classMetadata->discriminatorValue, 'discriminatorValues' => $this->getDiscriminatorValues($classMetadata), ], ); } - return $this->_cache[$key] = $columnInfo; + return $this->cache[$key] = $columnInfo; - case isset($this->_rsm->newObjectMappings[$key]): + case isset($this->rsm->newObjectMappings[$key]): // WARNING: A NEW object is also a scalar, so it must be declared before! - $mapping = $this->_rsm->newObjectMappings[$key]; + $mapping = $this->rsm->newObjectMappings[$key]; - return $this->_cache[$key] = [ + return $this->cache[$key] = [ 'isScalar' => true, 'isNewObjectParameter' => true, - 'fieldName' => $this->_rsm->scalarMappings[$key], - 'type' => Type::getType($this->_rsm->typeMappings[$key]), + 'fieldName' => $this->rsm->scalarMappings[$key], + 'type' => Type::getType($this->rsm->typeMappings[$key]), 'argIndex' => $mapping['argIndex'], 'objIndex' => $mapping['objIndex'], 'class' => new ReflectionClass($mapping['className']), - 'enumType' => $this->_rsm->enumMappings[$key] ?? null, + 'enumType' => $this->rsm->enumMappings[$key] ?? null, ]; - case isset($this->_rsm->scalarMappings[$key], $this->_hints[LimitSubqueryWalker::FORCE_DBAL_TYPE_CONVERSION]): - return $this->_cache[$key] = [ - 'fieldName' => $this->_rsm->scalarMappings[$key], - 'type' => Type::getType($this->_rsm->typeMappings[$key]), + case isset($this->rsm->scalarMappings[$key], $this->hints[LimitSubqueryWalker::FORCE_DBAL_TYPE_CONVERSION]): + return $this->cache[$key] = [ + 'fieldName' => $this->rsm->scalarMappings[$key], + 'type' => Type::getType($this->rsm->typeMappings[$key]), 'dqlAlias' => '', - 'enumType' => $this->_rsm->enumMappings[$key] ?? null, + 'enumType' => $this->rsm->enumMappings[$key] ?? null, ]; - case isset($this->_rsm->scalarMappings[$key]): - return $this->_cache[$key] = [ + case isset($this->rsm->scalarMappings[$key]): + return $this->cache[$key] = [ 'isScalar' => true, - 'fieldName' => $this->_rsm->scalarMappings[$key], - 'type' => Type::getType($this->_rsm->typeMappings[$key]), - 'enumType' => $this->_rsm->enumMappings[$key] ?? null, + 'fieldName' => $this->rsm->scalarMappings[$key], + 'type' => Type::getType($this->rsm->typeMappings[$key]), + 'enumType' => $this->rsm->enumMappings[$key] ?? null, ]; - case isset($this->_rsm->metaMappings[$key]): + case isset($this->rsm->metaMappings[$key]): // Meta column (has meaning in relational schema only, i.e. foreign keys or discriminator columns). - $fieldName = $this->_rsm->metaMappings[$key]; - $dqlAlias = $this->_rsm->columnOwnerMap[$key]; - $type = isset($this->_rsm->typeMappings[$key]) - ? Type::getType($this->_rsm->typeMappings[$key]) + $fieldName = $this->rsm->metaMappings[$key]; + $dqlAlias = $this->rsm->columnOwnerMap[$key]; + $type = isset($this->rsm->typeMappings[$key]) + ? Type::getType($this->rsm->typeMappings[$key]) : null; // Cache metadata fetch - $this->getClassMetadata($this->_rsm->aliasMap[$dqlAlias]); + $this->getClassMetadata($this->rsm->aliasMap[$dqlAlias]); - return $this->_cache[$key] = [ - 'isIdentifier' => isset($this->_rsm->isIdentifierColumn[$dqlAlias][$key]), + return $this->cache[$key] = [ + 'isIdentifier' => isset($this->rsm->isIdentifierColumn[$dqlAlias][$key]), 'isMetaColumn' => true, 'fieldName' => $fieldName, 'type' => $type, 'dqlAlias' => $dqlAlias, - 'enumType' => $this->_rsm->enumMappings[$key] ?? null, + 'enumType' => $this->rsm->enumMappings[$key] ?? null, ]; } @@ -500,11 +498,11 @@ private function getDiscriminatorValues(ClassMetadata $classMetadata): array */ protected function getClassMetadata(string $className): ClassMetadata { - if (! isset($this->_metadataCache[$className])) { - $this->_metadataCache[$className] = $this->_em->getClassMetadata($className); + if (! isset($this->metadataCache[$className])) { + $this->metadataCache[$className] = $this->em->getClassMetadata($className); } - return $this->_metadataCache[$className]; + return $this->metadataCache[$className]; } /** @@ -533,7 +531,7 @@ protected function registerManaged(ClassMetadata $class, object $entity, array $ ]; } - $this->_em->getUnitOfWork()->registerManaged($entity, $id, $data); + $this->em->getUnitOfWork()->registerManaged($entity, $id, $data); } /** diff --git a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php index 8cd58b351a4..baf8a26cfa5 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php @@ -99,7 +99,7 @@ protected function hydrateRowData(array $row, array &$result): void } $relationAlias = $this->resultSetMapping()->relationMap[$dqlAlias]; - $parentClass = $this->_metadataCache[$this->resultSetMapping()->aliasMap[$parent]]; + $parentClass = $this->metadataCache[$this->resultSetMapping()->aliasMap[$parent]]; $relation = $parentClass->associationMappings[$relationAlias]; // Check the type of the relation (many or single-valued) diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index 6dd8adee66d..721ac80fb1e 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -52,8 +52,8 @@ class ObjectHydrator extends AbstractHydrator protected function prepare(): void { - if (! isset($this->_hints[UnitOfWork::HINT_DEFEREAGERLOAD])) { - $this->_hints[UnitOfWork::HINT_DEFEREAGERLOAD] = true; + if (! isset($this->hints[UnitOfWork::HINT_DEFEREAGERLOAD])) { + $this->hints[UnitOfWork::HINT_DEFEREAGERLOAD] = true; } foreach ($this->resultSetMapping()->aliasMap as $dqlAlias => $className) { @@ -76,7 +76,7 @@ protected function prepare(): void $sourceClass = $this->getClassMetadata($sourceClassName); $assoc = $sourceClass->associationMappings[$this->resultSetMapping()->relationMap[$dqlAlias]]; - $this->_hints['fetched'][$parent][$assoc['fieldName']] = true; + $this->hints['fetched'][$parent][$assoc['fieldName']] = true; if ($assoc['type'] === ClassMetadata::MANY_TO_MANY) { continue; @@ -84,7 +84,7 @@ protected function prepare(): void // Mark any non-collection opposite sides as fetched, too. if ($assoc['mappedBy']) { - $this->_hints['fetched'][$dqlAlias][$assoc['mappedBy']] = true; + $this->hints['fetched'][$dqlAlias][$assoc['mappedBy']] = true; continue; } @@ -98,14 +98,14 @@ protected function prepare(): void continue; } - $this->_hints['fetched'][$dqlAlias][$inverseAssoc['fieldName']] = true; + $this->hints['fetched'][$dqlAlias][$inverseAssoc['fieldName']] = true; } } } protected function cleanup(): void { - $eagerLoad = isset($this->_hints[UnitOfWork::HINT_DEFEREAGERLOAD]) && $this->_hints[UnitOfWork::HINT_DEFEREAGERLOAD] === true; + $eagerLoad = isset($this->hints[UnitOfWork::HINT_DEFEREAGERLOAD]) && $this->hints[UnitOfWork::HINT_DEFEREAGERLOAD] === true; parent::cleanup(); @@ -116,10 +116,10 @@ protected function cleanup(): void $this->resultPointers = []; if ($eagerLoad) { - $this->_uow->triggerEagerLoads(); + $this->uow->triggerEagerLoads(); } - $this->_uow->hydrationComplete(); + $this->uow->hydrationComplete(); } protected function cleanupAfterRowIteration(): void @@ -178,19 +178,19 @@ private function initRelatedCollection( if (! $value instanceof PersistentCollection) { $value = new PersistentCollection( - $this->_em, - $this->_metadataCache[$relation['targetEntity']], + $this->em, + $this->metadataCache[$relation['targetEntity']], $value, ); $value->setOwner($entity, $relation); $class->reflFields[$fieldName]->setValue($entity, $value); - $this->_uow->setOriginalEntityProperty($oid, $fieldName, $value); + $this->uow->setOriginalEntityProperty($oid, $fieldName, $value); $this->initializedCollections[$oid . $fieldName] = $value; } elseif ( - isset($this->_hints[Query::HINT_REFRESH]) || - isset($this->_hints['fetched'][$parentDqlAlias][$fieldName]) && + isset($this->hints[Query::HINT_REFRESH]) || + isset($this->hints['fetched'][$parentDqlAlias][$fieldName]) && ! $value->isInitialized() ) { // Is already PersistentCollection, but either REFRESH or FETCH-JOIN and UNINITIALIZED! @@ -236,7 +236,7 @@ private function getEntity(array $data, string $dqlAlias): object throw HydrationException::emptyDiscriminatorValue($dqlAlias); } - $discrMap = $this->_metadataCache[$className]->discriminatorMap; + $discrMap = $this->metadataCache[$className]->discriminatorMap; $discriminatorValue = $data[$discrColumn]; if ($discriminatorValue instanceof BackedEnum) { $discriminatorValue = $discriminatorValue->value; @@ -253,13 +253,13 @@ private function getEntity(array $data, string $dqlAlias): object unset($data[$discrColumn]); } - if (isset($this->_hints[Query::HINT_REFRESH_ENTITY], $this->rootAliases[$dqlAlias])) { - $this->registerManaged($this->_metadataCache[$className], $this->_hints[Query::HINT_REFRESH_ENTITY], $data); + if (isset($this->hints[Query::HINT_REFRESH_ENTITY], $this->rootAliases[$dqlAlias])) { + $this->registerManaged($this->metadataCache[$className], $this->hints[Query::HINT_REFRESH_ENTITY], $data); } - $this->_hints['fetchAlias'] = $dqlAlias; + $this->hints['fetchAlias'] = $dqlAlias; - return $this->_uow->createEntity($className, $data, $this->_hints); + return $this->uow->createEntity($className, $data, $this->hints); } /** @@ -269,7 +269,7 @@ private function getEntity(array $data, string $dqlAlias): object private function getEntityFromIdentityMap(string $className, array $data): object|bool { // TODO: Abstract this code and UnitOfWork::createEntity() equivalent? - $class = $this->_metadataCache[$className]; + $class = $this->metadataCache[$className]; if ($class->isIdentifierComposite) { $idHash = ''; @@ -280,12 +280,12 @@ private function getEntityFromIdentityMap(string $className, array $data): objec : $data[$fieldName]); } - return $this->_uow->tryGetByIdHash(ltrim($idHash), $class->rootEntityName); + return $this->uow->tryGetByIdHash(ltrim($idHash), $class->rootEntityName); } elseif (isset($class->associationMappings[$class->identifier[0]])) { - return $this->_uow->tryGetByIdHash($data[$class->associationMappings[$class->identifier[0]]['joinColumns'][0]['name']], $class->rootEntityName); + return $this->uow->tryGetByIdHash($data[$class->associationMappings[$class->identifier[0]]['joinColumns'][0]['name']], $class->rootEntityName); } - return $this->_uow->tryGetByIdHash($data[$class->identifier[0]], $class->rootEntityName); + return $this->uow->tryGetByIdHash($data[$class->identifier[0]], $class->rootEntityName); } /** @@ -337,7 +337,7 @@ protected function hydrateRowData(array $row, array &$result): void continue; } - $parentClass = $this->_metadataCache[$this->resultSetMapping()->aliasMap[$parentAlias]]; + $parentClass = $this->metadataCache[$this->resultSetMapping()->aliasMap[$parentAlias]]; $relationField = $this->resultSetMapping()->relationMap[$dqlAlias]; $relation = $parentClass->associationMappings[$relationField]; $reflField = $parentClass->reflFields[$relationField]; @@ -357,7 +357,7 @@ protected function hydrateRowData(array $row, array &$result): void $rowData['data'][$parentAlias][$relationField] = $element; // Mark as not-fetched again - unset($this->_hints['fetched'][$parentAlias][$relationField]); + unset($this->hints['fetched'][$parentAlias][$relationField]); continue; } @@ -421,14 +421,14 @@ protected function hydrateRowData(array $row, array &$result): void // PATH B: Single-valued association $reflFieldValue = $reflField->getValue($parentObject); - if (! $reflFieldValue || isset($this->_hints[Query::HINT_REFRESH]) || ($reflFieldValue instanceof Proxy && ! $reflFieldValue->__isInitialized())) { + if (! $reflFieldValue || isset($this->hints[Query::HINT_REFRESH]) || ($reflFieldValue instanceof Proxy && ! $reflFieldValue->__isInitialized())) { // we only need to take action if this value is null, // we refresh the entity or its an uninitialized proxy. if (isset($nonemptyComponents[$dqlAlias])) { $element = $this->getEntity($data, $dqlAlias); $reflField->setValue($parentObject, $element); - $this->_uow->setOriginalEntityProperty($oid, $relationField, $element); - $targetClass = $this->_metadataCache[$relation['targetEntity']]; + $this->uow->setOriginalEntityProperty($oid, $relationField, $element); + $targetClass = $this->metadataCache[$relation['targetEntity']]; if ($relation['isOwningSide']) { // TODO: Just check hints['fetched'] here? @@ -437,7 +437,7 @@ protected function hydrateRowData(array $row, array &$result): void $inverseAssoc = $targetClass->associationMappings[$relation['inversedBy']]; if ($inverseAssoc['type'] & ClassMetadata::TO_ONE) { $targetClass->reflFields[$inverseAssoc['fieldName']]->setValue($element, $parentObject); - $this->_uow->setOriginalEntityProperty(spl_object_id($element), $inverseAssoc['fieldName'], $parentObject); + $this->uow->setOriginalEntityProperty(spl_object_id($element), $inverseAssoc['fieldName'], $parentObject); } } elseif ($parentClass === $targetClass && $relation['mappedBy']) { // Special case: bi-directional self-referencing one-one on the same class @@ -446,13 +446,13 @@ protected function hydrateRowData(array $row, array &$result): void } else { // For sure bidirectional, as there is no inverse side in unidirectional mappings $targetClass->reflFields[$relation['mappedBy']]->setValue($element, $parentObject); - $this->_uow->setOriginalEntityProperty(spl_object_id($element), $relation['mappedBy'], $parentObject); + $this->uow->setOriginalEntityProperty(spl_object_id($element), $relation['mappedBy'], $parentObject); } // Update result pointer $this->resultPointers[$dqlAlias] = $element; } else { - $this->_uow->setOriginalEntityProperty($oid, $relationField, null); + $this->uow->setOriginalEntityProperty($oid, $relationField, null); $reflField->setValue($parentObject, null); } // else leave $reflFieldValue null for single-valued associations @@ -490,8 +490,8 @@ protected function hydrateRowData(array $row, array &$result): void if (isset($this->resultSetMapping()->indexByMap[$dqlAlias])) { $resultKey = $row[$this->resultSetMapping()->indexByMap[$dqlAlias]]; - if (isset($this->_hints['collection'])) { - $this->_hints['collection']->hydrateSet($resultKey, $element); + if (isset($this->hints['collection'])) { + $this->hints['collection']->hydrateSet($resultKey, $element); } $result[$resultKey] = $element; @@ -499,8 +499,8 @@ protected function hydrateRowData(array $row, array &$result): void $resultKey = $this->resultCounter; ++$this->resultCounter; - if (isset($this->_hints['collection'])) { - $this->_hints['collection']->hydrateAdd($element); + if (isset($this->hints['collection'])) { + $this->hints['collection']->hydrateAdd($element); } $result[] = $element; @@ -518,8 +518,8 @@ protected function hydrateRowData(array $row, array &$result): void } } - if (isset($this->_hints[Query::HINT_INTERNAL_ITERATION]) && $this->_hints[Query::HINT_INTERNAL_ITERATION]) { - $this->_uow->hydrationComplete(); + if (isset($this->hints[Query::HINT_INTERNAL_ITERATION]) && $this->hints[Query::HINT_INTERNAL_ITERATION]) { + $this->uow->hydrationComplete(); } } diff --git a/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php index 07d8f0eeffa..0c1e32aa149 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php @@ -44,8 +44,8 @@ protected function cleanup(): void { parent::cleanup(); - $this->_uow->triggerEagerLoads(); - $this->_uow->hydrationComplete(); + $this->uow->triggerEagerLoads(); + $this->uow->hydrationComplete(); } /** @@ -59,7 +59,7 @@ protected function hydrateAllData(): array $this->hydrateRowData($row, $result); } - $this->_em->getUnitOfWork()->triggerEagerLoads(); + $this->em->getUnitOfWork()->triggerEagerLoads(); return $result; } @@ -77,7 +77,7 @@ protected function hydrateRowData(array $row, array &$result): void // We need to find the correct entity class name if we have inheritance in resultset if ($this->class->inheritanceType !== ClassMetadata::INHERITANCE_TYPE_NONE) { $discrColumn = $this->class->getDiscriminatorColumn(); - $discrColumnName = $this->getSQLResultCasing($this->_platform, $discrColumn['name']); + $discrColumnName = $this->getSQLResultCasing($this->platform, $discrColumn['name']); // Find mapped discriminator column from the result set. $metaMappingDiscrColumnName = array_search($discrColumnName, $this->resultSetMapping()->metaMappings, true); @@ -134,7 +134,7 @@ protected function hydrateRowData(array $row, array &$result): void // Convert field to a valid PHP value if (isset($cacheKeyInfo['type'])) { $type = $cacheKeyInfo['type']; - $value = $type->convertToPHPValue($value, $this->_platform); + $value = $type->convertToPHPValue($value, $this->platform); } if ($value !== null && isset($cacheKeyInfo['enumType'])) { @@ -160,17 +160,17 @@ protected function hydrateRowData(array $row, array &$result): void } } - if (isset($this->_hints[Query::HINT_REFRESH_ENTITY])) { - $this->registerManaged($this->class, $this->_hints[Query::HINT_REFRESH_ENTITY], $data); + if (isset($this->hints[Query::HINT_REFRESH_ENTITY])) { + $this->registerManaged($this->class, $this->hints[Query::HINT_REFRESH_ENTITY], $data); } - $uow = $this->_em->getUnitOfWork(); - $entity = $uow->createEntity($entityName, $data, $this->_hints); + $uow = $this->em->getUnitOfWork(); + $entity = $uow->createEntity($entityName, $data, $this->hints); $result[] = $entity; - if (isset($this->_hints[Query::HINT_INTERNAL_ITERATION]) && $this->_hints[Query::HINT_INTERNAL_ITERATION]) { - $this->_uow->hydrationComplete(); + if (isset($this->hints[Query::HINT_INTERNAL_ITERATION]) && $this->hints[Query::HINT_INTERNAL_ITERATION]) { + $this->uow->hydrationComplete(); } } } diff --git a/lib/Doctrine/ORM/NativeQuery.php b/lib/Doctrine/ORM/NativeQuery.php index f76e427797c..d633e57c156 100644 --- a/lib/Doctrine/ORM/NativeQuery.php +++ b/lib/Doctrine/ORM/NativeQuery.php @@ -60,7 +60,7 @@ protected function _doExecute(): Result|int $this->sql, $parameters, $types, - $this->_queryCacheProfile, + $this->queryCacheProfile, ); } } diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 9a24634a225..5a2bc0f0533 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -187,11 +187,11 @@ public function getAST(): SelectStatement|UpdateStatement|DeleteStatement protected function getResultSetMapping(): ResultSetMapping { // parse query or load from cache - if ($this->_resultSetMapping === null) { - $this->_resultSetMapping = $this->parse()->getResultSetMapping(); + if ($this->resultSetMapping === null) { + $this->resultSetMapping = $this->parse()->getResultSetMapping(); } - return $this->_resultSetMapping; + return $this->resultSetMapping; } /** @@ -252,14 +252,14 @@ protected function _doExecute(): Result|int { $executor = $this->parse()->getSqlExecutor(); - if ($this->_queryCacheProfile) { - $executor->setQueryCacheProfile($this->_queryCacheProfile); + if ($this->queryCacheProfile) { + $executor->setQueryCacheProfile($this->queryCacheProfile); } else { $executor->removeQueryCacheProfile(); } - if ($this->_resultSetMapping === null) { - $this->_resultSetMapping = $this->parserResult->getResultSetMapping(); + if ($this->resultSetMapping === null) { + $this->resultSetMapping = $this->parserResult->getResultSetMapping(); } // Prepare parameters @@ -276,7 +276,7 @@ protected function _doExecute(): Result|int } // evict all cache for the entity region - if ($this->hasCache && isset($this->_hints[self::HINT_CACHE_EVICT]) && $this->_hints[self::HINT_CACHE_EVICT]) { + if ($this->hasCache && isset($this->hints[self::HINT_CACHE_EVICT]) && $this->hints[self::HINT_CACHE_EVICT]) { $this->evictEntityCacheRegion(); } @@ -303,18 +303,18 @@ private function evictResultSetCache( array $types, array $connectionParams, ): void { - if ($this->_queryCacheProfile === null || ! $this->getExpireResultCache()) { + if ($this->queryCacheProfile === null || ! $this->getExpireResultCache()) { return; } - $cache = $this->_queryCacheProfile->getResultCache(); + $cache = $this->queryCacheProfile->getResultCache(); assert($cache !== null); $statements = (array) $executor->getSqlStatements(); // Type casted since it can either be a string or an array foreach ($statements as $statement) { - $cacheKeys = $this->_queryCacheProfile->generateCacheKeys($statement, $sqlParams, $types, $connectionParams); + $cacheKeys = $this->queryCacheProfile->generateCacheKeys($statement, $sqlParams, $types, $connectionParams); $cache->deleteItem(reset($cacheKeys)); } } @@ -684,14 +684,14 @@ public function getLockMode(): int|null */ protected function getQueryCacheId(): string { - ksort($this->_hints); + ksort($this->hints); return md5( - $this->getDQL() . serialize($this->_hints) . + $this->getDQL() . serialize($this->hints) . '&platform=' . get_debug_type($this->getEntityManager()->getConnection()->getDatabasePlatform()) . ($this->em->hasFilters() ? $this->em->getFilters()->getHash() : '') . '&firstResult=' . $this->firstResult . '&maxResult=' . $this->maxResults . - '&hydrationMode=' . $this->_hydrationMode . '&types=' . serialize($this->parsedTypes) . 'DOCTRINE_QUERY_CACHE_SALT', + '&hydrationMode=' . $this->hydrationMode . '&types=' . serialize($this->parsedTypes) . 'DOCTRINE_QUERY_CACHE_SALT', ); } diff --git a/lib/Doctrine/ORM/Query/Exec/AbstractSqlExecutor.php b/lib/Doctrine/ORM/Query/Exec/AbstractSqlExecutor.php index 6d207253d5b..0820b859a9c 100644 --- a/lib/Doctrine/ORM/Query/Exec/AbstractSqlExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/AbstractSqlExecutor.php @@ -19,7 +19,7 @@ abstract class AbstractSqlExecutor { /** @var list|string */ - protected array|string $_sqlStatements; + protected array|string $sqlStatements; protected QueryCacheProfile|null $queryCacheProfile; @@ -30,7 +30,7 @@ abstract class AbstractSqlExecutor */ public function getSqlStatements(): array|string { - return $this->_sqlStatements; + return $this->sqlStatements; } public function setQueryCacheProfile(QueryCacheProfile $qcp): void diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php index 373a05d7ff9..6096462c7d9 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php @@ -79,8 +79,8 @@ public function __construct(AST\Node $AST, SqlWalker $sqlWalker) // 3. Create and store DELETE statements $classNames = [...$primaryClass->parentClasses, ...[$primaryClass->name], ...$primaryClass->subClasses]; foreach (array_reverse($classNames) as $className) { - $tableName = $quoteStrategy->getTableName($em->getClassMetadata($className), $platform); - $this->_sqlStatements[] = 'DELETE FROM ' . $tableName + $tableName = $quoteStrategy->getTableName($em->getClassMetadata($className), $platform); + $this->sqlStatements[] = 'DELETE FROM ' . $tableName . ' WHERE (' . $idColumnList . ') IN (' . $idSubselect . ')'; } @@ -112,7 +112,7 @@ public function execute(Connection $conn, array $params, array $types): int $numDeleted = $conn->executeStatement($this->insertSql, $params, $types); // Execute DELETE statements - foreach ($this->_sqlStatements as $sql) { + foreach ($this->sqlStatements as $sql) { $conn->executeStatement($sql); } } catch (Throwable $exception) { diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php index 2079c3007e1..dd5f3055d58 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php @@ -111,7 +111,7 @@ public function __construct(AST\Node $AST, SqlWalker $sqlWalker) } if ($affected) { - $this->_sqlStatements[$i] = $updateSql . ' WHERE (' . $idColumnList . ') IN (' . $idSubselect . ')'; + $this->sqlStatements[$i] = $updateSql . ' WHERE (' . $idColumnList . ') IN (' . $idSubselect . ')'; } } @@ -156,7 +156,7 @@ public function execute(Connection $conn, array $params, array $types): int ); // Execute UPDATE statements - foreach ($this->_sqlStatements as $key => $statement) { + foreach ($this->sqlStatements as $key => $statement) { $paramValues = []; $paramTypes = []; diff --git a/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php b/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php index 9220922e5af..5445edb9994 100644 --- a/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php @@ -18,7 +18,7 @@ class SingleSelectExecutor extends AbstractSqlExecutor { public function __construct(SelectStatement $AST, SqlWalker $sqlWalker) { - $this->_sqlStatements = $sqlWalker->walkSelectStatement($AST); + $this->sqlStatements = $sqlWalker->walkSelectStatement($AST); } /** @@ -26,6 +26,6 @@ public function __construct(SelectStatement $AST, SqlWalker $sqlWalker) */ public function execute(Connection $conn, array $params, array $types): Result { - return $conn->executeQuery($this->_sqlStatements, $params, $types, $this->queryCacheProfile); + return $conn->executeQuery($this->sqlStatements, $params, $types, $this->queryCacheProfile); } } diff --git a/lib/Doctrine/ORM/Query/Exec/SingleTableDeleteUpdateExecutor.php b/lib/Doctrine/ORM/Query/Exec/SingleTableDeleteUpdateExecutor.php index 55ddb7f9339..7252684f280 100644 --- a/lib/Doctrine/ORM/Query/Exec/SingleTableDeleteUpdateExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/SingleTableDeleteUpdateExecutor.php @@ -23,9 +23,9 @@ class SingleTableDeleteUpdateExecutor extends AbstractSqlExecutor public function __construct(AST\Node $AST, $sqlWalker) { if ($AST instanceof AST\UpdateStatement) { - $this->_sqlStatements = $sqlWalker->walkUpdateStatement($AST); + $this->sqlStatements = $sqlWalker->walkUpdateStatement($AST); } elseif ($AST instanceof AST\DeleteStatement) { - $this->_sqlStatements = $sqlWalker->walkDeleteStatement($AST); + $this->sqlStatements = $sqlWalker->walkDeleteStatement($AST); } } @@ -38,6 +38,6 @@ public function execute(Connection $conn, array $params, array $types): int $conn->ensureConnectedToPrimary(); } - return $conn->executeStatement($this->_sqlStatements, $params, $types); + return $conn->executeStatement($this->sqlStatements, $params, $types); } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index c55b0763731..ae1e544ecd8 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -203,18 +203,6 @@ - lib/Doctrine/ORM/AbstractQuery.php - lib/Doctrine/ORM/Configuration.php - lib/Doctrine/ORM/EntityRepository.php - lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php - lib/Doctrine/ORM/Query/Exec/AbstractSqlExecutor.php - lib/Doctrine/ORM/Query/Exec/AbstractSqlExecutor.php - lib/Doctrine/ORM/Query/Printer.php - lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php - lib/Doctrine/ORM/Tools/Console/Helper/EntityManagerHelper.php - lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php - lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php - lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php tests/Doctrine/Tests/OrmFunctionalTestCase.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index daa2401bd78..df19a2565cd 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1209,14 +1209,14 @@ int - $this->_sqlStatements + $this->sqlStatements MultiTableDeleteExecutor MultiTableDeleteExecutor - $this->_sqlStatements + $this->sqlStatements @@ -1227,22 +1227,22 @@ int - $this->_sqlStatements + $this->sqlStatements MultiTableUpdateExecutor MultiTableUpdateExecutor - $this->_sqlStatements + $this->sqlStatements - $this->_sqlStatements + $this->sqlStatements - $this->_sqlStatements + $this->sqlStatements SingleSelectExecutor @@ -1250,13 +1250,13 @@ - $conn->executeStatement($this->_sqlStatements, $params, $types) + $conn->executeStatement($this->sqlStatements, $params, $types) int - $this->_sqlStatements + $this->sqlStatements SingleTableDeleteUpdateExecutor diff --git a/tests/Doctrine/Tests/ORM/AbstractQueryTest.php b/tests/Doctrine/Tests/ORM/AbstractQueryTest.php index 5ce4a9019bd..a0360decbeb 100644 --- a/tests/Doctrine/Tests/ORM/AbstractQueryTest.php +++ b/tests/Doctrine/Tests/ORM/AbstractQueryTest.php @@ -70,6 +70,6 @@ protected function _doExecute(): Result|int public function getResultCache(): CacheItemPoolInterface|null { - return $this->_queryCacheProfile->getResultCache(); + return $this->queryCacheProfile->getResultCache(); } }