Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Rector on the source code #11205

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Exception/EntityIdentityCollisionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Exception;

use function get_class;
use function sprintf;

final class EntityIdentityCollisionException extends Exception implements ORMException
Expand All @@ -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,
),
);
}
Expand Down
8 changes: 3 additions & 5 deletions src/Internal/Hydration/ObjectHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
);
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/TopologicalSort/CycleDetectedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');

Expand Down
2 changes: 1 addition & 1 deletion src/Mapping/AssociationMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}

Expand Down
6 changes: 1 addition & 5 deletions src/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/ORMSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 1 addition & 7 deletions src/PersistentCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -86,12 +81,11 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec
* @psalm-param Collection<TKey, T>&Selectable<TKey, T> $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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Persisters/Entity/SingleTablePersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
));
Expand Down
6 changes: 3 additions & 3 deletions src/Proxy/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down Expand Up @@ -66,7 +66,7 @@ public static function register(
return;
}

if (strpos($className, $proxyNamespace) !== 0) {
if (! str_starts_with($className, $proxyNamespace)) {
return;
}

Expand Down
3 changes: 1 addition & 2 deletions src/Proxy/DefaultProxyClassNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Doctrine\Persistence\Mapping\ProxyClassNameResolver;
use Doctrine\Persistence\Proxy;

use function get_class;
use function strrpos;
use function substr;

Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/Proxy/ProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand Down
5 changes: 2 additions & 3 deletions src/Tools/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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();

Expand Down
4 changes: 1 addition & 3 deletions src/Tools/Pagination/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
3 changes: 1 addition & 2 deletions src/Tools/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
17 changes: 8 additions & 9 deletions src/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
Loading