diff --git a/src/Exception/EntityIdentityCollisionException.php b/src/Exception/EntityIdentityCollisionException.php index 06ddd5dce20..0af3162f605 100644 --- a/src/Exception/EntityIdentityCollisionException.php +++ b/src/Exception/EntityIdentityCollisionException.php @@ -6,7 +6,6 @@ use Exception; -use function get_class; use function sprintf; final class EntityIdentityCollisionException extends Exception implements ORMException @@ -31,9 +30,9 @@ public static function create(object $existingEntity, object $newEntity, string Otherwise, it might be an ORM-internal inconsistency, please report it. EXCEPTION , - get_class($newEntity), + $newEntity::class, $idHash, - get_class($existingEntity), + $existingEntity::class, ), ); } diff --git a/src/Internal/Hydration/ObjectHydrator.php b/src/Internal/Hydration/ObjectHydrator.php index 774100b6e5f..c83c1e4701e 100644 --- a/src/Internal/Hydration/ObjectHydrator.php +++ b/src/Internal/Hydration/ObjectHydrator.php @@ -277,11 +277,9 @@ private function getEntityFromIdentityMap(string $className, array $data): objec $idHash = UnitOfWork::getIdHashByIdentifier( array_map( /** @return mixed */ - static function (string $fieldName) use ($data, $class) { - return isset($class->associationMappings[$fieldName]) && assert($class->associationMappings[$fieldName]->isToOneOwningSide()) - ? $data[$class->associationMappings[$fieldName]->joinColumns[0]->name] - : $data[$fieldName]; - }, + static fn (string $fieldName) => isset($class->associationMappings[$fieldName]) && assert($class->associationMappings[$fieldName]->isToOneOwningSide()) + ? $data[$class->associationMappings[$fieldName]->joinColumns[0]->name] + : $data[$fieldName], $class->identifier, ), ); diff --git a/src/Internal/TopologicalSort/CycleDetectedException.php b/src/Internal/TopologicalSort/CycleDetectedException.php index c28ce561dce..3af5329fcb0 100644 --- a/src/Internal/TopologicalSort/CycleDetectedException.php +++ b/src/Internal/TopologicalSort/CycleDetectedException.php @@ -18,7 +18,7 @@ class CycleDetectedException extends RuntimeException */ private bool $cycleCollected = false; - public function __construct(private object $startNode) + public function __construct(private readonly object $startNode) { parent::__construct('A cycle has been detected, so a topological sort is not possible. The getCycle() method provides the list of nodes that form the cycle.'); diff --git a/src/Mapping/AssociationMapping.php b/src/Mapping/AssociationMapping.php index ea78bbd6764..0253413e8d8 100644 --- a/src/Mapping/AssociationMapping.php +++ b/src/Mapping/AssociationMapping.php @@ -221,7 +221,7 @@ final public function type(): int $this instanceof OneToManyAssociationMapping => ClassMetadata::ONE_TO_MANY, $this instanceof ManyToOneAssociationMapping => ClassMetadata::MANY_TO_ONE, $this instanceof ManyToManyAssociationMapping => ClassMetadata::MANY_TO_MANY, - default => throw new Exception('Cannot determine type for ' . $this::class), + default => throw new Exception('Cannot determine type for ' . static::class), }; } diff --git a/src/Mapping/ClassMetadata.php b/src/Mapping/ClassMetadata.php index 1ac54a40b4e..0d9889b6e77 100644 --- a/src/Mapping/ClassMetadata.php +++ b/src/Mapping/ClassMetadata.php @@ -2488,11 +2488,7 @@ public function fullyQualifiedClassName(string|null $className): string|null public function getMetadataValue(string $name): mixed { - if (isset($this->$name)) { - return $this->$name; - } - - return null; + return $this->$name ?? null; } /** diff --git a/src/ORMSetup.php b/src/ORMSetup.php index 0dae92fda42..7354c710fe9 100644 --- a/src/ORMSetup.php +++ b/src/ORMSetup.php @@ -43,7 +43,6 @@ public static function createAttributeMetadataConfiguration( * Creates a configuration with an XML metadata driver. * * @param string[] $paths - * @param true $isXsdValidationEnabled */ public static function createXMLMetadataConfiguration( array $paths, diff --git a/src/PersistentCollection.php b/src/PersistentCollection.php index 60cbacb34e2..1fcc61da2e9 100644 --- a/src/PersistentCollection.php +++ b/src/PersistentCollection.php @@ -61,11 +61,6 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec */ private AssociationMapping|null $association = null; - /** - * The EntityManager that manages the persistence of the collection. - */ - private EntityManagerInterface|null $em = null; - /** * The name of the field on the target entities that points to the owner * of the collection. This is only set if the association is bi-directional. @@ -86,12 +81,11 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec * @psalm-param Collection&Selectable $collection The collection elements. */ public function __construct( - EntityManagerInterface $em, + private EntityManagerInterface|null $em, private readonly ClassMetadata|null $typeClass, Collection $collection, ) { $this->collection = $collection; - $this->em = $em; $this->initialized = true; } diff --git a/src/Persisters/Entity/SingleTablePersister.php b/src/Persisters/Entity/SingleTablePersister.php index bd12f50f16a..4a4d9998266 100644 --- a/src/Persisters/Entity/SingleTablePersister.php +++ b/src/Persisters/Entity/SingleTablePersister.php @@ -138,7 +138,7 @@ protected function getSelectConditionCriteriaSQL(Criteria $criteria): string protected function getSelectConditionDiscriminatorValueSQL(): string { - $values = array_map([$this->conn, 'quote'], array_map( + $values = array_map($this->conn->quote(...), array_map( strval(...), array_flip(array_intersect($this->class->discriminatorMap, $this->class->subClasses)), )); diff --git a/src/Proxy/Autoloader.php b/src/Proxy/Autoloader.php index d30477a80e8..1013e735d32 100644 --- a/src/Proxy/Autoloader.php +++ b/src/Proxy/Autoloader.php @@ -10,8 +10,8 @@ use function ltrim; use function spl_autoload_register; use function str_replace; +use function str_starts_with; use function strlen; -use function strpos; use function substr; use const DIRECTORY_SEPARATOR; @@ -34,7 +34,7 @@ final class Autoloader */ public static function resolveFile(string $proxyDir, string $proxyNamespace, string $className): string { - if (strpos($className, $proxyNamespace) !== 0) { + if (! str_starts_with($className, $proxyNamespace)) { throw new NotAProxyClass($className, $proxyNamespace); } @@ -66,7 +66,7 @@ public static function register( return; } - if (strpos($className, $proxyNamespace) !== 0) { + if (! str_starts_with($className, $proxyNamespace)) { return; } diff --git a/src/Proxy/DefaultProxyClassNameResolver.php b/src/Proxy/DefaultProxyClassNameResolver.php index 6a6fd1c9579..1345f2e3122 100644 --- a/src/Proxy/DefaultProxyClassNameResolver.php +++ b/src/Proxy/DefaultProxyClassNameResolver.php @@ -7,7 +7,6 @@ use Doctrine\Persistence\Mapping\ProxyClassNameResolver; use Doctrine\Persistence\Proxy; -use function get_class; use function strrpos; use function substr; @@ -31,6 +30,6 @@ public function resolveClassName(string $className): string /** @return class-string */ public static function getClass(object $object): string { - return (new self())->resolveClassName(get_class($object)); + return (new self())->resolveClassName($object::class); } } diff --git a/src/Proxy/ProxyFactory.php b/src/Proxy/ProxyFactory.php index 2a8e70f5bbc..f784cefa651 100644 --- a/src/Proxy/ProxyFactory.php +++ b/src/Proxy/ProxyFactory.php @@ -138,7 +138,7 @@ public function __serialize(): array */ public function __construct( private readonly EntityManagerInterface $em, - private string $proxyDir, + private readonly string $proxyDir, private readonly string $proxyNs, bool|int $autoGenerate = self::AUTOGENERATE_NEVER, ) { diff --git a/src/Tools/Debug.php b/src/Tools/Debug.php index ec27065b3dd..8521e53decc 100644 --- a/src/Tools/Debug.php +++ b/src/Tools/Debug.php @@ -17,7 +17,6 @@ use function end; use function explode; use function extension_loaded; -use function get_class; use function html_entity_decode; use function ini_get; use function ini_set; @@ -95,7 +94,7 @@ public static function export(mixed $var, int $maxDepth): mixed } if (! $maxDepth) { - return is_object($var) ? get_class($var) + return is_object($var) ? $var::class : (is_array($var) ? 'Array(' . count($var) . ')' : $var); } @@ -115,7 +114,7 @@ public static function export(mixed $var, int $maxDepth): mixed $return = new stdClass(); if ($var instanceof DateTimeInterface) { - $return->__CLASS__ = get_class($var); + $return->__CLASS__ = $var::class; $return->date = $var->format('c'); $return->timezone = $var->getTimezone()->getName(); diff --git a/src/Tools/Pagination/Paginator.php b/src/Tools/Pagination/Paginator.php index 01f97501484..db1b34db715 100644 --- a/src/Tools/Pagination/Paginator.php +++ b/src/Tools/Pagination/Paginator.php @@ -258,8 +258,6 @@ private function convertWhereInIdentifiersToDatabaseValues(array $identifiers): $type = $query->getSQL(); assert(is_string($type)); - return array_map(static function ($id) use ($connection, $type): mixed { - return $connection->convertToDatabaseValue($id, $type); - }, $identifiers); + return array_map(static fn ($id): mixed => $connection->convertToDatabaseValue($id, $type), $identifiers); } } diff --git a/src/Tools/SchemaValidator.php b/src/Tools/SchemaValidator.php index 71a2db44974..687fd1d36ba 100644 --- a/src/Tools/SchemaValidator.php +++ b/src/Tools/SchemaValidator.php @@ -35,7 +35,6 @@ use function class_exists; use function class_parents; use function count; -use function get_class; use function implode; use function in_array; use function interface_exists; @@ -435,7 +434,7 @@ function (FieldMapping $fieldMapping) use ($class): string|null { */ private function findBuiltInType(Type $type): string|null { - $typeName = get_class($type); + $typeName = $type::class; return self::BUILTIN_TYPES_MAP[$typeName] ?? null; } diff --git a/src/UnitOfWork.php b/src/UnitOfWork.php index 708f23ff80c..37fcf71253c 100644 --- a/src/UnitOfWork.php +++ b/src/UnitOfWork.php @@ -62,7 +62,6 @@ use function array_values; use function assert; use function current; -use function get_class; use function get_debug_type; use function implode; use function in_array; @@ -1039,7 +1038,7 @@ private function executeInserts(): void foreach ($entities as $entity) { $oid = spl_object_id($entity); - $class = $this->em->getClassMetadata(get_class($entity)); + $class = $this->em->getClassMetadata($entity::class); $persister = $this->getEntityPersister($class->name); $persister->addInsert($entity); @@ -1112,7 +1111,7 @@ private function addToEntityIdentifiersAndEntityMap( private function executeUpdates(): void { foreach ($this->entityUpdates as $oid => $entity) { - $class = $this->em->getClassMetadata(get_class($entity)); + $class = $this->em->getClassMetadata($entity::class); $persister = $this->getEntityPersister($class->name); $preUpdateInvoke = $this->listenersInvoker->getSubscribedSystems($class, Events::preUpdate); $postUpdateInvoke = $this->listenersInvoker->getSubscribedSystems($class, Events::postUpdate); @@ -1145,7 +1144,7 @@ private function executeDeletions(): void foreach ($entities as $entity) { $oid = spl_object_id($entity); - $class = $this->em->getClassMetadata(get_class($entity)); + $class = $this->em->getClassMetadata($entity::class); $persister = $this->getEntityPersister($class->name); $invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::postRemove); @@ -1194,7 +1193,7 @@ private function computeInsertExecutionOrder(): array // Now add edges foreach ($this->entityInsertions as $entity) { - $class = $this->em->getClassMetadata(get_class($entity)); + $class = $this->em->getClassMetadata($entity::class); foreach ($class->associationMappings as $assoc) { // We only need to consider the owning sides of to-one associations, @@ -1257,7 +1256,7 @@ private function computeDeleteExecutionOrder(): array // we need to treat those groups like a single entity when performing delete // order topological sorting. foreach ($this->entityDeletions as $entity) { - $class = $this->em->getClassMetadata(get_class($entity)); + $class = $this->em->getClassMetadata($entity::class); foreach ($class->associationMappings as $assoc) { // We only need to consider the owning sides of to-one associations, @@ -1294,7 +1293,7 @@ private function computeDeleteExecutionOrder(): array // Now do the actual topological sorting to find the delete order. foreach ($this->entityDeletions as $entity) { - $class = $this->em->getClassMetadata(get_class($entity)); + $class = $this->em->getClassMetadata($entity::class); // Get the entities representing the SCC $entityComponent = $stronglyConnectedComponents->getNodeRepresentingStronglyConnectedComponent($entity); @@ -1585,7 +1584,7 @@ public function getIdHashByEntity(object $entity): string $identifier = $this->entityIdentifiers[spl_object_id($entity)]; if (empty($identifier) || in_array(null, $identifier, true)) { - $classMetadata = $this->em->getClassMetadata(get_class($entity)); + $classMetadata = $this->em->getClassMetadata($entity::class); throw ORMInvalidArgumentException::entityWithoutIdentity($classMetadata->name, $entity); } @@ -3231,7 +3230,7 @@ private function normalizeIdentifier(ClassMetadata $targetClass, array $flatIden */ final public function assignPostInsertId(object $entity, mixed $generatedId): void { - $class = $this->em->getClassMetadata(get_class($entity)); + $class = $this->em->getClassMetadata($entity::class); $idField = $class->getSingleIdentifierFieldName(); $idValue = $this->convertSingleFieldIdentifierToPHPValue($class, $generatedId); $oid = spl_object_id($entity);