Skip to content

Commit 7008ba6

Browse files
committed
[DoctrineBridge] Simplify code related to entityClass
1 parent ce85e5b commit 7008ba6

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ public function validate($object, Constraint $constraint)
7373
throw new ConstraintDefinitionException(sprintf('Object manager "%s" does not exist.', $constraint->em));
7474
}
7575
} else {
76-
if (null !== $constraint->entityClass) {
77-
$em = $this->registry->getManagerForClass($constraint->entityClass);
78-
} else {
79-
$em = $this->registry->getManagerForClass($entityClass);
80-
}
76+
$em = $this->registry->getManagerForClass($constraint->entityClass ?? $entityClass);
8177

8278
if (!$em) {
8379
throw new ConstraintDefinitionException(sprintf('Unable to find the object manager associated with an entity of class "%s".', get_debug_type($object)));
@@ -188,18 +184,18 @@ public function validate($object, Constraint $constraint)
188184

189185
$fieldValues = $this->getFieldValues($object, $class, $identifierFieldNames);
190186
if (array_values($class->getIdentifierFieldNames()) != array_values($identifierFieldNames)) {
191-
throw new ConstraintDefinitionException(sprintf('The "%s" entity identifier field names should be "%s", not "%s".', $constraint->entityClass, implode(', ', $class->getIdentifierFieldNames()), implode(', ', $constraint->identifierFieldNames)));
187+
throw new ConstraintDefinitionException(sprintf('The "%s" entity identifier field names should be "%s", not "%s".', $entityClass, implode(', ', $class->getIdentifierFieldNames()), implode(', ', $constraint->identifierFieldNames)));
192188
}
193189

194190
$entityMatched = true;
195191

196192
foreach ($identifierFieldNames as $identifierFieldName) {
197-
$field = new \ReflectionProperty($constraint->entityClass, $identifierFieldName);
193+
$field = new \ReflectionProperty($entityClass, $identifierFieldName);
198194
if (!$field->isPublic()) {
199195
$field->setAccessible(true);
200196
}
201197

202-
$propertyValue = $this->getPropertyValue($constraint->entityClass, $identifierFieldName, current($result));
198+
$propertyValue = $this->getPropertyValue($entityClass, $identifierFieldName, current($result));
203199
if ($fieldValues[$identifierFieldName] !== $propertyValue) {
204200
$entityMatched = false;
205201
break;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy