Skip to content

Commit

Permalink
Migrate more code to PHP8
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Jul 14, 2022
1 parent af1303e commit 214a912
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 67 deletions.
16 changes: 8 additions & 8 deletions lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class AttachEntityListenersListener
{
/** @var mixed[][] */
private $entityListeners = [];
private array $entityListeners = [];

/**
* Adds a entity listener for a specific entity.
Expand All @@ -23,11 +23,13 @@ class AttachEntityListenersListener
* @param string $listenerClass The listener class.
* @param string $eventName The entity lifecycle event.
* @param string|null $listenerCallback The listener callback method or NULL to use $eventName.
*
* @return void
*/
public function addEntityListener($entityClass, $listenerClass, $eventName, $listenerCallback = null)
{
public function addEntityListener(
string $entityClass,
string $listenerClass,
string $eventName,
$listenerCallback = null
): void {
$this->entityListeners[ltrim($entityClass, '\\')][] = [
'event' => $eventName,
'class' => $listenerClass,
Expand All @@ -37,10 +39,8 @@ public function addEntityListener($entityClass, $listenerClass, $eventName, $lis

/**
* Processes event and attach the entity listener.
*
* @return void
*/
public function loadClassMetadata(LoadClassMetadataEventArgs $event)
public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
{
$metadata = $event->getClassMetadata();

Expand Down
36 changes: 8 additions & 28 deletions lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,26 @@
*/
class DebugUnitOfWorkListener
{
/** @var string */
private $file;

/** @var string */
private $context;

/**
* Pass a stream and context information for the debugging session.
*
* The stream can be php://output to print to the screen.
*
* @param string $file
* @param string $context
*/
public function __construct($file = 'php://output', $context = '')
{
$this->file = $file;
$this->context = $context;
public function __construct(
private string $file = 'php://output',
private string $context = ''
) {
}

/**
* @return void
*/
public function onFlush(OnFlushEventArgs $args)
public function onFlush(OnFlushEventArgs $args): void
{
$this->dumpIdentityMap($args->getEntityManager());
}

/**
* Dumps the contents of the identity map into a stream.
*
* @return void
*/
public function dumpIdentityMap(EntityManagerInterface $em)
public function dumpIdentityMap(EntityManagerInterface $em): void
{
$uow = $em->getUnitOfWork();
$identityMap = $uow->getIdentityMap();
Expand Down Expand Up @@ -119,10 +105,7 @@ public function dumpIdentityMap(EntityManagerInterface $em)
fclose($fh);
}

/**
* @param mixed $var
*/
private function getType($var): string
private function getType(mixed $var): string
{
if (is_object($var)) {
$refl = new ReflectionObject($var);
Expand All @@ -133,10 +116,7 @@ private function getType($var): string
return gettype($var);
}

/**
* @param object $entity
*/
private function getIdString($entity, UnitOfWork $uow): string
private function getIdString(object $entity, UnitOfWork $uow): string
{
if ($uow->isInIdentityMap($entity)) {
$ids = $uow->getEntityIdentifier($entity);
Expand Down
18 changes: 5 additions & 13 deletions lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
class ResolveTargetEntityListener implements EventSubscriber
{
/** @var mixed[][] indexed by original entity name */
private $resolveTargetEntities = [];
private array $resolveTargetEntities = [];

/**
* {@inheritDoc}
*/
public function getSubscribedEvents()
public function getSubscribedEvents(): array
{
return [
Events::loadClassMetadata,
Expand All @@ -39,24 +39,18 @@ public function getSubscribedEvents()
/**
* Adds a target-entity class name to resolve to a new class name.
*
* @param string $originalEntity
* @param string $newEntity
* @psalm-param array<string, mixed> $mapping
*
* @return void
*/
public function addResolveTargetEntity($originalEntity, $newEntity, array $mapping)
public function addResolveTargetEntity(string $originalEntity, string $newEntity, array $mapping): void
{
$mapping['targetEntity'] = ltrim($newEntity, '\\');
$this->resolveTargetEntities[ltrim($originalEntity, '\\')] = $mapping;
}

/**
* @internal this is an event callback, and should not be called directly
*
* @return void
*/
public function onClassMetadataNotFound(OnClassMetadataNotFoundEventArgs $args)
public function onClassMetadataNotFound(OnClassMetadataNotFoundEventArgs $args): void
{
if (array_key_exists($args->getClassName(), $this->resolveTargetEntities)) {
$args->setFoundMetadata(
Expand All @@ -71,10 +65,8 @@ public function onClassMetadataNotFound(OnClassMetadataNotFoundEventArgs $args)
* Processes event and resolves new target entity names.
*
* @internal this is an event callback, and should not be called directly
*
* @return void
*/
public function loadClassMetadata(LoadClassMetadataEventArgs $args)
public function loadClassMetadata(LoadClassMetadataEventArgs $args): void
{
$cm = $args->getClassMetadata();

Expand Down
28 changes: 10 additions & 18 deletions lib/Doctrine/ORM/Utility/IdentifierFlattener.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,19 @@
*/
final class IdentifierFlattener
{
/**
* The UnitOfWork used to coordinate object-level transactions.
*
* @var UnitOfWork
*/
private $unitOfWork;

/**
* The metadata factory, used to retrieve the ORM metadata of entity classes.
*
* @var ClassMetadataFactory
*/
private $metadataFactory;

/**
* Initializes a new IdentifierFlattener instance, bound to the given EntityManager.
*/
public function __construct(UnitOfWork $unitOfWork, ClassMetadataFactory $metadataFactory)
{
$this->unitOfWork = $unitOfWork;
$this->metadataFactory = $metadataFactory;
public function __construct(
/**
* The UnitOfWork used to coordinate object-level transactions.
*/
private UnitOfWork $unitOfWork,
/**
* The metadata factory, used to retrieve the ORM metadata of entity classes.
*/
private ClassMetadataFactory $metadataFactory
) {
}

/**
Expand Down

0 comments on commit 214a912

Please sign in to comment.