cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Repository;
@@ -13,42 +20,16 @@ use Doctrine\Persistence\ObjectRepository;
final class UserRepository implements ObjectRepository
{
private EntityRepository $repository;
private EntityManagerInterface $entityManager;
private EntityRepository $repository;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
$this->repository = $entityManager->getRepository(User::class);
}
public function find($id, $lockMode = null, $lockVersion = null): ?User
{
return $this->repository->find($id, $lockMode, $lockVersion);
}
public function findOneBy(array $criteria, array $orderBy = null): ?User
{
return $this->repository->findOneBy($criteria, $orderBy);
}
/**
* @return User[]
*/
public function findAll(): array
{
return $this->repository->findAll();
}
/**
* @return User[]
*/
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function countBy(array $criteria): int
{
return $this->repository->count($criteria);
@@ -59,18 +40,6 @@ final class UserRepository implements ObjectRepository
return $this->countBy(['enabled' => true]);
}
/**
* @return User[]|array
*/
public function findByActive(array $orderBy = null, int $limit = null, int $offset = null): array
{
return $this->findBy(['enabled' => true], $orderBy, $limit, $offset);
}
public function getClassName() {
return User::class;
}
public function countByUsernameOrEmail(string $pattern): int
{
$qb = $this->queryByUsernameOrEmail($pattern);
@@ -80,6 +49,38 @@ final class UserRepository implements ObjectRepository
return (int) $qb->getQuery()->getSingleScalarResult();
}
public function find($id, $lockMode = null, $lockVersion = null): ?User
{
return $this->repository->find($id, $lockMode, $lockVersion);
}
/**
* @return User[]
*/
public function findAll(): array
{
return $this->repository->findAll();
}
/**
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return User[]
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
/**
* @return array|User[]
*/
public function findByActive(?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
{
return $this->findBy(['enabled' => true], $orderBy, $limit, $offset);
}
public function findByUsernameOrEmail(string $pattern)
{
$qb = $this->queryByUsernameOrEmail($pattern);
@@ -87,6 +88,11 @@ final class UserRepository implements ObjectRepository
return $qb->getQuery()->getResult();
}
public function findOneBy(array $criteria, ?array $orderBy = null): ?User
{
return $this->repository->findOneBy($criteria, $orderBy);
}
public function findOneByUsernameOrEmail(string $pattern)
{
$qb = $this->queryByUsernameOrEmail($pattern);
@@ -95,28 +101,29 @@ final class UserRepository implements ObjectRepository
}
/**
* Get the users having a specific flags
* Get the users having a specific flags.
*
* If provided, only the users amongst "filtered users" are searched. This
* allows to make a first search amongst users based on role and center
* and, then filter those users having some flags.
*
* @param \Chill\MainBundle\Entity\User[] $amongstUsers
* @param mixed $flag
*/
public function findUsersHavingFlags($flag, array $amongstUsers = []): array
{
$gcs = $this
->entityManager
->createQuery(
"SELECT DISTINCT gc " .
"FROM ".GroupCenter::class." gc " .
"JOIN gc.permissionsGroup pg " .
"WHERE " .
"JSONB_EXISTS_IN_ARRAY(pg.flags, :flag) = :true "
'SELECT DISTINCT gc ' .
'FROM ' . GroupCenter::class . ' gc ' .
'JOIN gc.permissionsGroup pg ' .
'WHERE ' .
'JSONB_EXISTS_IN_ARRAY(pg.flags, :flag) = :true '
)
->setParameters([
'true' => true,
'flag' => $flag
'flag' => $flag,
])
->getResult();
@@ -132,14 +139,14 @@ final class UserRepository implements ObjectRepository
$orx = $qb->expr()->orX();
foreach($gcs as $i => $gc) {
foreach ($gcs as $i => $gc) {
$orx->add(':gc_' . $i . ' MEMBER OF u.groupCenters');
$qb->setParameter('gc_' . $i, $gc);
}
$qb->andWhere($orx);
if ($amongstUsers !== []) {
if ([] !== $amongstUsers) {
$qb
->andWhere($qb->expr()->in('u', ':amongstUsers'))
->setParameter('amongstUsers', $amongstUsers);
@@ -148,7 +155,12 @@ final class UserRepository implements ObjectRepository
return $qb->getQuery()->getResult();
}
protected function queryByUsernameOrEmail(string $pattern): QueryBuilder
public function getClassName()
{
return User::class;
}
private function queryByUsernameOrEmail(string $pattern): QueryBuilder
{
$qb = $this->entityManager->createQueryBuilder('u');