mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -13,8 +13,6 @@ namespace Chill\PersonBundle\Actions\Remove;
|
||||
|
||||
use Chill\PersonBundle\Actions\ActionEvent;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\Relationships\Relationship;
|
||||
@@ -22,10 +20,6 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
use function array_merge;
|
||||
use function implode;
|
||||
use function in_array;
|
||||
|
||||
/**
|
||||
* Move or delete entities associated to a person to a new one, and delete the
|
||||
* old person. The data associated to a person (birthdate, name, ...) are left
|
||||
@@ -36,7 +30,7 @@ use function in_array;
|
||||
class PersonMove
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly PersonMoveManager $personMoveManager,
|
||||
private readonly EventDispatcherInterface $eventDispatcher
|
||||
) {}
|
||||
@@ -68,7 +62,7 @@ class PersonMove
|
||||
public function getSQL(Person $from, Person $to, array $deleteEntities = [])
|
||||
{
|
||||
$sqls = [];
|
||||
$toDelete = array_merge($deleteEntities, $this->getDeleteEntities());
|
||||
$toDelete = \array_merge($deleteEntities, $this->getDeleteEntities());
|
||||
|
||||
foreach ($this->em->getMetadataFactory()->getAllMetadata() as $metadata) {
|
||||
if ($metadata->isMappedSuperclass) {
|
||||
@@ -76,18 +70,17 @@ class PersonMove
|
||||
}
|
||||
|
||||
foreach ($metadata->getAssociationMappings() as $field => $mapping) {
|
||||
|
||||
if ($this->personMoveManager->hasHandler($metadata->getName(), $field)) {
|
||||
$sqls = array_merge($sqls, $this->personMoveManager->getSqls($metadata->getName(), $field, $from, $to));
|
||||
$sqls = \array_merge($sqls, $this->personMoveManager->getSqls($metadata->getName(), $field, $from, $to));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($mapping['sourceEntity'], $this->getIgnoredEntities(), true)) {
|
||||
if (\in_array($mapping['sourceEntity'], $this->getIgnoredEntities(), true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Person::class === $mapping['targetEntity'] and true === $mapping['isOwningSide']) {
|
||||
if (in_array($mapping['sourceEntity'], $toDelete, true)) {
|
||||
if (\in_array($mapping['sourceEntity'], $toDelete, true)) {
|
||||
$sql = $this->createDeleteSQL($metadata, $from, $field);
|
||||
$event = new ActionEvent(
|
||||
$from->getId(),
|
||||
@@ -96,9 +89,9 @@ class PersonMove
|
||||
['to' => $to->getId(), 'original_action' => 'move']
|
||||
);
|
||||
$this->eventDispatcher->dispatch($event, ActionEvent::DELETE);
|
||||
$sqls = array_merge($sqls, $event->getPreSql(), [$event->getSqlStatement()], $event->getPostSql());
|
||||
$sqls = \array_merge($sqls, $event->getPreSql(), [$event->getSqlStatement()], $event->getPostSql());
|
||||
} else {
|
||||
$sqls = array_merge($sqls, $this->createMoveSQLs($metadata, $from, $to, $field));
|
||||
$sqls = \array_merge($sqls, $this->createMoveSQLs($metadata, $from, $to, $field));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,7 +126,7 @@ class PersonMove
|
||||
return sprintf(
|
||||
'DELETE FROM %s WHERE %s;',
|
||||
$this->getTableName($metadata),
|
||||
implode(' AND ', $conditions)
|
||||
\implode(' AND ', $conditions)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -148,11 +141,11 @@ class PersonMove
|
||||
|
||||
if (array_key_exists('joinTable', $mapping)) {
|
||||
// there is a join_table: we have to find conflict
|
||||
$tableName = (null !== ($mapping['joinTable']['schema'] ?? null) ? $mapping['joinTable']['schema'] . '.' : '')
|
||||
. $mapping['joinTable']['name'];
|
||||
$tableName = (null !== ($mapping['joinTable']['schema'] ?? null) ? $mapping['joinTable']['schema'].'.' : '')
|
||||
.$mapping['joinTable']['name'];
|
||||
|
||||
$sqlInsert = sprintf(
|
||||
"INSERT INTO %s (%s, %s) SELECT %d, %s FROM %s WHERE %s = %d ON CONFLICT DO NOTHING;",
|
||||
'INSERT INTO %s (%s, %s) SELECT %d, %s FROM %s WHERE %s = %d ON CONFLICT DO NOTHING;',
|
||||
$tableName,
|
||||
$mapping['joinTable']['inverseJoinColumns'][0]['name'], // person_id
|
||||
$mapping['joinTable']['joinColumns'][0]['name'], // something_else_id
|
||||
@@ -164,7 +157,7 @@ class PersonMove
|
||||
);
|
||||
|
||||
$deleteSql = sprintf(
|
||||
"DELETE FROM %s WHERE %s = %d;",
|
||||
'DELETE FROM %s WHERE %s = %d;',
|
||||
$tableName,
|
||||
$mapping['joinTable']['inverseJoinColumns'][0]['name'], // person_id
|
||||
$from->getId()
|
||||
@@ -179,9 +172,8 @@ class PersonMove
|
||||
}
|
||||
|
||||
return [
|
||||
$sqlInsert, $deleteSql
|
||||
$sqlInsert, $deleteSql,
|
||||
];
|
||||
|
||||
}
|
||||
if (array_key_exists('joinColumns', $mapping)) {
|
||||
$tableName = $this->getTableName($metadata);
|
||||
@@ -197,8 +189,8 @@ class PersonMove
|
||||
return [sprintf(
|
||||
'UPDATE %s SET %s WHERE %s;',
|
||||
$tableName,
|
||||
implode(' ', $sets),
|
||||
implode(' AND ', $conditions)
|
||||
\implode(' ', $sets),
|
||||
\implode(' AND ', $conditions)
|
||||
)];
|
||||
}
|
||||
|
||||
@@ -210,7 +202,7 @@ class PersonMove
|
||||
{
|
||||
return [
|
||||
AccompanyingPeriod\AccompanyingPeriodWork::class,
|
||||
Relationship::class
|
||||
Relationship::class,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -230,6 +222,6 @@ class PersonMove
|
||||
{
|
||||
return empty($metadata->getSchemaName()) ?
|
||||
$metadata->getTableName() :
|
||||
$metadata->getSchemaName() . '.' . $metadata->getTableName();
|
||||
$metadata->getSchemaName().'.'.$metadata->getTableName();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user