Skip to content

Commit

Permalink
add typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
Warxcell committed Feb 21, 2021
1 parent a81aff0 commit 9d57e0f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 47 deletions.
46 changes: 16 additions & 30 deletions lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
Expand Up @@ -21,7 +21,6 @@
namespace Doctrine\ORM\Internal\Hydration;

use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
Expand Down Expand Up @@ -94,7 +93,7 @@ abstract class AbstractHydrator
/**
* The statement that provides the data to hydrate.
*
* @var Statement
* @var ResultStatement
*/
protected $_stmt;

Expand Down Expand Up @@ -122,13 +121,9 @@ public function __construct(EntityManagerInterface $em)
*
* @deprecated
*
* @param object $stmt
* @param object $resultSetMapping
* @param array $hints
*
* @return IterableResult
* @param array<string, mixed> $hints
*/
public function iterate($stmt, $resultSetMapping, array $hints = [])
public function iterate(ResultStatement $stmt, object $resultSetMapping, array $hints = []): IterableResult
{
@trigger_error(
'Method ' . __METHOD__ . '() is deprecated and will be removed in Doctrine ORM 3.0. Use toIterable() instead.',
Expand Down Expand Up @@ -193,13 +188,12 @@ public function toIterable(ResultStatement $stmt, ResultSetMapping $resultSetMap
/**
* Hydrates all rows returned by the passed statement instance at once.
*
* @param object $stmt
* @param object $resultSetMapping
* @param array $hints
* @param ResultStatement $stmt
* @param array<string, mixed> $hints
*
* @return array
* @return mixed
*/
public function hydrateAll($stmt, $resultSetMapping, array $hints = [])
public function hydrateAll($stmt, object $resultSetMapping, array $hints = [])
{
$this->_stmt = $stmt;
$this->_rsm = $resultSetMapping;
Expand Down Expand Up @@ -264,10 +258,8 @@ protected function prepare()
/**
* Executes one-time cleanup tasks at the end of a hydration that was initiated
* through {@link hydrateAll} or {@link iterate()}.
*
* @return void
*/
protected function cleanup()
protected function cleanup(): void
{
$this->_stmt->closeCursor();

Expand All @@ -294,11 +286,9 @@ protected function cleanupAfterRowIteration(): void
* @param mixed[] $row The row data.
* @param mixed[] $result The result to fill.
*
* @return void
*
* @throws HydrationException
*/
protected function hydrateRowData(array $row, array &$result)
protected function hydrateRowData(array $row, array &$result): void
{
throw new HydrationException('hydrateRowData() not implemented by this hydrator.');
}
Expand All @@ -319,9 +309,9 @@ abstract protected function hydrateAllData();
* field names during this procedure as well as any necessary conversions on
* the values applied. Scalar values are kept in a specific key 'scalars'.
*
* @param mixed[] $data SQL Result Row.
* @param array &$id Dql-Alias => ID-Hash.
* @param array &$nonemptyComponents Does this DQL-Alias has at least one non NULL value?
* @param mixed[] $data SQL Result Row.
* @param array<string, string> $id Dql-Alias => ID-Hash.
* @param array<string, bool> $nonemptyComponents Does this DQL-Alias has at least one non NULL value?
*
* @return array<string, array<string, mixed>> An array with all the fields
* (name => value) of the data
Expand All @@ -337,7 +327,7 @@ abstract protected function hydrateAllData();
* scalars?: array
* }
*/
protected function gatherRowData(array $data, array &$id, array &$nonemptyComponents)
protected function gatherRowData(array $data, array &$id, array &$nonemptyComponents): array
{
$rowData = ['data' => []];

Expand Down Expand Up @@ -415,7 +405,7 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon
*
* @return array The processed row.
*/
protected function gatherScalarRowData(&$data)
protected function gatherScalarRowData(array &$data): array
{
$rowData = [];

Expand Down Expand Up @@ -448,7 +438,7 @@ protected function gatherScalarRowData(&$data)
*
* @return array|null
*/
protected function hydrateColumnInfo($key)
protected function hydrateColumnInfo(string $key)
{
if (isset($this->_cache[$key])) {
return $this->_cache[$key];
Expand Down Expand Up @@ -555,12 +545,8 @@ function (string $subClass): string {

/**
* Retrieve ClassMetadata associated to entity class name.
*
* @param string $className
*
* @return ClassMetadata
*/
protected function getClassMetadata($className)
protected function getClassMetadata(string $className): ClassMetadata
{
if (! isset($this->_metadataCache[$className])) {
$this->_metadataCache[$className] = $this->_em->getClassMetadata($className);
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php
Expand Up @@ -84,7 +84,7 @@ protected function hydrateAllData()
/**
* {@inheritdoc}
*/
protected function hydrateRowData(array $row, array &$result)
protected function hydrateRowData(array $row, array &$result): void
{
// 1) Initialize
$id = $this->_idTemplate; // initialize the id-memory
Expand Down
15 changes: 5 additions & 10 deletions lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
Expand Up @@ -120,10 +120,7 @@ protected function prepare()
}
}

/**
* {@inheritdoc}
*/
protected function cleanup()
protected function cleanup(): void
{
$eagerLoad = isset($this->_hints[UnitOfWork::HINT_DEFEREAGERLOAD]) && $this->_hints[UnitOfWork::HINT_DEFEREAGERLOAD] === true;

Expand Down Expand Up @@ -203,7 +200,7 @@ private function initRelatedCollection($entity, $class, $fieldName, $parentDqlAl
} elseif (
isset($this->_hints[Query::HINT_REFRESH]) ||
isset($this->_hints['fetched'][$parentDqlAlias][$fieldName]) &&
! $value->isInitialized()
! $value->isInitialized()
) {
// Is already PersistentCollection, but either REFRESH or FETCH-JOIN and UNINITIALIZED!
$value->setDirty(false);
Expand Down Expand Up @@ -288,8 +285,8 @@ private function getEntityFromIdentityMap($className, array $data)

foreach ($class->identifier as $fieldName) {
$idHash .= ' ' . (isset($class->associationMappings[$fieldName])
? $data[$class->associationMappings[$fieldName]['joinColumns'][0]['name']]
: $data[$fieldName]);
? $data[$class->associationMappings[$fieldName]['joinColumns'][0]['name']]
: $data[$fieldName]);
}

return $this->_uow->tryGetByIdHash(ltrim($idHash), $class->rootEntityName);
Expand Down Expand Up @@ -319,10 +316,8 @@ private function getEntityFromIdentityMap($className, array $data)
*
* @param array $row The data of the row to process.
* @param array $result The result array to fill.
*
* @return void
*/
protected function hydrateRowData(array $row, array &$result)
protected function hydrateRowData(array $row, array &$result): void
{
// Initialize
$id = $this->idTemplate; // initialize the id-memory
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php
Expand Up @@ -46,7 +46,7 @@ protected function hydrateAllData()
/**
* {@inheritdoc}
*/
protected function hydrateRowData(array $row, array &$result)
protected function hydrateRowData(array $row, array &$result): void
{
$result[] = $this->gatherScalarRowData($row);
}
Expand Down
7 changes: 2 additions & 5 deletions lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php
Expand Up @@ -55,10 +55,7 @@ protected function prepare()
$this->class = $this->getClassMetadata(reset($this->_rsm->aliasMap));
}

/**
* {@inheritdoc}
*/
protected function cleanup()
protected function cleanup(): void
{
parent::cleanup();

Expand All @@ -85,7 +82,7 @@ protected function hydrateAllData()
/**
* {@inheritdoc}
*/
protected function hydrateRowData(array $row, array &$result)
protected function hydrateRowData(array $row, array &$result): void
{
$entityName = $this->class->name;
$data = [];
Expand Down

0 comments on commit 9d57e0f

Please sign in to comment.