phpcsfixes

This commit is contained in:
2022-02-11 11:28:32 +01:00
committed by Julien Fastré
parent bf0b7f1bb2
commit c8e5ba4738
8 changed files with 103 additions and 85 deletions

View File

@@ -1,5 +1,14 @@
<?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\DocStoreBundle\Repository;
use Chill\DocStoreBundle\Entity\PersonDocument;
@@ -13,12 +22,12 @@ use Symfony\Component\Security\Core\Security;
class PersonDocumentACLAwareRepository implements PersonDocumentACLAwareRepositoryInterface
{
private EntityManagerInterface $em;
private AuthorizationHelperInterface $authorizationHelper;
private CenterResolverDispatcher $centerResolverDispatcher;
private EntityManagerInterface $em;
private Security $security;
public function __construct(EntityManagerInterface $em, AuthorizationHelperInterface $authorizationHelper, CenterResolverDispatcher $centerResolverDispatcher, Security $security)
@@ -29,19 +38,15 @@ class PersonDocumentACLAwareRepository implements PersonDocumentACLAwareReposito
$this->security = $security;
}
public function findByPerson(Person $person, array $orderBy = [], int $limit = 20, int $offset = 0): array
public function buildQueryByPerson(Person $person): QueryBuilder
{
$qb = $this->buildQueryByPerson($person)->select('d');
$qb = $this->em->getRepository(PersonDocument::class)->createQueryBuilder('d');
$this->addACL($qb, $person);
$qb
->where($qb->expr()->eq('d.person', ':person'))
->setParameter('person', $person);
foreach ($orderBy as list($field, $order)) {
$qb->addOrderBy($field, $order);
}
$qb->setFirstResult($offset)->setMaxResults($limit);
return $qb->getQuery()->getResult();
return $qb;
}
public function countByPerson(Person $person): int
@@ -53,21 +58,23 @@ class PersonDocumentACLAwareRepository implements PersonDocumentACLAwareReposito
return $qb->getQuery()->getSingleScalarResult();
}
public function buildQueryByPerson(Person $person): QueryBuilder
public function findByPerson(Person $person, array $orderBy = [], int $limit = 20, int $offset = 0): array
{
$qb = $this->em->getRepository(PersonDocument::class)->createQueryBuilder('d');
$qb = $this->buildQueryByPerson($person)->select('d');
$qb
->where($qb->expr()->eq('d.person', ':person'))
->setParameter('person', $person)
;
$this->addACL($qb, $person);
return $qb;
foreach ($orderBy as [$field, $order]) {
$qb->addOrderBy($field, $order);
}
$qb->setFirstResult($offset)->setMaxResults($limit);
return $qb->getQuery()->getResult();
}
private function addACL(QueryBuilder $qb, Person $person): void
{
$center = $this->centerResolverDispatcher->resolveCenter($person);
$reachableScopes = $this->authorizationHelper
@@ -78,8 +85,6 @@ class PersonDocumentACLAwareRepository implements PersonDocumentACLAwareReposito
);
$qb->andWhere($qb->expr()->in('d.scope', ':scopes'))
->setParameter('scopes', $reachableScopes)
;
->setParameter('scopes', $reachableScopes);
}
}