apply more cs rules for php-cs

This commit is contained in:
2023-10-17 13:27:03 +02:00
parent 0b0cbed9db
commit bc2041cbdd
1485 changed files with 8169 additions and 9620 deletions

View File

@@ -14,7 +14,6 @@ namespace Chill\PersonBundle\Repository;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Location;
use Chill\MainBundle\Entity\PostalCode;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\UserJob;
@@ -30,7 +29,6 @@ use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use Repository\AccompanyingPeriodACLAwareRepositoryTest;
use Symfony\Component\Security\Core\Security;
use function count;
/**
* @see AccompanyingPeriodACLAwareRepositoryTest
@@ -109,8 +107,8 @@ final readonly class AccompanyingPeriodACLAwareRepository implements Accompanyin
Person $person,
string $role,
?array $orderBy = [],
?int $limit = null,
?int $offset = null
int $limit = null,
int $offset = null
): array {
$qb = $this->accompanyingPeriodRepository->createQueryBuilder('ap');
$scopes = $this->authorizationHelper
@@ -124,7 +122,7 @@ final readonly class AccompanyingPeriodACLAwareRepository implements Accompanyin
$this->centerResolver->resolveCenters($person)
);
if (0 === count($scopes)) {
if (0 === \count($scopes)) {
return [];
}
@@ -139,11 +137,11 @@ final readonly class AccompanyingPeriodACLAwareRepository implements Accompanyin
return $qb->getQuery()->getResult();
}
public function addOrderLimitClauses(QueryBuilder $qb, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): QueryBuilder
public function addOrderLimitClauses(QueryBuilder $qb, array $orderBy = null, int $limit = null, int $offset = null): QueryBuilder
{
if (null !== $orderBy) {
foreach ($orderBy as $field => $order) {
$qb->addOrderBy('ap.' . $field, $order);
$qb->addOrderBy('ap.'.$field, $order);
}
}
@@ -159,9 +157,9 @@ final readonly class AccompanyingPeriodACLAwareRepository implements Accompanyin
}
/**
* Add clause for scope on a query, based on no
* Add clause for scope on a query, based on no.
*
* @param QueryBuilder $qb where the accompanying period have the `ap` alias
* @param QueryBuilder $qb where the accompanying period have the `ap` alias
* @param array<Scope> $scopesCanSee
* @param array<Scope> $scopesCanSeeConfidential
*/
@@ -194,7 +192,7 @@ final readonly class AccompanyingPeriodACLAwareRepository implements Accompanyin
// - and the parcours is not confidential OR the user is the referrer OR the user can see the confidential course
$orOnScope = $qb->expr()->orX(
$qb->expr()->isMemberOf(':scope_' . $key, 'ap.scopes'),
$qb->expr()->isMemberOf(':scope_'.$key, 'ap.scopes'),
$qb->expr()->eq('ap.user', ':user')
);
@@ -211,7 +209,7 @@ final readonly class AccompanyingPeriodACLAwareRepository implements Accompanyin
);
$orx->add($andXOnScope);
}
$qb->setParameter('scope_' . $key, $scope);
$qb->setParameter('scope_'.$key, $scope);
}
$qb->andWhere($orx);
@@ -232,7 +230,7 @@ final readonly class AccompanyingPeriodACLAwareRepository implements Accompanyin
return $centerOnScopes;
}
public function findByUnDispatched(array $jobs, array $services, array $administrativeAdministrativeLocations, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
public function findByUnDispatched(array $jobs, array $services, array $administrativeAdministrativeLocations, array $orderBy = null, int $limit = null, int $offset = null): array
{
$qb = $this->buildQueryUnDispatched($jobs, $services, $administrativeAdministrativeLocations);
$qb->select('ap');
@@ -258,13 +256,13 @@ final readonly class AccompanyingPeriodACLAwareRepository implements Accompanyin
/**
* @param list<array{center: Center, scopeOnRole: list<Scope>, scopeCanSeeConfidential: list<Scope>}> $centerScopes
* @param bool $allowNoCenter if true, will allow to see the periods linked to person which does not have any center. Very few edge case when some Person are not associated to a center.
* @param bool $allowNoCenter if true, will allow to see the periods linked to person which does not have any center. Very few edge case when some Person are not associated to a center.
*/
public function addACLMultiCenterOnQuery(QueryBuilder $qb, array $centerScopes, bool $allowNoCenter = false): QueryBuilder
{
$user = $this->security->getUser();
if (0 === count($centerScopes) || !$user instanceof User) {
if (0 === \count($centerScopes) || !$user instanceof User) {
return $qb->andWhere("'FALSE' = 'TRUE'");
}
@@ -274,27 +272,27 @@ final readonly class AccompanyingPeriodACLAwareRepository implements Accompanyin
foreach ($centerScopes as ['center' => $center, 'scopeOnRole' => $scopes, 'scopeCanSeeConfidential' => $scopesCanSeeConfidential]) {
$and = $qb->expr()->andX(
$qb->expr()->exists(
'SELECT 1 FROM ' . AccompanyingPeriodParticipation::class . " part_{$idx} " .
"JOIN part_{$idx}.person p{$idx} LEFT JOIN p{$idx}.centerCurrent centerCurrent_{$idx} " .
'SELECT 1 FROM '.AccompanyingPeriodParticipation::class." part_{$idx} ".
"JOIN part_{$idx}.person p{$idx} LEFT JOIN p{$idx}.centerCurrent centerCurrent_{$idx} ".
"WHERE part_{$idx}.accompanyingPeriod = ap.id AND (centerCurrent_{$idx}.center = :center_{$idx}"
. ($allowNoCenter ? " OR centerCurrent_{$idx}.id IS NULL)" : ")")
.($allowNoCenter ? " OR centerCurrent_{$idx}.id IS NULL)" : ')')
)
);
$qb->setParameter('center_' . $idx, $center);
$qb->setParameter('center_'.$idx, $center);
$orScopeInsideCenter = $qb->expr()->orX(
// even if the scope is not in one authorized, the user can see the course if it is in DRAFT state
$qb->expr()->eq('ap.step', ':draft')
);
$idx++;
++$idx;
foreach ($scopes as $scope) {
// for each scope:
// - either the user is the referrer of the course
// - or the accompanying course is one of the reachable scopes
// - and the parcours is not confidential OR the user is the referrer OR the user can see the confidential course
$orOnScope = $qb->expr()->orX(
$qb->expr()->isMemberOf(':scope_' . $idx, 'ap.scopes'),
$qb->expr()->isMemberOf(':scope_'.$idx, 'ap.scopes'),
$qb->expr()->eq('ap.user', ':user_executing')
);
$qb->setParameter('user_executing', $user);
@@ -312,23 +310,23 @@ final readonly class AccompanyingPeriodACLAwareRepository implements Accompanyin
);
$orScopeInsideCenter->add($andXOnScope);
}
$qb->setParameter('scope_' . $idx, $scope);
$qb->setParameter('scope_'.$idx, $scope);
$idx++;
++$idx;
}
$and->add($orScopeInsideCenter);
$orX->add($and);
$idx++;
++$idx;
}
return $qb->andWhere($orX);
}
/**
* @param array|UserJob[] $jobs
* @param array|Scope[] $services
* @param array|UserJob[] $jobs
* @param array|Scope[] $services
* @param array|Location[] $locations
*/
public function buildQueryUnDispatched(array $jobs, array $services, array $locations): QueryBuilder
@@ -345,22 +343,22 @@ final readonly class AccompanyingPeriodACLAwareRepository implements Accompanyin
->setParameter('draft', AccompanyingPeriod::STEP_DRAFT)
->setParameter('closed', AccompanyingPeriod::STEP_CLOSED);
if (0 < count($jobs)) {
if (0 < \count($jobs)) {
$qb->andWhere($qb->expr()->in('ap.job', ':jobs'))
->setParameter('jobs', $jobs);
}
if (0 < count($locations)) {
if (0 < \count($locations)) {
$qb->andWhere($qb->expr()->in('ap.administrativeLocation', ':locations'))
->setParameter('locations', $locations);
}
if (0 < count($services)) {
if (0 < \count($services)) {
$or = $qb->expr()->orX();
foreach ($services as $key => $service) {
$or->add($qb->expr()->isMemberOf(':scopef_' . $key, 'ap.scopes'));
$qb->setParameter('scopef_' . $key, $service);
$or->add($qb->expr()->isMemberOf(':scopef_'.$key, 'ap.scopes'));
$qb->setParameter('scopef_'.$key, $service);
}
$qb->andWhere($or);
}