Remove obsolete documentation, fix typing here and there.

This commit is contained in:
Pol Dellaiera
2021-05-21 16:34:42 +02:00
parent 220f1ea0eb
commit d672a29dda
14 changed files with 25 additions and 181 deletions

View File

@@ -32,105 +32,88 @@ final class PersonRepository
$this->repository = $entityManager->getRepository(Person::class);
}
public function find($id, $lockMode = null, $lockVersion = null)
public function find($id, $lockMode = null, $lockVersion = null): ?Person
{
return $this->repository->find($id, $lockMode, $lockVersion);
}
/**
* @param string $phonenumber
* @param $centers
* @param $firstResult
* @param $maxResults
* @param array $only
* @return mixed
* @throws \Exception
*/
public function findByPhone(
string $phonenumber,
$centers,
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 string $phonenumber
* @param $centers
* @param array $only
* @return int
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function countByPhone(
string $phonenumber,
$centers,
string $phonenumber,
$centers,
array $only = ['mobile', 'phone']
): int
{
): int {
$qb = $this->repository->createQueryBuilder('p');
$qb->select('COUNT(p)');
$this->addByCenters($qb, $centers);
$this->addPhoneNumber($qb, $phonenumber, $only);
return $qb->getQuery()->getSingleScalarResult();
}
/**
* @param QueryBuilder $qb
* @param string $phonenumber
* @param array $only
* @throws \Exception
*/
protected function addPhoneNumber(QueryBuilder $qb, string $phonenumber, array $only)
protected 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
* @return string
*/
protected function parsePhoneNumber($phonenumber): string
protected function parsePhoneNumber(string $phonenumber): string
{
return \str_replace(' ', '', $phonenumber);
}
/**
* @param QueryBuilder $qb
* @param array $centers
*/
protected function addByCenters(QueryBuilder $qb, array $centers)
protected function addByCenters(QueryBuilder $qb, array $centers): void
{
if (count($centers) > 0) {
$qb->andWhere($qb->expr()->in('p.center', ':centers'));