|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Arp\LaminasDoctrine\Query\Filter; |
|
6
|
|
|
|
|
7
|
|
|
use Arp\LaminasDoctrine\Query\Constant\WhereType; |
|
8
|
|
|
use Arp\LaminasDoctrine\Query\Exception\InvalidArgumentException; |
|
9
|
|
|
use Arp\LaminasDoctrine\Query\Metadata\MetadataInterface; |
|
10
|
|
|
use Arp\LaminasDoctrine\Query\QueryBuilderInterface; |
|
11
|
|
|
use Doctrine\ORM\Query\Expr; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @author Alex Patterson <[email protected]> |
|
15
|
|
|
* @package Arp\LaminasDoctrine\Query\Filter |
|
16
|
|
|
*/ |
|
17
|
|
|
final class Between extends AbstractFilter |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @param QueryBuilderInterface $queryBuilder |
|
21
|
|
|
* @param MetadataInterface $metadata |
|
22
|
|
|
* @param array $criteria |
|
23
|
|
|
* |
|
24
|
|
|
* @throws InvalidArgumentException |
|
25
|
|
|
*/ |
|
26
|
|
|
public function filter(QueryBuilderInterface $queryBuilder, MetadataInterface $metadata, array $criteria): void |
|
27
|
|
|
{ |
|
28
|
|
|
$fieldName = $this->resolveFieldName($metadata, $criteria); |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
$queryAlias = $criteria['alias'] ?? 'entity'; |
|
31
|
|
|
$paramName = uniqid($queryAlias, false); |
|
32
|
|
|
|
|
33
|
|
|
$expression = $queryBuilder->expr()->between( |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
if (!isset($criteria['where']) || WhereType::AND === $criteria['where']) { |
|
39
|
|
|
$queryBuilder->andWhere($expression); |
|
40
|
|
|
} else { |
|
41
|
|
|
$queryBuilder->orWhere($expression); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
// Some comparisons will not require a value to be provided |
|
45
|
|
|
if (array_key_exists('value', $criteria)) { |
|
46
|
|
|
$value = $this->formatValue($metadata, $fieldName, $criteria['value'], $criteria['format'] ?? null); |
|
|
|
|
|
|
47
|
|
|
$queryBuilder->setParameter($paramName, $value); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.