Passed
Push — main ( 788265...3118bd )
by Iain
05:04
created

LessThanFilter::modifyQuery()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright Humbly Arrogant Software Limited 2020-2023.
7
 *
8
 * Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license.
9
 *
10
 * Change Date: 26.06.2026 ( 3 years after 2.2.0 release )
11
 *
12
 * On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
13
 */
14
15
namespace Parthenon\Athena\Filters;
16
17
use Doctrine\ORM\Query;
18
use Doctrine\ORM\QueryBuilder;
19
20
class LessThanFilter implements DoctrineFilterInterface
21
{
22
    use QueryBuilderTrait;
23
24
    public const NAME = 'less_than';
25
26
    protected string $fieldName;
27
28
    private $data;
29
30
    public function modifyQueryBuilder(QueryBuilder $queryBuilder)
31
    {
32
        if (!$this->data) {
33
            return;
34
        }
35
        [$alias, $fieldName] = $this->readyQueryBuilderForAliasAndFieldName($queryBuilder);
36
        $queryBuilder->andWhere($alias.'.'.$fieldName.' < :'.$this->getSafeFieldName());
37
    }
38
39
    public function modifyQuery(Query $query)
40
    {
41
        if (!$this->data) {
42
            return;
43
        }
44
        $query->setParameter(':'.$this->getSafeFieldName(), $this->data);
45
    }
46
47
    public function getName(): string
48
    {
49
        return static::NAME;
50
    }
51
52
    public function setData($data): FilterInterface
53
    {
54
        $this->data = $data;
55
56
        return $this;
57
    }
58
59
    public function setFieldName(string $fieldName): FilterInterface
60
    {
61
        $this->fieldName = $fieldName;
62
63
        return $this;
64
    }
65
66
    public function getFieldName(): string
67
    {
68
        return $this->fieldName;
69
    }
70
71
    public function getHeaderName(): string
72
    {
73
        return ucwords(str_replace('_', ' ', $this->fieldName));
74
    }
75
76
    public function getData()
77
    {
78
        return $this->data;
79
    }
80
81
    public function hasData(): bool
82
    {
83
        return isset($this->data);
84
    }
85
}
86