Completed
Push — master ( 45aada...26ef87 )
by Matthew
02:32
created

QueryObject::setLimit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4286
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace Ps2alerts\Api\QueryObjects;
4
5
class QueryObject
6
{
7
    /**
8
     * @var array
9
     */
10
    protected $wheres;
11
12
    /**
13
     * @var string
14
     */
15
    protected $orderBy;
16
17
    /**
18
     * @var string
19
     */
20
    protected $orderByDirection = 'asc';
21
22
    /**
23
     * @var string
24
     */
25
    protected $dimension = 'multi';
26
27
    /**
28
     * Limit of records to bring back
29
     *
30
     * @var integer
31
     */
32
    protected $limit = null;
33
34
    /**
35
     * Place to set special workaround flags
36
     *
37
     * @var string|array
38
     */
39
    protected $flags;
40
41
    /**
42
     * Adds where statements to the object
43
     *
44
     * @param array $array
45
     */
46
    public function addWhere($array)
47
    {
48
        $this->wheres[] = $array;
49
    }
50
51
    /**
52
     * Pulls out the array for the where statements
53
     *
54
     * @return array
55
     */
56
    public function getWheres()
57
    {
58
        return $this->wheres;
59
    }
60
61
    /**
62
     * Set order by column
63
     *
64
     * @param string $string [description]
65
     */
66
    public function setOrderBy($string)
67
    {
68
        $this->orderBy = $string;
69
    }
70
71
    /**
72
     * Get order by column
73
     *
74
     * @return string
75
     */
76
    public function getOrderBy()
77
    {
78
        return $this->orderBy;
79
    }
80
81
    /**
82
     * Set asc or desc
83
     *
84
     * @param string $string
85
     */
86
    public function setOrderByDirection($string)
87
    {
88
        $this->orderByDirection = $string;
89
    }
90
91
    /**
92
     * Gets order by direction
93
     *
94
     * @return string
95
     */
96
    public function getOrderByDirection()
97
    {
98
        return $this->orderByDirection;
99
    }
100
101
    /**
102
     * Set array dimension level
103
     *
104
     * @param string $string
105
     */
106
    public function setDimension($string)
107
    {
108
        $this->dimension = $string;
109
    }
110
111
    /**
112
     * Gets array dimension level
113
     *
114
     * @return string
115
     */
116
    public function getDimension()
117
    {
118
        return $this->dimension;
119
    }
120
121
    /**
122
     * Sets the limit of records to bring back
123
     *
124
     * @param integer $limit
125
     */
126
    public function setLimit($limit)
127
    {
128
        if (is_numeric($limit)) {
129
            $this->limit = $limit;
0 ignored issues
show
Documentation Bug introduced by
It seems like $limit can also be of type double or string. However, the property $limit is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
130
        }
131
    }
132
133
    /**
134
     * Gets the limit of records
135
     *
136
     * @return integer
137
     */
138
    public function getLimit()
139
    {
140
        return $this->limit;
141
    }
142
143
    /**
144
     * Allows setting of workaround flags
145
     *
146
     * @param array|string $flags
147
     */
148
    public function setFlags($flags)
149
    {
150
        $this->flags = $flags;
151
    }
152
153
    /**
154
     * Retreives workaround flags
155
     *
156
     * @return array|string
157
     */
158
    public function getFlags()
159
    {
160
        return $this->flags;
161
    }
162
}
163