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,31 +1,22 @@
<?php
/*
* Copyright (C) 2019 Julien Fastré <julien.fastre@champs-libres.coop>
/**
* Chill is a software for social workers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Repository;
use Chill\PersonBundle\Entity\Person;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ObjectRepository;
use UnexpectedValueException;
use Exception;
use function in_array;
use function str_replace;
final class PersonRepository implements ObjectRepository
{
@@ -36,65 +27,9 @@ final class PersonRepository implements ObjectRepository
$this->repository = $entityManager->getRepository(Person::class);
}
public function find($id, $lockMode = null, $lockVersion = null): ?Person
{
return $this->repository->find($id, $lockMode, $lockVersion);
}
public function findByIds($ids): array
{
return $this->repository->findBy(['id' => $ids]);
}
public function findAll()
{
return $this->repository->findAll();
}
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null)
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function findOneBy(array $criteria)
{
return $this->repository->findOneBy($criteria);
}
public function getClassName()
{
return Person::class;
}
/**
* @param $centers
* @param $firstResult
* @param $maxResults
* @return mixed
* @throws \Exception
*/
public function findByPhone(
string $phonenumber,
$centers,
$firstResult,
$maxResults,
array $only = ['mobile', 'phone']
) {
$qb = $this->repository->createQueryBuilder('p');
$qb->select('p');
$this->addByCenters($qb, $centers);
$this->addPhoneNumber($qb, $phonenumber, $only);
$qb->setFirstResult($firstResult)
->setMaxResults($maxResults)
;
return $qb->getQuery()->getResult();
}
/**
* @param $centers
*
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
*/
@@ -112,50 +47,103 @@ final class PersonRepository implements ObjectRepository
return $qb->getQuery()->getSingleScalarResult();
}
/**
* @throws \Exception
*/
protected function addPhoneNumber(QueryBuilder $qb, string $phonenumber, array $only): void
public function find($id, $lockMode = null, $lockVersion = null): ?Person
{
if (count($only) === 0) {
throw new \Exception("No array field to search");
}
$phonenumber = $this->parsePhoneNumber($phonenumber);
$orX = $qb->expr()->orX();
if (\in_array('mobile', $only)) {
$orX->add($qb->expr()->like("REPLACE(p.mobilenumber, ' ', '')", ':phonenumber'));
}
if (\in_array('phone', $only)) {
$orX->add($qb->expr()->like("REPLACE(p.phonenumber, ' ', '')", ':phonenumber'));
}
$qb->andWhere($orX);
$qb->setParameter('phonenumber', '%'.$phonenumber.'%');
return $this->repository->find($id, $lockMode, $lockVersion);
}
/**
* @param $phonenumber
* @return string
*/
protected function parsePhoneNumber(string $phonenumber): string
public function findAll()
{
return \str_replace(' ', '', $phonenumber);
return $this->repository->findAll();
}
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null)
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function findByIds($ids): array
{
return $this->repository->findBy(['id' => $ids]);
}
/**
* @param QueryBuilder $qb
* @param array $centers
* @param $centers
* @param $firstResult
* @param $maxResults
*
* @throws Exception
*
* @return mixed
*/
protected function addByCenters(QueryBuilder $qb, array $centers): void
public function findByPhone(
string $phonenumber,
$centers,
$firstResult,
$maxResults,
array $only = ['mobile', 'phone']
) {
$qb = $this->repository->createQueryBuilder('p');
$qb->select('p');
$this->addByCenters($qb, $centers);
$this->addPhoneNumber($qb, $phonenumber, $only);
$qb->setFirstResult($firstResult)
->setMaxResults($maxResults);
return $qb->getQuery()->getResult();
}
public function findOneBy(array $criteria)
{
return $this->repository->findOneBy($criteria);
}
public function getClassName()
{
return Person::class;
}
private function addByCenters(QueryBuilder $qb, array $centers): void
{
if (count($centers) > 0) {
$qb->andWhere($qb->expr()->in('p.center', ':centers'));
$qb->setParameter('centers', $centers);
}
}
/**
* @throws Exception
*/
private function addPhoneNumber(QueryBuilder $qb, string $phonenumber, array $only): void
{
if (count($only) === 0) {
throw new Exception('No array field to search');
}
$phonenumber = $this->parsePhoneNumber($phonenumber);
$orX = $qb->expr()->orX();
if (in_array('mobile', $only)) {
$orX->add($qb->expr()->like("REPLACE(p.mobilenumber, ' ', '')", ':phonenumber'));
}
if (in_array('phone', $only)) {
$orX->add($qb->expr()->like("REPLACE(p.phonenumber, ' ', '')", ':phonenumber'));
}
$qb->andWhere($orX);
$qb->setParameter('phonenumber', '%' . $phonenumber . '%');
}
/**
* @param $phonenumber
*/
private function parsePhoneNumber(string $phonenumber): string
{
return str_replace(' ', '', $phonenumber);
}
}