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

@@ -12,10 +12,8 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Repository\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodInfo;
use DateInterval;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use LogicException;
use Symfony\Component\Clock\ClockInterface;
readonly class AccompanyingPeriodInfoRepository implements AccompanyingPeriodInfoRepositoryInterface
@@ -29,14 +27,14 @@ readonly class AccompanyingPeriodInfoRepository implements AccompanyingPeriodInf
$this->entityRepository = $em->getRepository($this->getClassName());
}
public function findAccompanyingPeriodIdInactiveAfter(DateInterval $interval, array $statuses = []): array
public function findAccompanyingPeriodIdInactiveAfter(\DateInterval $interval, array $statuses = []): array
{
$query = $this->em->createQuery();
$baseDql = 'SELECT DISTINCT IDENTITY(ai.accompanyingPeriod) FROM '.AccompanyingPeriodInfo::class.' ai JOIN ai.accompanyingPeriod a WHERE NOT EXISTS
(SELECT 1 FROM ' . AccompanyingPeriodInfo::class . ' aiz WHERE aiz.infoDate > :after AND IDENTITY(aiz.accompanyingPeriod) = IDENTITY(ai.accompanyingPeriod))';
(SELECT 1 FROM '.AccompanyingPeriodInfo::class.' aiz WHERE aiz.infoDate > :after AND IDENTITY(aiz.accompanyingPeriod) = IDENTITY(ai.accompanyingPeriod))';
if ([] !== $statuses) {
$dql = $baseDql . ' AND a.step IN (:statuses)';
$dql = $baseDql.' AND a.step IN (:statuses)';
$query->setParameter('statuses', $statuses);
} else {
$dql = $baseDql;
@@ -47,14 +45,14 @@ readonly class AccompanyingPeriodInfoRepository implements AccompanyingPeriodInf
->getSingleColumnResult();
}
public function findAccompanyingPeriodIdActiveSince(DateInterval $interval, array $statuses = []): array
public function findAccompanyingPeriodIdActiveSince(\DateInterval $interval, array $statuses = []): array
{
$query = $this->em->createQuery();
$baseDql = 'SELECT DISTINCT IDENTITY(ai.accompanyingPeriod) FROM ' . AccompanyingPeriodInfo::class . ' ai
$baseDql = 'SELECT DISTINCT IDENTITY(ai.accompanyingPeriod) FROM '.AccompanyingPeriodInfo::class.' ai
JOIN ai.accompanyingPeriod a WHERE ai.infoDate > :after';
if ([] !== $statuses) {
$dql = $baseDql . ' AND a.step IN (:statuses)';
$dql = $baseDql.' AND a.step IN (:statuses)';
$query->setParameter('statuses', $statuses);
} else {
$dql = $baseDql;
@@ -67,7 +65,7 @@ readonly class AccompanyingPeriodInfoRepository implements AccompanyingPeriodInf
public function find($id): never
{
throw new LogicException("Calling an accompanying period info by his id does not make sense");
throw new \LogicException('Calling an accompanying period info by his id does not make sense');
}
public function findAll(): array
@@ -75,7 +73,7 @@ readonly class AccompanyingPeriodInfoRepository implements AccompanyingPeriodInf
return $this->entityRepository->findAll();
}
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
public function findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): array
{
return $this->entityRepository->findBy($criteria, $orderBy, $limit, $offset);
}

View File

@@ -21,17 +21,17 @@ use Doctrine\Persistence\ObjectRepository;
interface AccompanyingPeriodInfoRepositoryInterface extends ObjectRepository
{
/**
* Return a list of id for inactive accompanying periods
* Return a list of id for inactive accompanying periods.
*
* @param \DateInterval $interval
* @param list<AccompanyingPeriod::STEP_*> $statuses
*
* @return list<int>
*/
public function findAccompanyingPeriodIdInactiveAfter(\DateInterval $interval, array $statuses = []): array;
/**
* @param \DateInterval $interval
* @param list<AccompanyingPeriod::STEP_*> $statuses
*
* @return list<int>
*/
public function findAccompanyingPeriodIdActiveSince(\DateInterval $interval, array $statuses = []): array;

View File

@@ -39,12 +39,12 @@ class AccompanyingPeriodWorkEvaluationDocumentRepository implements ObjectReposi
}
/**
* @param null|mixed $limit
* @param null|mixed $offset
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return array|object[]|AccompanyingPeriodWorkEvaluationDocument[]
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}

View File

@@ -14,7 +14,6 @@ namespace Chill\PersonBundle\Repository\AccompanyingPeriod;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
@@ -54,7 +53,7 @@ class AccompanyingPeriodWorkEvaluationRepository implements ObjectRepository
*
* @return array|AccompanyingPeriodWorkEvaluation[]
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
@@ -93,14 +92,14 @@ class AccompanyingPeriodWorkEvaluationRepository implements ObjectRepository
$qb->expr()->orX(
$qb->expr()->eq('period.user', ':user'),
$qb->expr()->exists(
'SELECT 1 FROM ' . AccompanyingPeriodWork::class . ' subw JOIN subw.referrersHistory subw_ref_history WHERE subw.id = work.id AND subw_ref_history.user = :user'
'SELECT 1 FROM '.AccompanyingPeriodWork::class.' subw JOIN subw.referrersHistory subw_ref_history WHERE subw.id = work.id AND subw_ref_history.user = :user'
)
)
)
)
->setParameters([
'user' => $user,
'now' => new DateTimeImmutable('now'),
'now' => new \DateTimeImmutable('now'),
]);
return $qb;

View File

@@ -15,7 +15,6 @@ use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use DateTimeImmutable;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
@@ -47,13 +46,13 @@ final readonly class AccompanyingPeriodWorkRepository implements ObjectRepositor
->getSingleScalarResult();
}
public function countNearEndDateByUser(User $user, DateTimeImmutable $since, DateTimeImmutable $until): int
public function countNearEndDateByUser(User $user, \DateTimeImmutable $since, \DateTimeImmutable $until): int
{
return $this->buildQueryNearEndDateByUser($user, $since, $until)
->select('count(w)')->getQuery()->getSingleScalarResult();
}
public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder
public function createQueryBuilder(string $alias, string $indexBy = null): QueryBuilder
{
return $this->repository->createQueryBuilder($alias, $indexBy);
}
@@ -68,7 +67,7 @@ final readonly class AccompanyingPeriodWorkRepository implements ObjectRepositor
return $this->repository->findAll();
}
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
@@ -91,8 +90,9 @@ final readonly class AccompanyingPeriodWorkRepository implements ObjectRepositor
* * first, opened works
* * then, closed works
*
* @param array{types?: list<SocialAction>, user?: list<User>, after?: \DateTimeImmutable|null, before?: \DateTimeImmutable|null} $filters
*
* @return AccompanyingPeriodWork[]
* @param array{types?: list<SocialAction>, user?: list<User>, after?: null|\DateTimeImmutable, before?: null|\DateTimeImmutable} $filters
*/
public function findByAccompanyingPeriodOpenFirst(AccompanyingPeriod $period, array $filters, int $limit = 10, int $offset = 0): array
{
@@ -106,23 +106,23 @@ final readonly class AccompanyingPeriodWorkRepository implements ObjectRepositor
// implement filters
if ([] !== ($filters['types'] ?? [])) {
$sql .= " AND w.socialaction_id IN (:types)";
$sql .= ' AND w.socialaction_id IN (:types)';
}
if ([] !== ($filters['user'] ?? [])) {
$sql .= " AND rw.user_id IN ("
. implode(
$sql .= ' AND rw.user_id IN ('
.implode(
', ',
// we add a user_xx for each key of the 'user' list
array_map(fn (User $u, int $idx) => ':user_' . $idx, $filters['user'], array_keys($filters['user']))
array_map(fn (User $u, int $idx) => ':user_'.$idx, $filters['user'], array_keys($filters['user']))
)
. ")";
.')';
}
$sql .= " AND daterange(:after::date, :before::date) && daterange(w.startDate, w.endDate, '[]')";
// if the start and end date were inversed, we inverse the order to avoid an error
if (null !== ($filters['after'] ?? null) && null !== ($filters['before']) && $filters['after'] > $filters['before']) {
if (null !== ($filters['after'] ?? null) && null !== $filters['before'] && $filters['after'] > $filters['before']) {
$before = $filters['after'];
$after = $filters['before'];
} else {
@@ -137,7 +137,7 @@ final readonly class AccompanyingPeriodWorkRepository implements ObjectRepositor
w.enddate DESC,
w.id DESC";
$sql .= " LIMIT :limit OFFSET :offset";
$sql .= ' LIMIT :limit OFFSET :offset';
$typeIds = [];
foreach ($filters['types'] as $type) {
@@ -153,14 +153,14 @@ final readonly class AccompanyingPeriodWorkRepository implements ObjectRepositor
->setParameter('offset', $offset, Types::INTEGER);
foreach ($filters['user'] as $key => $user) {
$nq->setParameter('user_' . $key, $user);
$nq->setParameter('user_'.$key, $user);
}
return $nq->getResult();
}
/**
* Return a list of types of social actions associated to the accompanying period
* Return a list of types of social actions associated to the accompanying period.
*
* @return array<SocialAction>
*/
@@ -171,10 +171,8 @@ final readonly class AccompanyingPeriodWorkRepository implements ObjectRepositor
->select('1')
->from(AccompanyingPeriodWork::class, 'apw');
$in->andWhere('apw.accompanyingPeriod = :period')->setParameter('period', $period);
// join between the embedded exist query and the main query
$in->andWhere('apw.socialAction = sa');
@@ -189,7 +187,7 @@ final readonly class AccompanyingPeriodWorkRepository implements ObjectRepositor
return $qb->getQuery()->getResult();
}
public function findNearEndDateByUser(User $user, DateTimeImmutable $since, DateTimeImmutable $until, int $limit = 20, int $offset = 0): array
public function findNearEndDateByUser(User $user, \DateTimeImmutable $since, \DateTimeImmutable $until, int $limit = 20, int $offset = 0): array
{
return $this->buildQueryNearEndDateByUser($user, $since, $until)
->select('w')
@@ -227,7 +225,7 @@ final readonly class AccompanyingPeriodWorkRepository implements ObjectRepositor
return $qb;
}
private function buildQueryNearEndDateByUser(User $user, DateTimeImmutable $since, DateTimeImmutable $until): QueryBuilder
private function buildQueryNearEndDateByUser(User $user, \DateTimeImmutable $since, \DateTimeImmutable $until): QueryBuilder
{
$qb = $this->repository->createQueryBuilder('w');
@@ -240,7 +238,7 @@ final readonly class AccompanyingPeriodWorkRepository implements ObjectRepositor
$qb->expr()->orX(
$qb->expr()->eq('period.user', ':user'),
$qb->expr()->exists(
'SELECT 1 FROM ' . AccompanyingPeriodWork::class . ' subw JOIN subw.referrersHistory subw_ref_history WHERE subw.id = w.id AND subw_ref_history.user = :user and subw.ref_history.endDate IS NULL'
'SELECT 1 FROM '.AccompanyingPeriodWork::class.' subw JOIN subw.referrersHistory subw_ref_history WHERE subw.id = w.id AND subw_ref_history.user = :user and subw.ref_history.endDate IS NULL'
)
)
)

View File

@@ -41,7 +41,7 @@ final readonly class ClosingMotiveRepository implements ClosingMotiveRepositoryI
/**
* @return array|ClosingMotive[]
*/
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
public function findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
@@ -51,15 +51,12 @@ final readonly class ClosingMotiveRepository implements ClosingMotiveRepositoryI
return $this->findOneBy($criteria);
}
/**
* @return mixed
*/
public function getActiveClosingMotive(bool $onlyLeaf = true)
{
$rsm = new ResultSetMappingBuilder($this->entityManager);
$rsm->addRootEntityFromClassMetadata($this->repository->getClassName(), 'cm');
$sql = 'SELECT ' . (string) $rsm . '
$sql = 'SELECT '.(string) $rsm.'
FROM chill_person_accompanying_period_closingmotive AS cm
WHERE
active IS TRUE ';

View File

@@ -15,8 +15,5 @@ use Doctrine\Persistence\ObjectRepository;
interface ClosingMotiveRepositoryInterface extends ObjectRepository
{
/**
* @return mixed
*/
public function getActiveClosingMotive(bool $onlyLeaf = true);
}

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);
}

View File

@@ -22,8 +22,8 @@ use Chill\PersonBundle\Entity\Person;
interface AccompanyingPeriodACLAwareRepositoryInterface
{
/**
* @param array|UserJob[] $jobs
* @param array|Scope[] $services
* @param array|UserJob[] $jobs
* @param array|Scope[] $services
* @param array|Location[] $administrativeLocations
*/
public function countByUnDispatched(array $jobs, array $services, array $administrativeLocations): int;
@@ -40,20 +40,22 @@ interface AccompanyingPeriodACLAwareRepositoryInterface
Person $person,
string $role,
?array $orderBy = [],
?int $limit = null,
?int $offset = null
int $limit = null,
int $offset = null
): array;
/**
* @param array|UserJob[] $jobs if empty, does not take this argument into account
* @param array|Scope[] $services if empty, does not take this argument into account
* @param array|UserJob[] $jobs if empty, does not take this argument into account
* @param array|Scope[] $services if empty, does not take this argument into account
* @param array|Location[] $administrativeLocations
*
* @return list<AccompanyingPeriod>
*/
public function findByUnDispatched(array $jobs, array $services, array $administrativeLocations, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array;
public function findByUnDispatched(array $jobs, array $services, array $administrativeLocations, array $orderBy = null, int $limit = null, int $offset = null): array;
/**
* @param array|PostalCode[] $postalCodes
*
* @return list<AccompanyingPeriod>
*/
public function findByUserAndPostalCodesOpenedAccompanyingPeriod(?User $user, array $postalCodes, array $orderBy = [], int $limit = 0, int $offset = 50): array;

View File

@@ -13,7 +13,6 @@ namespace Chill\PersonBundle\Repository;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
@@ -33,14 +32,14 @@ final class AccompanyingPeriodRepository implements ObjectRepository
return $this->repository->count($criteria);
}
public function countByRecentUserHistory(User $user, DateTimeImmutable $since): int
public function countByRecentUserHistory(User $user, \DateTimeImmutable $since): int
{
$qb = $this->buildQueryByRecentUserHistory($user, $since);
return $qb->select('count(a)')->getQuery()->getSingleScalarResult();
}
public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder
public function createQueryBuilder(string $alias, string $indexBy = null): QueryBuilder
{
return $this->repository->createQueryBuilder($alias, $indexBy);
}
@@ -58,7 +57,7 @@ final class AccompanyingPeriodRepository implements ObjectRepository
return $this->repository->findAll();
}
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
@@ -66,7 +65,7 @@ final class AccompanyingPeriodRepository implements ObjectRepository
/**
* @return array|AccompanyingPeriod[]
*/
public function findByRecentUserHistory(User $user, DateTimeImmutable $since, ?int $limit = 20, ?int $offset = 0): array
public function findByRecentUserHistory(User $user, \DateTimeImmutable $since, ?int $limit = 20, ?int $offset = 0): array
{
$qb = $this->buildQueryByRecentUserHistory($user, $since);
@@ -98,14 +97,14 @@ final class AccompanyingPeriodRepository implements ObjectRepository
return AccompanyingPeriod::class;
}
private function buildQueryByRecentUserHistory(User $user, DateTimeImmutable $since): QueryBuilder
private function buildQueryByRecentUserHistory(User $user, \DateTimeImmutable $since): QueryBuilder
{
$qb = $this->repository->createQueryBuilder('a');
$qb
->join('a.userHistories', 'userHistory')
->where($qb->expr()->eq('a.user', ':user'))
->andWhere($qb->expr()->neq('a.step', "'" . AccompanyingPeriod::STEP_DRAFT . "'"))
->andWhere($qb->expr()->neq('a.step', "'".AccompanyingPeriod::STEP_DRAFT."'"))
->andWhere($qb->expr()->gte('userHistory.startDate', ':since'))
->andWhere($qb->expr()->isNull('userHistory.endDate'))
->setParameter('user', $user)

View File

@@ -15,7 +15,6 @@ use Chill\MainBundle\Entity\AddressReference;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Security\Core\Security;
@@ -37,7 +36,7 @@ final readonly class HouseholdACLAwareRepository implements HouseholdACLAwareRep
}
$qb
->join($alias . '.members', 'members')
->join($alias.'.members', 'members')
->join('members.person', 'person')
->join('person.centerCurrent', 'person_center_current')
->andWhere(
@@ -68,7 +67,7 @@ final readonly class HouseholdACLAwareRepository implements HouseholdACLAwareRep
)
)
)
->setParameter('today', new DateTime('today'));
->setParameter('today', new \DateTime('today'));
return $qb;
}

View File

@@ -49,7 +49,7 @@ final class HouseholdCompositionRepository implements HouseholdCompositionReposi
*
* @return array|object[]|HouseholdComposition[]
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
@@ -57,7 +57,7 @@ final class HouseholdCompositionRepository implements HouseholdCompositionReposi
/**
* @return array|HouseholdComposition[]|object[]
*/
public function findByHousehold(Household $household, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
public function findByHousehold(Household $household, array $orderBy = null, int $limit = null, int $offset = null): array
{
return $this->findBy(['household' => $household], $orderBy, $limit, $offset);
}

View File

@@ -32,12 +32,12 @@ interface HouseholdCompositionRepositoryInterface extends ObjectRepository
*
* @return array|object[]|HouseholdComposition[]
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array;
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array;
/**
* @return array|HouseholdComposition[]|object[]
*/
public function findByHousehold(Household $household, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array;
public function findByHousehold(Household $household, array $orderBy = null, int $limit = null, int $offset = null): array;
public function findOneBy(array $criteria): ?HouseholdComposition;

View File

@@ -46,12 +46,12 @@ final class HouseholdCompositionTypeRepository implements HouseholdCompositionTy
}
/**
* @param $limit
* @param $offset
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return array|HouseholdCompositionType[]|object[]
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}

View File

@@ -29,12 +29,12 @@ interface HouseholdCompositionTypeRepositoryInterface extends ObjectRepository
public function findAllActive(): array;
/**
* @param $limit
* @param $offset
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return array|HouseholdCompositionType[]|object[]
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array;
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array;
public function findOneBy(array $criteria): ?HouseholdCompositionType;

View File

@@ -18,8 +18,6 @@ use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
use Doctrine\Persistence\ObjectRepository;
use function strtr;
final class HouseholdRepository implements ObjectRepository
{
private const SQL_BY_ACCOMPANYING_PERIOD_PARTICIPATION = <<<'SQL'
@@ -67,7 +65,7 @@ final class HouseholdRepository implements ObjectRepository
return $this->repository->findAll();
}
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null)
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
@@ -94,12 +92,12 @@ final class HouseholdRepository implements ObjectRepository
if ($isCount) {
$rsm->addScalarResult('count', 'count');
$sql = strtr(self::SQL_BY_ACCOMPANYING_PERIOD_PARTICIPATION, [
$sql = \strtr(self::SQL_BY_ACCOMPANYING_PERIOD_PARTICIPATION, [
'{select}' => 'COUNT(households.*) AS count',
'{limits}' => '',
]);
} else {
$sql = strtr(self::SQL_BY_ACCOMPANYING_PERIOD_PARTICIPATION, [
$sql = \strtr(self::SQL_BY_ACCOMPANYING_PERIOD_PARTICIPATION, [
'{select}' => $rsm->generateSelectClause(['h' => 'households']),
'{limits}' => "OFFSET {$offset} LIMIT {$limit}",
]);

View File

@@ -44,12 +44,12 @@ final class PersonHouseholdAddressRepository implements ObjectRepository
*
* @return PersonHouseholdAddress[]
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function findOneBy(array $criteria, ?array $orderBy = null): ?PersonHouseholdAddress
public function findOneBy(array $criteria, array $orderBy = null): ?PersonHouseholdAddress
{
return $this->repository->findOneBy($criteria, $orderBy);
}

View File

@@ -12,8 +12,8 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Repository\Household;
use Chill\PersonBundle\Entity\Household\Position;
//use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
//use Doctrine\Persistence\ManagerRegistry;
// use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
// use Doctrine\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\Persistence\ObjectRepository;
@@ -28,8 +28,6 @@ final class PositionRepository implements ObjectRepository
}
/**
* @param mixed $id
*
* @return Position
*/
public function find($id)
@@ -51,7 +49,7 @@ final class PositionRepository implements ObjectRepository
*
* @return Position[]
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}

View File

@@ -34,7 +34,7 @@ class MaritalStatusRepository implements MaritalStatusRepositoryInterface
return $this->repository->findAll();
}
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}

View File

@@ -19,7 +19,7 @@ interface MaritalStatusRepositoryInterface
public function findAll(): array;
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array;
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array;
public function findOneBy(array $criteria): ?MaritalStatus;

View File

@@ -40,7 +40,7 @@ class PersonCenterHistoryRepository implements PersonCenterHistoryInterface
/**
* @return array|PersonCenterHistory[]
*/
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
public function findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}

View File

@@ -18,35 +18,26 @@ use Chill\MainBundle\Search\SearchApiQuery;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use DateTimeInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\Query;
use Symfony\Component\Security\Core\Security;
use function array_fill;
use function array_map;
use function array_merge;
use function array_push;
use function count;
use function explode;
use function implode;
final readonly class PersonACLAwareRepository implements PersonACLAwareRepositoryInterface
{
public function __construct(private Security $security, private EntityManagerInterface $em, private CountryRepository $countryRepository, private AuthorizationHelperInterface $authorizationHelper) {}
public function buildAuthorizedQuery(
?string $default = null,
?string $firstname = null,
?string $lastname = null,
?DateTimeInterface $birthdate = null,
?DateTimeInterface $birthdateBefore = null,
?DateTimeInterface $birthdateAfter = null,
?string $gender = null,
?string $countryCode = null,
?string $phonenumber = null,
?string $city = null
string $default = null,
string $firstname = null,
string $lastname = null,
\DateTimeInterface $birthdate = null,
\DateTimeInterface $birthdateBefore = null,
\DateTimeInterface $birthdateAfter = null,
string $gender = null,
string $countryCode = null,
string $phonenumber = null,
string $city = null
): SearchApiQuery {
$query = $this->createSearchQuery(
$default,
@@ -65,16 +56,16 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
}
public function countBySearchCriteria(
?string $default = null,
?string $firstname = null,
?string $lastname = null,
?DateTimeInterface $birthdate = null,
?DateTimeInterface $birthdateBefore = null,
?DateTimeInterface $birthdateAfter = null,
?string $gender = null,
?string $countryCode = null,
?string $phonenumber = null,
?string $city = null
string $default = null,
string $firstname = null,
string $lastname = null,
\DateTimeInterface $birthdate = null,
\DateTimeInterface $birthdateBefore = null,
\DateTimeInterface $birthdateAfter = null,
string $gender = null,
string $countryCode = null,
string $phonenumber = null,
string $city = null
): int {
$query = $this->buildAuthorizedQuery(
$default,
@@ -99,16 +90,16 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
* @throws ParsingException
*/
public function createSearchQuery(
?string $default = null,
?string $firstname = null,
?string $lastname = null,
?DateTimeInterface $birthdate = null,
?DateTimeInterface $birthdateBefore = null,
?DateTimeInterface $birthdateAfter = null,
?string $gender = null,
?string $countryCode = null,
?string $phonenumber = null,
?string $city = null
string $default = null,
string $firstname = null,
string $lastname = null,
\DateTimeInterface $birthdate = null,
\DateTimeInterface $birthdateBefore = null,
\DateTimeInterface $birthdateAfter = null,
string $gender = null,
string $countryCode = null,
string $phonenumber = null,
string $city = null
): SearchApiQuery {
$query = new SearchApiQuery();
$query
@@ -120,25 +111,25 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
$andWhereSearchClauseArgs = [];
if ('' !== trim($default)) {
foreach (explode(' ', $default) as $str) {
foreach (\explode(' ', $default) as $str) {
if ('' === trim($str)) {
continue;
}
$pertinence[] =
'STRICT_WORD_SIMILARITY(LOWER(UNACCENT(?)), person.fullnamecanonical) + ' .
"(person.fullnamecanonical LIKE '%' || LOWER(UNACCENT(?)) || '%')::int + " .
"(EXISTS (SELECT 1 FROM unnest(string_to_array(fullnamecanonical, ' ')) AS t WHERE starts_with(t, UNACCENT(LOWER(?)))))::int + " .
'STRICT_WORD_SIMILARITY(LOWER(UNACCENT(?)), person.fullnamecanonical) + '.
"(person.fullnamecanonical LIKE '%' || LOWER(UNACCENT(?)) || '%')::int + ".
"(EXISTS (SELECT 1 FROM unnest(string_to_array(fullnamecanonical, ' ')) AS t WHERE starts_with(t, UNACCENT(LOWER(?)))))::int + ".
'(starts_with(LOWER(UNACCENT(lastname)), UNACCENT(LOWER(?))))::int';
array_push($pertinenceArgs, $str, $str, $str, $str);
\array_push($pertinenceArgs, $str, $str, $str, $str);
$andWhereSearchClause[] =
'(LOWER(UNACCENT(?)) <<% person.fullnamecanonical OR ' .
'(LOWER(UNACCENT(?)) <<% person.fullnamecanonical OR '.
"person.fullnamecanonical LIKE '%' || LOWER(UNACCENT(?)) || '%' )";
array_push($andWhereSearchClauseArgs, $str, $str);
\array_push($andWhereSearchClauseArgs, $str, $str);
}
$query->andWhereClause(
implode(' AND ', $andWhereSearchClause),
\implode(' AND ', $andWhereSearchClause),
$andWhereSearchClauseArgs
);
} else {
@@ -146,7 +137,7 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
$pertinenceArgs = [];
}
$query
->setSelectPertinence(implode(' + ', $pertinence), $pertinenceArgs);
->setSelectPertinence(\implode(' + ', $pertinence), $pertinenceArgs);
if (null !== $birthdate) {
$query->andWhereClause(
@@ -188,16 +179,16 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
"person.phonenumber LIKE '%' || ? || '%' OR person.mobilenumber LIKE '%' || ? || '%' OR pp.phonenumber LIKE '%' || ? || '%'",
[$phonenumber, $phonenumber, $phonenumber]
);
$query->setFromClause($query->getFromClause() . ' LEFT JOIN chill_person_phone pp ON pp.person_id = person.id');
$query->setFromClause($query->getFromClause().' LEFT JOIN chill_person_phone pp ON pp.person_id = person.id');
}
if (null !== $city) {
$query->setFromClause($query->getFromClause() . ' ' .
'JOIN view_chill_person_current_address vcpca ON vcpca.person_id = person.id ' .
'JOIN chill_main_address cma ON vcpca.address_id = cma.id ' .
$query->setFromClause($query->getFromClause().' '.
'JOIN view_chill_person_current_address vcpca ON vcpca.person_id = person.id '.
'JOIN chill_main_address cma ON vcpca.address_id = cma.id '.
'JOIN chill_main_postal_code cmpc ON cma.postcode_id = cmpc.id');
foreach (explode(' ', $city) as $cityStr) {
foreach (\explode(' ', $city) as $cityStr) {
$query->andWhereClause(
"(UNACCENT(LOWER(cmpc.label)) LIKE '%' || UNACCENT(LOWER(?)) || '%' OR cmpc.code LIKE '%' || UNACCENT(LOWER(?)) || '%')",
[$cityStr, $city]
@@ -206,7 +197,7 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
}
if (null !== $countryCode) {
$query->setFromClause($query->getFromClause() . ' JOIN country ON person.nationality_id = country.id');
$query->setFromClause($query->getFromClause().' JOIN country ON person.nationality_id = country.id');
$query->andWhereClause('country.countrycode = UPPER(?)', [$countryCode]);
}
@@ -239,33 +230,33 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
$query->addSelectClause($rsm->generateSelectClause());
$nql = $this->em->createNativeQuery(
$query->buildQuery() . ' ORDER BY pertinence DESC OFFSET ? LIMIT ?',
$query->buildQuery().' ORDER BY pertinence DESC OFFSET ? LIMIT ?',
$rsm
)->setParameters(array_merge($query->buildParameters(), [$start, $limit]));
)->setParameters(\array_merge($query->buildParameters(), [$start, $limit]));
return $nql->getResult();
}
/**
* @return array|Person[]
*
* @throws NonUniqueResultException
* @throws ParsingException
*
* @return array|Person[]
*/
public function findBySearchCriteria(
int $start,
int $limit,
bool $simplify = false,
?string $default = null,
?string $firstname = null,
?string $lastname = null,
?DateTimeInterface $birthdate = null,
?DateTimeInterface $birthdateBefore = null,
?DateTimeInterface $birthdateAfter = null,
?string $gender = null,
?string $countryCode = null,
?string $phonenumber = null,
?string $city = null
string $default = null,
string $firstname = null,
string $lastname = null,
\DateTimeInterface $birthdate = null,
\DateTimeInterface $birthdateBefore = null,
\DateTimeInterface $birthdateAfter = null,
string $gender = null,
string $countryCode = null,
string $phonenumber = null,
string $city = null
): array {
$query = $this->buildAuthorizedQuery(
$default,
@@ -293,18 +284,18 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
}
return $query
->setFromClause($query->getFromClause() . ' JOIN view_chill_person_person_center_history_current vcppchc ON vcppchc.person_id = person.id', $query->getFromParams())
->setFromClause($query->getFromClause().' JOIN view_chill_person_person_center_history_current vcppchc ON vcppchc.person_id = person.id', $query->getFromParams())
->andWhereClause(
strtr(
'vcppchc.center_id IN ({{ center_ids }})',
[
'{{ center_ids }}' => implode(
'{{ center_ids }}' => \implode(
', ',
array_fill(0, count($authorizedCenters), '?')
\array_fill(0, \count($authorizedCenters), '?')
),
]
),
array_map(static fn (Center $c) => $c->getId(), $authorizedCenters)
\array_map(static fn (Center $c) => $c->getId(), $authorizedCenters)
);
}
}

View File

@@ -13,34 +13,33 @@ namespace Chill\PersonBundle\Repository;
use Chill\MainBundle\Search\SearchApiQuery;
use Chill\PersonBundle\Entity\Person;
use DateTimeInterface;
interface PersonACLAwareRepositoryInterface
{
public function buildAuthorizedQuery(
?string $default = null,
?string $firstname = null,
?string $lastname = null,
?DateTimeInterface $birthdate = null,
?DateTimeInterface $birthdateBefore = null,
?DateTimeInterface $birthdateAfter = null,
?string $gender = null,
?string $countryCode = null,
?string $phonenumber = null,
?string $city = null
string $default = null,
string $firstname = null,
string $lastname = null,
\DateTimeInterface $birthdate = null,
\DateTimeInterface $birthdateBefore = null,
\DateTimeInterface $birthdateAfter = null,
string $gender = null,
string $countryCode = null,
string $phonenumber = null,
string $city = null
): SearchApiQuery;
public function countBySearchCriteria(
?string $default = null,
?string $firstname = null,
?string $lastname = null,
?DateTimeInterface $birthdate = null,
?DateTimeInterface $birthdateBefore = null,
?DateTimeInterface $birthdateAfter = null,
?string $gender = null,
?string $countryCode = null,
?string $phonenumber = null,
?string $city = null
string $default = null,
string $firstname = null,
string $lastname = null,
\DateTimeInterface $birthdate = null,
\DateTimeInterface $birthdateBefore = null,
\DateTimeInterface $birthdateAfter = null,
string $gender = null,
string $countryCode = null,
string $phonenumber = null,
string $city = null
);
/**
@@ -50,15 +49,15 @@ interface PersonACLAwareRepositoryInterface
int $start,
int $limit,
bool $simplify = false,
?string $default = null,
?string $firstname = null,
?string $lastname = null,
?DateTimeInterface $birthdate = null,
?DateTimeInterface $birthdateBefore = null,
?DateTimeInterface $birthdateAfter = null,
?string $gender = null,
?string $countryCode = null,
?string $phonenumber = null,
?string $city = null
string $default = null,
string $firstname = null,
string $lastname = null,
\DateTimeInterface $birthdate = null,
\DateTimeInterface $birthdateBefore = null,
\DateTimeInterface $birthdateAfter = null,
string $gender = null,
string $countryCode = null,
string $phonenumber = null,
string $city = null
): array;
}

View File

@@ -16,11 +16,6 @@ use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ObjectRepository;
use Exception;
use function count;
use function in_array;
use function str_replace;
class PersonRepository implements ObjectRepository
{
@@ -32,8 +27,6 @@ class PersonRepository implements ObjectRepository
}
/**
* @param $centers
*
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
*/
@@ -51,7 +44,7 @@ class PersonRepository implements ObjectRepository
return $qb->getQuery()->getSingleScalarResult();
}
public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder
public function createQueryBuilder(string $alias, string $indexBy = null): QueryBuilder
{
return $this->repository->createQueryBuilder($alias, $indexBy);
}
@@ -66,7 +59,7 @@ class PersonRepository implements ObjectRepository
return $this->repository->findAll();
}
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null)
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
@@ -77,13 +70,7 @@ class PersonRepository implements ObjectRepository
}
/**
* @param $centers
* @param $firstResult
* @param $maxResults
*
* @throws Exception
*
* @return mixed
* @throws \Exception
*/
public function findByPhone(
string $phonenumber,
@@ -116,43 +103,40 @@ class PersonRepository implements ObjectRepository
private function addByCenters(QueryBuilder $qb, array $centers): void
{
if (count($centers) > 0) {
if (\count($centers) > 0) {
$qb->andWhere($qb->expr()->in('p.center', ':centers'));
$qb->setParameter('centers', $centers);
}
}
/**
* @throws Exception
* @throws \Exception
*/
private function addPhoneNumber(QueryBuilder $qb, string $phonenumber, array $only): void
{
if (count($only) === 0) {
throw new Exception('No array field to search');
if (0 === \count($only)) {
throw new \Exception('No array field to search');
}
$phonenumber = $this->parsePhoneNumber($phonenumber);
$orX = $qb->expr()->orX();
if (in_array('mobile', $only, true)) {
if (\in_array('mobile', $only, true)) {
$orX->add($qb->expr()->like("REPLACE(p.mobilenumber, ' ', '')", ':phonenumber'));
}
if (in_array('phone', $only, true)) {
if (\in_array('phone', $only, true)) {
$orX->add($qb->expr()->like("REPLACE(p.phonenumber, ' ', '')", ':phonenumber'));
}
$qb->andWhere($orX);
$qb->setParameter('phonenumber', '%' . $phonenumber . '%');
$qb->setParameter('phonenumber', '%'.$phonenumber.'%');
}
/**
* @param $phonenumber
*/
private function parsePhoneNumber(string $phonenumber): string
{
return str_replace(' ', '', $phonenumber);
return \str_replace(' ', '', $phonenumber);
}
}

View File

@@ -44,7 +44,7 @@ final class PersonResourceRepository implements ObjectRepository
*
* @return PersonResource[]
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}

View File

@@ -35,7 +35,7 @@ class RelationRepository implements ObjectRepository
return $this->repository->findAll();
}
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}

View File

@@ -48,7 +48,7 @@ class RelationshipRepository implements ObjectRepository
return $this->repository->findAll();
}
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}

View File

@@ -13,7 +13,6 @@ namespace Chill\PersonBundle\Repository;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\Person\ResidentialAddress;
use DateTimeImmutable;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\QueryBuilder;
@@ -42,9 +41,9 @@ class ResidentialAddressRepository extends ServiceEntityRepository
->getSingleScalarResult();
}
public function buildQueryFindCurrentResidentialAddresses(Person $person, ?DateTimeImmutable $at = null): QueryBuilder
public function buildQueryFindCurrentResidentialAddresses(Person $person, \DateTimeImmutable $at = null): QueryBuilder
{
$date = $at ?? new DateTimeImmutable('today');
$date = $at ?? new \DateTimeImmutable('today');
$qb = $this->createQueryBuilder('ra');
$dateFilter = $qb->expr()->andX(
@@ -67,7 +66,7 @@ class ResidentialAddressRepository extends ServiceEntityRepository
/**
* @return array|ResidentialAddress[]|null
*/
public function findCurrentResidentialAddressByPerson(Person $person, ?DateTimeImmutable $at = null): array
public function findCurrentResidentialAddressByPerson(Person $person, \DateTimeImmutable $at = null): array
{
return $this->buildQueryFindCurrentResidentialAddresses($person, $at)
->select('ra')

View File

@@ -48,12 +48,12 @@ final class EvaluationRepository implements EvaluationRepositoryInterface
*
* @return array<int, Evaluation>
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function findOneBy(array $criteria, ?array $orderBy = null): ?Evaluation
public function findOneBy(array $criteria, array $orderBy = null): ?Evaluation
{
return $this->repository->findOneBy($criteria, $orderBy);
}

View File

@@ -34,9 +34,9 @@ interface EvaluationRepositoryInterface extends ObjectRepository
*
* @return array<int, Evaluation>
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array;
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array;
public function findOneBy(array $criteria, ?array $orderBy = null): ?Evaluation;
public function findOneBy(array $criteria, array $orderBy = null): ?Evaluation;
/**
* @return class-string

View File

@@ -13,7 +13,6 @@ namespace Chill\PersonBundle\Repository\SocialWork;
use Chill\PersonBundle\Entity\SocialWork\Goal;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
@@ -57,7 +56,7 @@ final class GoalRepository implements ObjectRepository
*
* @return array<int, Goal>
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
@@ -65,7 +64,7 @@ final class GoalRepository implements ObjectRepository
/**
* @return Goal[]
*/
public function findBySocialActionWithDescendants(SocialAction $action, array $orderBy = [], ?int $limit = null, ?int $offset = null): array
public function findBySocialActionWithDescendants(SocialAction $action, array $orderBy = [], int $limit = null, int $offset = null): array
{
$qb = $this->buildQueryBySocialActionWithDescendants($action);
$qb->select('g');
@@ -76,10 +75,10 @@ final class GoalRepository implements ObjectRepository
$qb->expr()->gt('g.desactivationDate', ':now')
)
)
->setParameter('now', new DateTime('now'));
->setParameter('now', new \DateTime('now'));
foreach ($orderBy as $sort => $order) {
$qb->addOrderBy('g.' . $sort, $order);
$qb->addOrderBy('g.'.$sort, $order);
}
return $qb
@@ -89,7 +88,7 @@ final class GoalRepository implements ObjectRepository
->getResult();
}
public function findOneBy(array $criteria, ?array $orderBy = null): ?Goal
public function findOneBy(array $criteria, array $orderBy = null): ?Goal
{
return $this->repository->findOneBy($criteria, $orderBy);
}

View File

@@ -67,7 +67,7 @@ final class ResultRepository implements ObjectRepository
*
* @return array<int, Result>
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
@@ -75,13 +75,13 @@ final class ResultRepository implements ObjectRepository
/**
* @return array<Result>
*/
public function findByGoal(Goal $goal, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
public function findByGoal(Goal $goal, array $orderBy = null, int $limit = null, int $offset = null): array
{
$qb = $this->buildQueryByGoal($goal);
if (null !== $orderBy) {
foreach ($orderBy as $sort => $order) {
$qb->addOrderBy('r.' . $sort, $order);
$qb->addOrderBy('r.'.$sort, $order);
}
}
@@ -96,13 +96,13 @@ final class ResultRepository implements ObjectRepository
/**
* @return Result[]
*/
public function findBySocialActionWithDescendants(SocialAction $action, array $orderBy = [], ?int $limit = null, ?int $offset = null): array
public function findBySocialActionWithDescendants(SocialAction $action, array $orderBy = [], int $limit = null, int $offset = null): array
{
$qb = $this->buildQueryBySocialActionWithDescendants($action);
$qb->select('r');
foreach ($orderBy as $sort => $order) {
$qb->addOrderBy('r.' . $sort, $order);
$qb->addOrderBy('r.'.$sort, $order);
}
return $qb
@@ -112,7 +112,7 @@ final class ResultRepository implements ObjectRepository
->getResult();
}
public function findOneBy(array $criteria, ?array $orderBy = null): ?Result
public function findOneBy(array $criteria, array $orderBy = null): ?Result
{
return $this->repository->findOneBy($criteria, $orderBy);
}

View File

@@ -12,7 +12,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Repository\SocialWork;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
@@ -27,7 +26,7 @@ final class SocialActionRepository implements ObjectRepository
$this->repository = $entityManager->getRepository(SocialAction::class);
}
public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder
public function createQueryBuilder(string $alias, string $indexBy = null): QueryBuilder
{
return $this->repository->createQueryBuilder($alias, $indexBy);
}
@@ -59,12 +58,12 @@ final class SocialActionRepository implements ObjectRepository
*
* @return array<int, SocialAction>
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function findOneBy(array $criteria, ?array $orderBy = null): ?SocialAction
public function findOneBy(array $criteria, array $orderBy = null): ?SocialAction
{
return $this->repository->findOneBy($criteria, $orderBy);
}
@@ -84,7 +83,7 @@ final class SocialActionRepository implements ObjectRepository
$qb->where('sa.desactivationDate is null')
->orWhere('sa.desactivationDate > :now')
->orderBy('sa.ordering', 'ASC')
->setParameter('now', new DateTime('now'));
->setParameter('now', new \DateTime('now'));
return $qb;
}

View File

@@ -12,7 +12,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Repository\SocialWork;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
@@ -54,12 +53,12 @@ final class SocialIssueRepository implements ObjectRepository
*
* @return array<int, SocialIssue>
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function findOneBy(array $criteria, ?array $orderBy = null): ?SocialIssue
public function findOneBy(array $criteria, array $orderBy = null): ?SocialIssue
{
return $this->repository->findOneBy($criteria, $orderBy);
}
@@ -79,7 +78,7 @@ final class SocialIssueRepository implements ObjectRepository
$qb->where('si.desactivationDate is null')
->orWhere('si.desactivationDate > :now')
->orderBy('si.ordering', 'ASC')
->setParameter('now', new DateTime('now'));
->setParameter('now', new \DateTime('now'));
return $qb;
}