Skip to content

Commit

Permalink
Migrate Internal namespace to PHP8
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcBrillault authored and greg0ire committed Jun 17, 2022
1 parent af1303e commit e22f02f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 71 deletions.
27 changes: 6 additions & 21 deletions lib/Doctrine/ORM/Internal/CommitOrderCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,36 +38,27 @@ class CommitOrderCalculator
*
* @var array<stdClass>
*/
private $nodeList = [];
private array $nodeList = [];

/**
* Volatile variable holding calculated nodes during sorting process.
*
* @psalm-var list<object>
*/
private $sortedNodeList = [];
private array $sortedNodeList = [];

/**
* Checks for node (vertex) existence in graph.
*
* @param string $hash
*
* @return bool
*/
public function hasNode($hash)
public function hasNode(string $hash): bool
{
return isset($this->nodeList[$hash]);
}

/**
* Adds a new node (vertex) to the graph, assigning its hash and value.
*
* @param string $hash
* @param object $node
*
* @return void
*/
public function addNode($hash, $node)
public function addNode(string $hash, object $node): void
{
$vertex = new stdClass();

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

/**
* Adds a new dependency (edge) to the graph using their hashes.
*
* @param string $fromHash
* @param string $toHash
* @param int $weight
*
* @return void
*/
public function addDependency($fromHash, $toHash, $weight)
public function addDependency(string $fromHash, string $toHash, int $weight): void
{
$vertex = $this->nodeList[$fromHash];
$edge = new stdClass();
Expand All @@ -108,7 +93,7 @@ public function addDependency($fromHash, $toHash, $weight)
*
* @psalm-return list<object>
*/
public function sort()
public function sort(): array
{
foreach ($this->nodeList as $vertex) {
if ($vertex->state !== self::NOT_VISITED) {
Expand Down
17 changes: 5 additions & 12 deletions lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ abstract class AbstractHydrator
*/
protected ?ResultSetMapping $_rsm = null;

/**
* The EntityManager instance.
*/
protected EntityManagerInterface $_em;

/**
* The dbms Platform instance.
*/
Expand Down Expand Up @@ -77,10 +72,12 @@ abstract class AbstractHydrator
*/
protected array $_hints = [];

protected EntityManagerInterface $_em;

/**
* Initializes a new instance of a class derived from <tt>AbstractHydrator</tt>.
*/
public function __construct(EntityManagerInterface $em)
public function __construct(protected EntityManagerInterface $em)
{
$this->_em = $em;
$this->_platform = $em->getConnection()->getDatabasePlatform();
Expand Down Expand Up @@ -291,9 +288,7 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon
if ($value !== null && isset($cacheKeyInfo['enumType'])) {
$enumType = $cacheKeyInfo['enumType'];
if (is_array($value)) {
$value = array_map(static function ($value) use ($enumType): BackedEnum {
return $enumType::from($value);
}, $value);
$value = array_map(static fn ($value): BackedEnum => $enumType::from($value), $value);
} else {
$value = $enumType::from($value);
}
Expand Down Expand Up @@ -486,9 +481,7 @@ protected function hydrateColumnInfo(string $key): ?array
private function getDiscriminatorValues(ClassMetadata $classMetadata): array
{
$values = array_map(
function (string $subClass): string {
return (string) $this->getClassMetadata($subClass)->discriminatorValue;
},
fn (string $subClass): string => (string) $this->getClassMetadata($subClass)->discriminatorValue,
$classMetadata->subClasses
);

Expand Down
9 changes: 3 additions & 6 deletions lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use Doctrine\ORM\Mapping\ClassMetadata;

use function array_key_last;
use function count;
use function end;
use function is_array;
use function key;
use function reset;
Expand Down Expand Up @@ -124,9 +124,7 @@ protected function hydrateRowData(array $row, array &$result): void
$baseElement[$relationAlias][] = $element;
}

end($baseElement[$relationAlias]);

$this->_identifierMap[$path][$id[$parent]][$id[$dqlAlias]] = key($baseElement[$relationAlias]);
$this->_identifierMap[$path][$id[$parent]][$id[$dqlAlias]] = array_key_last($baseElement[$relationAlias]);
}
}
} else {
Expand Down Expand Up @@ -269,7 +267,6 @@ private function updateResultPointer(
return;
}

end($coll);
$this->_resultPointers[$dqlAlias] =& $coll[key($coll)];
$this->_resultPointers[$dqlAlias] =& $coll[array_key_last($coll)];
}
}
26 changes: 10 additions & 16 deletions lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,24 @@
class ObjectHydrator extends AbstractHydrator
{
/** @var mixed[] */
private $identifierMap = [];
private array $identifierMap = [];

/** @var mixed[] */
private $resultPointers = [];
private array $resultPointers = [];

/** @var mixed[] */
private $idTemplate = [];
private array $idTemplate = [];

/** @var int */
private $resultCounter = 0;
private int $resultCounter = 0;

/** @var mixed[] */
private $rootAliases = [];
private array $rootAliases = [];

/** @var mixed[] */
private $initializedCollections = [];
private array $initializedCollections = [];

/** @var mixed[] */
private $existingCollections = [];
private array $existingCollections = [];

protected function prepare(): void
{
Expand Down Expand Up @@ -148,12 +147,11 @@ protected function hydrateAllData(): array
/**
* Initializes a related collection.
*
* @param object $entity The entity to which the collection belongs.
* @param string $fieldName The name of the field on the entity that holds the collection.
* @param string $parentDqlAlias Alias of the parent fetch joining this collection.
*/
private function initRelatedCollection(
$entity,
object $entity,
ClassMetadata $class,
string $fieldName,
string $parentDqlAlias
Expand Down Expand Up @@ -203,11 +201,9 @@ private function initRelatedCollection(
* @param string $dqlAlias The DQL alias of the entity's class.
* @psalm-param array<string, mixed> $data The instance data.
*
* @return object
*
* @throws HydrationException
*/
private function getEntity(array $data, string $dqlAlias)
private function getEntity(array $data, string $dqlAlias): object
{
$className = $this->resultSetMapping()->aliasMap[$dqlAlias];

Expand Down Expand Up @@ -252,10 +248,8 @@ private function getEntity(array $data, string $dqlAlias)
/**
* @psalm-param class-string $className
* @psalm-param array<string, mixed> $data
*
* @return mixed
*/
private function getEntityFromIdentityMap(string $className, array $data)
private function getEntityFromIdentityMap(string $className, array $data): object|bool
{
// TODO: Abstract this code and UnitOfWork::createEntity() equivalent?
$class = $this->_metadataCache[$className];
Expand Down
19 changes: 3 additions & 16 deletions lib/Doctrine/ORM/Internal/HydrationCompleteHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,17 @@
*/
final class HydrationCompleteHandler
{
/** @var ListenersInvoker */
private $listenersInvoker;

/** @var EntityManagerInterface */
private $em;

/** @var mixed[][] */
private $deferredPostLoadInvocations = [];
private array $deferredPostLoadInvocations = [];

/**
* Constructor for this object
*/
public function __construct(ListenersInvoker $listenersInvoker, EntityManagerInterface $em)
public function __construct(private ListenersInvoker $listenersInvoker, private EntityManagerInterface $em)
{
$this->listenersInvoker = $listenersInvoker;
$this->em = $em;
}

/**
* Method schedules invoking of postLoad entity to the very end of current hydration cycle.
*
* @param object $entity
*/
public function deferPostLoadInvoking(ClassMetadata $class, $entity): void
public function deferPostLoadInvoking(ClassMetadata $class, object $entity): void
{
$invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::postLoad);

Expand Down
3 changes: 3 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@
<PossiblyInvalidArgument occurrences="1">
<code>$index</code>
</PossiblyInvalidArgument>
<PossiblyNullArgument occurrences="1">
<code>$index</code>
</PossiblyNullArgument>
<PossiblyNullArrayAssignment occurrences="2">
<code>$result[$resultKey]</code>
<code>$result[$resultKey]</code>
Expand Down

0 comments on commit e22f02f

Please sign in to comment.