Skip to content

Commit 9624129

Browse files
authored
Add native types to AbstractHydrator and child classes (#9353)
1 parent 9f85e27 commit 9624129

File tree

13 files changed

+74
-169
lines changed

13 files changed

+74
-169
lines changed

lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php

Lines changed: 19 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -31,64 +31,52 @@ abstract class AbstractHydrator
3131
{
3232
/**
3333
* The ResultSetMapping.
34-
*
35-
* @var ResultSetMapping|null
3634
*/
37-
protected $_rsm;
35+
protected ?ResultSetMapping $_rsm = null;
3836

3937
/**
4038
* The EntityManager instance.
41-
*
42-
* @var EntityManagerInterface
4339
*/
44-
protected $_em;
40+
protected EntityManagerInterface $_em;
4541

4642
/**
4743
* The dbms Platform instance.
48-
*
49-
* @var AbstractPlatform
5044
*/
51-
protected $_platform;
45+
protected AbstractPlatform $_platform;
5246

5347
/**
5448
* The UnitOfWork of the associated EntityManager.
55-
*
56-
* @var UnitOfWork
5749
*/
58-
protected $_uow;
50+
protected UnitOfWork $_uow;
5951

6052
/**
6153
* Local ClassMetadata cache to avoid going to the EntityManager all the time.
6254
*
6355
* @var array<string, ClassMetadata<object>>
6456
*/
65-
protected $_metadataCache = [];
57+
protected array $_metadataCache = [];
6658

6759
/**
6860
* The cache used during row-by-row hydration.
6961
*
7062
* @var array<string, mixed[]|null>
7163
*/
72-
protected $_cache = [];
64+
protected array $_cache = [];
7365

7466
/**
7567
* The statement that provides the data to hydrate.
76-
*
77-
* @var Result|null
7868
*/
79-
protected $_stmt;
69+
protected ?Result $_stmt = null;
8070

8171
/**
8272
* The query hints.
8373
*
8474
* @var array<string, mixed>
8575
*/
86-
protected $_hints = [];
76+
protected array $_hints = [];
8777

8878
/**
8979
* Initializes a new instance of a class derived from <tt>AbstractHydrator</tt>.
90-
*
91-
* @param EntityManagerInterface $em The EntityManager to use.
9280
*/
9381
public function __construct(EntityManagerInterface $em)
9482
{
@@ -166,10 +154,8 @@ final protected function resultSetMapping(): ResultSetMapping
166154
* Hydrates all rows returned by the passed statement instance at once.
167155
*
168156
* @psalm-param array<string, string> $hints
169-
*
170-
* @return mixed[]
171157
*/
172-
public function hydrateAll(Result $stmt, ResultSetMapping $resultSetMapping, array $hints = [])
158+
public function hydrateAll(Result $stmt, ResultSetMapping $resultSetMapping, array $hints = []): mixed
173159
{
174160
$this->_stmt = $stmt;
175161
$this->_rsm = $resultSetMapping;
@@ -190,32 +176,24 @@ public function hydrateAll(Result $stmt, ResultSetMapping $resultSetMapping, arr
190176
/**
191177
* When executed in a hydrate() loop we have to clear internal state to
192178
* decrease memory consumption.
193-
*
194-
* @param mixed $eventArgs
195-
*
196-
* @return void
197179
*/
198-
public function onClear($eventArgs)
180+
public function onClear(mixed $eventArgs): void
199181
{
200182
}
201183

202184
/**
203185
* Executes one-time preparation tasks, once each time hydration is started
204186
* through {@link hydrateAll} or {@link toIterable()}.
205-
*
206-
* @return void
207187
*/
208-
protected function prepare()
188+
protected function prepare(): void
209189
{
210190
}
211191

212192
/**
213193
* Executes one-time cleanup tasks at the end of a hydration that was initiated
214194
* through {@link hydrateAll} or {@link toIterable()}.
215-
*
216-
* @return void
217195
*/
218-
protected function cleanup()
196+
protected function cleanup(): void
219197
{
220198
$this->statement()->free();
221199

@@ -242,21 +220,17 @@ protected function cleanupAfterRowIteration(): void
242220
* @param mixed[] $row The row data.
243221
* @param mixed[] $result The result to fill.
244222
*
245-
* @return void
246-
*
247223
* @throws HydrationException
248224
*/
249-
protected function hydrateRowData(array $row, array &$result)
225+
protected function hydrateRowData(array $row, array &$result): void
250226
{
251227
throw new HydrationException('hydrateRowData() not implemented by this hydrator.');
252228
}
253229

254230
/**
255231
* Hydrates all rows from the current statement instance at once.
256-
*
257-
* @return mixed[]
258232
*/
259-
abstract protected function hydrateAllData();
233+
abstract protected function hydrateAllData(): mixed;
260234

261235
/**
262236
* Processes a row of the result set.
@@ -284,7 +258,7 @@ abstract protected function hydrateAllData();
284258
* scalars?: array
285259
* }
286260
*/
287-
protected function gatherRowData(array $data, array &$id, array &$nonemptyComponents)
261+
protected function gatherRowData(array $data, array &$id, array &$nonemptyComponents): array
288262
{
289263
$rowData = ['data' => []];
290264

@@ -365,7 +339,7 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon
365339
* @return mixed[] The processed row.
366340
* @psalm-return array<string, mixed>
367341
*/
368-
protected function gatherScalarRowData(&$data)
342+
protected function gatherScalarRowData(array &$data): array
369343
{
370344
$rowData = [];
371345

@@ -400,7 +374,7 @@ protected function gatherScalarRowData(&$data)
400374
* @return mixed[]|null
401375
* @psalm-return array<string, mixed>|null
402376
*/
403-
protected function hydrateColumnInfo($key)
377+
protected function hydrateColumnInfo(string $key): ?array
404378
{
405379
if (isset($this->_cache[$key])) {
406380
return $this->_cache[$key];
@@ -508,12 +482,8 @@ function (string $subClass): string {
508482

509483
/**
510484
* Retrieve ClassMetadata associated to entity class name.
511-
*
512-
* @param string $className
513-
*
514-
* @return ClassMetadata
515485
*/
516-
protected function getClassMetadata($className)
486+
protected function getClassMetadata(string $className): ClassMetadata
517487
{
518488
if (! isset($this->_metadataCache[$className])) {
519489
$this->_metadataCache[$className] = $this->_em->getClassMetadata($className);
@@ -525,14 +495,11 @@ protected function getClassMetadata($className)
525495
/**
526496
* Register entity as managed in UnitOfWork.
527497
*
528-
* @param object $entity
529498
* @param mixed[] $data
530499
*
531-
* @return void
532-
*
533500
* @todo The "$id" generation is the same of UnitOfWork#createEntity. Remove this duplication somehow
534501
*/
535-
protected function registerManaged(ClassMetadata $class, $entity, array $data)
502+
protected function registerManaged(ClassMetadata $class, object $entity, array $data): void
536503
{
537504
if ($class->isIdentifierComposite) {
538505
$id = [];

lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,22 @@
1919
class ArrayHydrator extends AbstractHydrator
2020
{
2121
/** @var array<string,bool> */
22-
private $_rootAliases = [];
22+
private array $_rootAliases = [];
2323

24-
/** @var bool */
25-
private $_isSimpleQuery = false;
24+
private bool $_isSimpleQuery = false;
2625

2726
/** @var mixed[] */
28-
private $_identifierMap = [];
27+
private array $_identifierMap = [];
2928

3029
/** @var mixed[] */
31-
private $_resultPointers = [];
30+
private array $_resultPointers = [];
3231

3332
/** @var array<string,string> */
34-
private $_idTemplate = [];
33+
private array $_idTemplate = [];
3534

36-
/** @var int */
37-
private $_resultCounter = 0;
35+
private int $_resultCounter = 0;
3836

39-
/**
40-
* {@inheritdoc}
41-
*/
42-
protected function prepare()
37+
protected function prepare(): void
4338
{
4439
$this->_isSimpleQuery = count($this->resultSetMapping()->aliasMap) <= 1;
4540

@@ -53,7 +48,7 @@ protected function prepare()
5348
/**
5449
* {@inheritdoc}
5550
*/
56-
protected function hydrateAllData()
51+
protected function hydrateAllData(): array
5752
{
5853
$result = [];
5954

@@ -67,7 +62,7 @@ protected function hydrateAllData()
6762
/**
6863
* {@inheritdoc}
6964
*/
70-
protected function hydrateRowData(array $row, array &$result)
65+
protected function hydrateRowData(array $row, array &$result): void
7166
{
7267
// 1) Initialize
7368
$id = $this->_idTemplate; // initialize the id-memory
@@ -242,13 +237,13 @@ protected function hydrateRowData(array $row, array &$result)
242237
* Updates the result pointer for an Entity. The result pointers point to the
243238
* last seen instance of each Entity type. This is used for graph construction.
244239
*
245-
* @param mixed[]|null $coll The element.
246-
* @param bool|int $index Index of the element in the collection.
247-
* @param bool $oneToOne Whether it is a single-valued association or not.
240+
* @param mixed[]|null $coll The element.
241+
* @param string|int|false $index Index of the element in the collection.
242+
* @param bool $oneToOne Whether it is a single-valued association or not.
248243
*/
249244
private function updateResultPointer(
250245
?array &$coll,
251-
$index,
246+
string|int|false $index,
252247
string $dqlAlias,
253248
bool $oneToOne
254249
): void {

lib/Doctrine/ORM/Internal/Hydration/HydrationException.php

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,12 @@
1212

1313
class HydrationException extends Exception implements ORMException
1414
{
15-
/**
16-
* @return HydrationException
17-
*/
18-
public static function nonUniqueResult()
15+
public static function nonUniqueResult(): self
1916
{
2017
return new self('The result returned by the query was not unique.');
2118
}
2219

23-
/**
24-
* @param string $alias
25-
* @param string $parentAlias
26-
*
27-
* @return HydrationException
28-
*/
29-
public static function parentObjectOfRelationNotFound($alias, $parentAlias)
20+
public static function parentObjectOfRelationNotFound(string $alias, string $parentAlias): self
3021
{
3122
return new self(sprintf(
3223
"The parent object of entity result with alias '%s' was not found."
@@ -36,27 +27,15 @@ public static function parentObjectOfRelationNotFound($alias, $parentAlias)
3627
));
3728
}
3829

39-
/**
40-
* @param string $dqlAlias
41-
*
42-
* @return HydrationException
43-
*/
44-
public static function emptyDiscriminatorValue($dqlAlias)
30+
public static function emptyDiscriminatorValue(string $dqlAlias): self
4531
{
4632
return new self("The DQL alias '" . $dqlAlias . "' contains an entity " .
4733
'of an inheritance hierarchy with an empty discriminator value. This means ' .
4834
'that the database contains inconsistent data with an empty ' .
4935
'discriminator value in a table row.');
5036
}
5137

52-
/**
53-
* @param string $entityName
54-
* @param string $discrColumnName
55-
* @param string $dqlAlias
56-
*
57-
* @return HydrationException
58-
*/
59-
public static function missingDiscriminatorColumn($entityName, $discrColumnName, $dqlAlias)
38+
public static function missingDiscriminatorColumn(string $entityName, string $discrColumnName, string $dqlAlias): self
6039
{
6140
return new self(sprintf(
6241
'The discriminator column "%s" is missing for "%s" using the DQL alias "%s".',
@@ -66,14 +45,7 @@ public static function missingDiscriminatorColumn($entityName, $discrColumnName,
6645
));
6746
}
6847

69-
/**
70-
* @param string $entityName
71-
* @param string $discrColumnName
72-
* @param string $dqlAlias
73-
*
74-
* @return HydrationException
75-
*/
76-
public static function missingDiscriminatorMetaMappingColumn($entityName, $discrColumnName, $dqlAlias)
48+
public static function missingDiscriminatorMetaMappingColumn(string $entityName, string $discrColumnName, string $dqlAlias): self
7749
{
7850
return new self(sprintf(
7951
'The meta mapping for the discriminator column "%s" is missing for "%s" using the DQL alias "%s".',
@@ -84,13 +56,10 @@ public static function missingDiscriminatorMetaMappingColumn($entityName, $discr
8456
}
8557

8658
/**
87-
* @param string $discrValue
8859
* @param string[] $discrMap
8960
* @psalm-param array<string, string> $discrMap
90-
*
91-
* @return HydrationException
9261
*/
93-
public static function invalidDiscriminatorValue($discrValue, $discrMap)
62+
public static function invalidDiscriminatorValue(string $discrValue, array $discrMap): self
9463
{
9564
return new self(sprintf(
9665
'The discriminator value "%s" is invalid. It must be one of "%s".',

0 commit comments

Comments
 (0)