mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 23:23:51 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -19,7 +19,7 @@ class PersonMoveAccompanyingPeriodParticipationHandler implements PersonMoveSqlH
|
||||
{
|
||||
public function supports(string $className, string $field): bool
|
||||
{
|
||||
return $className === AccompanyingPeriodParticipation::class;
|
||||
return AccompanyingPeriodParticipation::class === $className;
|
||||
}
|
||||
|
||||
public function getSqls(string $className, string $field, Person $from, Person $to): array
|
||||
|
@@ -23,7 +23,7 @@ class PersonMoveCenterHistoryHandler implements PersonMoveSqlHandlerInterface
|
||||
|
||||
public function supports(string $className, string $field): bool
|
||||
{
|
||||
return $className === Person\PersonCenterHistory::class;
|
||||
return Person\PersonCenterHistory::class === $className;
|
||||
}
|
||||
|
||||
public function getSqls(string $className, string $field, Person $from, Person $to): array
|
||||
@@ -37,7 +37,7 @@ class PersonMoveCenterHistoryHandler implements PersonMoveSqlHandlerInterface
|
||||
|
||||
$centerHistoriesA = $this->centerHistoryRepository->findBy(['person' => $from]);
|
||||
foreach ($centerHistoriesA as $ch) {
|
||||
if ($oldestDateA === null || ($ch->getStartDate() < $oldestDateA)) {
|
||||
if (null === $oldestDateA || ($ch->getStartDate() < $oldestDateA)) {
|
||||
$oldestDateA = $ch->getStartDate();
|
||||
$oldestCenterHistoryA = $ch;
|
||||
}
|
||||
@@ -45,7 +45,7 @@ class PersonMoveCenterHistoryHandler implements PersonMoveSqlHandlerInterface
|
||||
|
||||
$centerHistoriesB = $this->centerHistoryRepository->findBy(['person' => $to]);
|
||||
foreach ($centerHistoriesB as $ch) {
|
||||
if ($oldestDateB === null || ($ch->getStartDate() < $oldestDateB)) {
|
||||
if (null === $oldestDateB || ($ch->getStartDate() < $oldestDateB)) {
|
||||
$oldestDateB = $ch->getStartDate();
|
||||
$oldestCenterHistoryB = $ch;
|
||||
}
|
||||
@@ -58,7 +58,6 @@ class PersonMoveCenterHistoryHandler implements PersonMoveSqlHandlerInterface
|
||||
$sqlStatements = [$sqlDelete];
|
||||
|
||||
if ((null !== $oldestDateA && null !== $oldestDateB) && $oldestDateA <= $oldestDateB) {
|
||||
|
||||
$sqlInsert = sprintf(<<<'SQL'
|
||||
UPDATE chill_person_person_center_history SET startDate = '%s' WHERE id = %d;
|
||||
SQL, $oldestDateA->format('Y-m-d'), $oldestCenterHistoryB->getId());
|
||||
@@ -67,7 +66,5 @@ class PersonMoveCenterHistoryHandler implements PersonMoveSqlHandlerInterface
|
||||
}
|
||||
|
||||
return $sqlStatements;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ class PersonMoveHouseholdHandler implements PersonMoveSqlHandlerInterface
|
||||
{
|
||||
public function supports(string $className, string $field): bool
|
||||
{
|
||||
return $className === HouseholdMember::class;
|
||||
return HouseholdMember::class === $className;
|
||||
}
|
||||
|
||||
public function getSqls(string $className, string $field, Person $from, Person $to): array
|
||||
@@ -43,5 +43,4 @@ class PersonMoveHouseholdHandler implements PersonMoveSqlHandlerInterface
|
||||
|
||||
return [$sqlInsert, $deleteSql];
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ class PersonMoveRelationHandler implements PersonMoveSqlHandlerInterface
|
||||
{
|
||||
public function supports(string $className, string $field): bool
|
||||
{
|
||||
return $className === Relationship::class;
|
||||
return Relationship::class === $className;
|
||||
}
|
||||
|
||||
public function getSqls(string $className, string $field, Person $from, Person $to): array
|
||||
@@ -38,8 +38,8 @@ class PersonMoveRelationHandler implements PersonMoveSqlHandlerInterface
|
||||
SQL, $from->getId(), $from->getId(), $to->getId(), $from->getId(), $from->getId(), $to->getId());
|
||||
|
||||
$deleteSql = [
|
||||
sprintf("DELETE FROM chill_person_relationships WHERE fromperson_id = %d", $from->getId()),
|
||||
sprintf("DELETE FROM chill_person_relationships WHERE toperson_id = %d", $from->getId())
|
||||
sprintf('DELETE FROM chill_person_relationships WHERE fromperson_id = %d', $from->getId()),
|
||||
sprintf('DELETE FROM chill_person_relationships WHERE toperson_id = %d', $from->getId()),
|
||||
];
|
||||
|
||||
return [$insertSql, ...$deleteSql];
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
@@ -17,14 +17,13 @@ class PersonMoveManager
|
||||
{
|
||||
public function __construct(
|
||||
/**
|
||||
* @var iterable<PersonMoveSqlHandlerInterface>
|
||||
* @var iterable<PersonMoveSqlHandlerInterface>
|
||||
*/
|
||||
private readonly iterable $handlers,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param class-string $className
|
||||
* @return bool
|
||||
*/
|
||||
public function hasHandler(string $className, string $field): bool
|
||||
{
|
||||
@@ -39,6 +38,7 @@ class PersonMoveManager
|
||||
|
||||
/**
|
||||
* @param class-string $className
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getSqls(string $className, string $field, Person $from, Person $to): array
|
||||
@@ -48,7 +48,7 @@ class PersonMoveManager
|
||||
return $handler->getSqls($className, $field, $from, $to);
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ interface PersonMoveSqlHandlerInterface
|
||||
|
||||
/**
|
||||
* @param class-string $className
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getSqls(string $className, string $field, Person $from, Person $to): array;
|
||||
|
Reference in New Issue
Block a user