Completed
Push — master ( df95c6...f74e51 )
by
unknown
13s
created

Filters   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 73
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A greaterThan() 0 4 1
A greaterThanOrEqual() 0 4 1
A lessThan() 0 4 1
A between() 0 4 1
A in() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
namespace Moip\Helper;
4
5
/**
6
 * Class Filters.
7
 */
8
class Filters
9
{
10
    /**
11
     * @var array
12
     **/
13
    private $filters = [];
14
15
    /**
16
     * Set filter to compare if field is greater than value.
17
     *
18
     * @param string   $field field to setup filter.
19
     * @param int|Date $value value to setup filter.
20
     */
21
    public function greaterThan($field, $value)
22
    {
23
        $this->filters[] = sprintf('%s::gt(%s)', $field, $value);
24
    }
25
26
    /**
27
     * Set filter to compare if field is greater than or equal value.
28
     *
29
     * @param string   $field field to setup filter.
30
     * @param int|Date $value value to setup filter.
31
     */
32
    public function greaterThanOrEqual($field, $value)
33
    {
34
        $this->filters[] = sprintf('%s::ge(%s)', $field, $value);
35
    }
36
37
    /**
38
     * Set filter to compare if field is less than value.
39
     *
40
     * @param string   $field field to setup filter.
41
     * @param int|Date $value value to setup filter.
42
     */
43
    public function lessThan($field, $value)
44
    {
45
        $this->filters[] = sprintf('%s::lt(%s)', $field, $value);
46
    }
47
48
    /**
49
     * Set filter to compare if field is between both values.
50
     *
51
     * @param string $field  field to setup filter.
52
     * @param string $value1 first value to setup filter.
53
     * @param string $value2 second value to setup filter.
54
     */
55
    public function between($field, $value1, $value2)
56
    {
57
        $this->filters[] = sprintf('%s::bt(%s,%s)', $field, $value1, $value2);
58
    }
59
60
    /**
61
     * Set filter to compare if field is in array.
62
     *
63
     * @param string $field  field to setup filter.
64
     * @param array  $values value to setup filter.
65
     */
66
    public function in($field, array $values)
67
    {
68
        $this->filters[] = sprintf('%s::in(%s)', $field, implode(',', $values));
69
    }
70
71
    /**
72
     * Join filters in one string.
73
     *
74
     * @return string
75
     */
76
    public function __toString()
77
    {
78
        return implode('|', $this->filters);
79
    }
80
}
81