Skip to content

Commit 734a1c6

Browse files
authored
Merge pull request #9852 from MarcBrillault/internal-php8
Migrate Internal namespace to PHP8
2 parents 318e6ec + e22f02f commit 734a1c6

File tree

6 files changed

+30
-71
lines changed

6 files changed

+30
-71
lines changed

lib/Doctrine/ORM/Internal/CommitOrderCalculator.php

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,36 +38,27 @@ class CommitOrderCalculator
3838
*
3939
* @var array<stdClass>
4040
*/
41-
private $nodeList = [];
41+
private array $nodeList = [];
4242

4343
/**
4444
* Volatile variable holding calculated nodes during sorting process.
4545
*
4646
* @psalm-var list<object>
4747
*/
48-
private $sortedNodeList = [];
48+
private array $sortedNodeList = [];
4949

5050
/**
5151
* Checks for node (vertex) existence in graph.
52-
*
53-
* @param string $hash
54-
*
55-
* @return bool
5652
*/
57-
public function hasNode($hash)
53+
public function hasNode(string $hash): bool
5854
{
5955
return isset($this->nodeList[$hash]);
6056
}
6157

6258
/**
6359
* Adds a new node (vertex) to the graph, assigning its hash and value.
64-
*
65-
* @param string $hash
66-
* @param object $node
67-
*
68-
* @return void
6960
*/
70-
public function addNode($hash, $node)
61+
public function addNode(string $hash, object $node): void
7162
{
7263
$vertex = new stdClass();
7364

@@ -81,14 +72,8 @@ public function addNode($hash, $node)
8172

8273
/**
8374
* Adds a new dependency (edge) to the graph using their hashes.
84-
*
85-
* @param string $fromHash
86-
* @param string $toHash
87-
* @param int $weight
88-
*
89-
* @return void
9075
*/
91-
public function addDependency($fromHash, $toHash, $weight)
76+
public function addDependency(string $fromHash, string $toHash, int $weight): void
9277
{
9378
$vertex = $this->nodeList[$fromHash];
9479
$edge = new stdClass();
@@ -108,7 +93,7 @@ public function addDependency($fromHash, $toHash, $weight)
10893
*
10994
* @psalm-return list<object>
11095
*/
111-
public function sort()
96+
public function sort(): array
11297
{
11398
foreach ($this->nodeList as $vertex) {
11499
if ($vertex->state !== self::NOT_VISITED) {

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ abstract class AbstractHydrator
3636
*/
3737
protected ?ResultSetMapping $_rsm = null;
3838

39-
/**
40-
* The EntityManager instance.
41-
*/
42-
protected EntityManagerInterface $_em;
43-
4439
/**
4540
* The dbms Platform instance.
4641
*/
@@ -77,10 +72,12 @@ abstract class AbstractHydrator
7772
*/
7873
protected array $_hints = [];
7974

75+
protected EntityManagerInterface $_em;
76+
8077
/**
8178
* Initializes a new instance of a class derived from <tt>AbstractHydrator</tt>.
8279
*/
83-
public function __construct(EntityManagerInterface $em)
80+
public function __construct(protected EntityManagerInterface $em)
8481
{
8582
$this->_em = $em;
8683
$this->_platform = $em->getConnection()->getDatabasePlatform();
@@ -291,9 +288,7 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon
291288
if ($value !== null && isset($cacheKeyInfo['enumType'])) {
292289
$enumType = $cacheKeyInfo['enumType'];
293290
if (is_array($value)) {
294-
$value = array_map(static function ($value) use ($enumType): BackedEnum {
295-
return $enumType::from($value);
296-
}, $value);
291+
$value = array_map(static fn ($value): BackedEnum => $enumType::from($value), $value);
297292
} else {
298293
$value = $enumType::from($value);
299294
}
@@ -486,9 +481,7 @@ protected function hydrateColumnInfo(string $key): ?array
486481
private function getDiscriminatorValues(ClassMetadata $classMetadata): array
487482
{
488483
$values = array_map(
489-
function (string $subClass): string {
490-
return (string) $this->getClassMetadata($subClass)->discriminatorValue;
491-
},
484+
fn (string $subClass): string => (string) $this->getClassMetadata($subClass)->discriminatorValue,
492485
$classMetadata->subClasses
493486
);
494487

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
use Doctrine\ORM\Mapping\ClassMetadata;
88

9+
use function array_key_last;
910
use function count;
10-
use function end;
1111
use function is_array;
1212
use function key;
1313
use function reset;
@@ -124,9 +124,7 @@ protected function hydrateRowData(array $row, array &$result): void
124124
$baseElement[$relationAlias][] = $element;
125125
}
126126

127-
end($baseElement[$relationAlias]);
128-
129-
$this->_identifierMap[$path][$id[$parent]][$id[$dqlAlias]] = key($baseElement[$relationAlias]);
127+
$this->_identifierMap[$path][$id[$parent]][$id[$dqlAlias]] = array_key_last($baseElement[$relationAlias]);
130128
}
131129
}
132130
} else {
@@ -269,7 +267,6 @@ private function updateResultPointer(
269267
return;
270268
}
271269

272-
end($coll);
273-
$this->_resultPointers[$dqlAlias] =& $coll[key($coll)];
270+
$this->_resultPointers[$dqlAlias] =& $coll[array_key_last($coll)];
274271
}
275272
}

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,24 @@
2727
class ObjectHydrator extends AbstractHydrator
2828
{
2929
/** @var mixed[] */
30-
private $identifierMap = [];
30+
private array $identifierMap = [];
3131

3232
/** @var mixed[] */
33-
private $resultPointers = [];
33+
private array $resultPointers = [];
3434

3535
/** @var mixed[] */
36-
private $idTemplate = [];
36+
private array $idTemplate = [];
3737

38-
/** @var int */
39-
private $resultCounter = 0;
38+
private int $resultCounter = 0;
4039

4140
/** @var mixed[] */
42-
private $rootAliases = [];
41+
private array $rootAliases = [];
4342

4443
/** @var mixed[] */
45-
private $initializedCollections = [];
44+
private array $initializedCollections = [];
4645

4746
/** @var mixed[] */
48-
private $existingCollections = [];
47+
private array $existingCollections = [];
4948

5049
protected function prepare(): void
5150
{
@@ -148,12 +147,11 @@ protected function hydrateAllData(): array
148147
/**
149148
* Initializes a related collection.
150149
*
151-
* @param object $entity The entity to which the collection belongs.
152150
* @param string $fieldName The name of the field on the entity that holds the collection.
153151
* @param string $parentDqlAlias Alias of the parent fetch joining this collection.
154152
*/
155153
private function initRelatedCollection(
156-
$entity,
154+
object $entity,
157155
ClassMetadata $class,
158156
string $fieldName,
159157
string $parentDqlAlias
@@ -203,11 +201,9 @@ private function initRelatedCollection(
203201
* @param string $dqlAlias The DQL alias of the entity's class.
204202
* @psalm-param array<string, mixed> $data The instance data.
205203
*
206-
* @return object
207-
*
208204
* @throws HydrationException
209205
*/
210-
private function getEntity(array $data, string $dqlAlias)
206+
private function getEntity(array $data, string $dqlAlias): object
211207
{
212208
$className = $this->resultSetMapping()->aliasMap[$dqlAlias];
213209

@@ -252,10 +248,8 @@ private function getEntity(array $data, string $dqlAlias)
252248
/**
253249
* @psalm-param class-string $className
254250
* @psalm-param array<string, mixed> $data
255-
*
256-
* @return mixed
257251
*/
258-
private function getEntityFromIdentityMap(string $className, array $data)
252+
private function getEntityFromIdentityMap(string $className, array $data): object|bool
259253
{
260254
// TODO: Abstract this code and UnitOfWork::createEntity() equivalent?
261255
$class = $this->_metadataCache[$className];

lib/Doctrine/ORM/Internal/HydrationCompleteHandler.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,17 @@
1616
*/
1717
final class HydrationCompleteHandler
1818
{
19-
/** @var ListenersInvoker */
20-
private $listenersInvoker;
21-
22-
/** @var EntityManagerInterface */
23-
private $em;
24-
2519
/** @var mixed[][] */
26-
private $deferredPostLoadInvocations = [];
20+
private array $deferredPostLoadInvocations = [];
2721

28-
/**
29-
* Constructor for this object
30-
*/
31-
public function __construct(ListenersInvoker $listenersInvoker, EntityManagerInterface $em)
22+
public function __construct(private ListenersInvoker $listenersInvoker, private EntityManagerInterface $em)
3223
{
33-
$this->listenersInvoker = $listenersInvoker;
34-
$this->em = $em;
3524
}
3625

3726
/**
3827
* Method schedules invoking of postLoad entity to the very end of current hydration cycle.
39-
*
40-
* @param object $entity
4128
*/
42-
public function deferPostLoadInvoking(ClassMetadata $class, $entity): void
29+
public function deferPostLoadInvoking(ClassMetadata $class, object $entity): void
4330
{
4431
$invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::postLoad);
4532

psalm-baseline.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@
265265
<PossiblyInvalidArgument occurrences="1">
266266
<code>$index</code>
267267
</PossiblyInvalidArgument>
268+
<PossiblyNullArgument occurrences="1">
269+
<code>$index</code>
270+
</PossiblyNullArgument>
268271
<PossiblyNullArrayAssignment occurrences="2">
269272
<code>$result[$resultKey]</code>
270273
<code>$result[$resultKey]</code>

0 commit comments

Comments
 (0)