Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Warxcell committed Nov 15, 2021
1 parent 45741da commit 7c770b0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
11 changes: 8 additions & 3 deletions src/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
namespace Arxy\DoctrineORMFilters;

use Doctrine\ORM\QueryBuilder;
use InvalidArgumentException;

use function call_user_func_array;
use function count;
use function is_array;
use function is_callable;

trait Filters
{
Expand All @@ -26,7 +32,7 @@ private function getFilter($name): callable
$this->createFilters();

if (!isset($this->filters[$name])) {
throw new \InvalidArgumentException('Filter '.$name.' for '.get_class($this).' does not exists');
throw new InvalidArgumentException('Filter ' . $name . ' for ' . get_class($this) . ' does not exists');
}

return $this->filters[$name];
Expand Down Expand Up @@ -81,7 +87,6 @@ public function getSingleResultByFilters(iterable $filterBy): object
return $this->createQueryBuilderByFilters('entity', $filterBy)->getQuery()->getSingleResult();
}


public function countByFilters(iterable $filterBy): int
{
return (int)$this
Expand All @@ -90,4 +95,4 @@ public function countByFilters(iterable $filterBy): int
->getQuery()
->getSingleScalarResult();
}
}
}
14 changes: 10 additions & 4 deletions src/HasFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Arxy\DoctrineORMFilters;

use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use Doctrine\ORM\QueryBuilder;

interface HasFilters
Expand All @@ -17,17 +19,21 @@ public function createQueryBuilderByFilters(
public function appendFilter(QueryBuilder $queryBuilder, string $alias, string $filterName, ...$values): bool;

/**
* @throws \Doctrine\ORM\NonUniqueResultException
* @throws NonUniqueResultException
*/
public function findOneByFilters(iterable $filterBy): ?object;

public function findByFilters(iterable $filterBy): array;

/**
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
* @throws NoResultException
* @throws NonUniqueResultException
*/
public function getSingleResultByFilters(iterable $filterBy): object;

/**
* @throws NonUniqueResultException
* @throws NoResultException
*/
public function countByFilters(iterable $filterBy): int;
}
}
5 changes: 3 additions & 2 deletions tests/TestRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

use Arxy\DoctrineORMFilters\Filters;
use Arxy\DoctrineORMFilters\HasFilters;
use Doctrine\ORM\QueryBuilder;

class TestRepository implements HasFilters
{
use Filters;

public function createQueryBuilder($alias, $indexBy = null)
public function createQueryBuilder($alias, $indexBy = null): QueryBuilder
{

}
Expand All @@ -18,4 +19,4 @@ public function getFilters(): array
{
return [];
}
}
}

0 comments on commit 7c770b0

Please sign in to comment.