1 | <?php |
||
17 | abstract class Collection extends ArrayObject implements Common |
||
18 | { |
||
19 | private $client; |
||
20 | |||
21 | private $loadStatus = 0; |
||
22 | |||
23 | private $fields = []; |
||
24 | |||
25 | private $class = null; |
||
26 | |||
27 | private $limit = null; |
||
28 | |||
29 | private $offset = null; |
||
30 | |||
31 | /** |
||
32 | * Collection constructor. |
||
33 | * |
||
34 | * @param Client $client |
||
35 | * @param array $fields |
||
36 | * @param string $class |
||
37 | * @param int $limit |
||
38 | * @param int $offset |
||
39 | * @throws Exception |
||
40 | */ |
||
41 | 6 | public function __construct(Client $client, array $fields, $class, $limit, $offset) |
|
64 | |||
65 | /** |
||
66 | * @param int $limit |
||
67 | */ |
||
68 | 6 | public function setLimit($limit) |
|
76 | |||
77 | /** |
||
78 | * @param bool $force |
||
79 | * @return $this |
||
80 | */ |
||
81 | 6 | public function load($force = false) |
|
82 | { |
||
83 | 6 | if ($this->loadStatus == 200 && !$force) { |
|
84 | return $this; |
||
85 | } |
||
86 | |||
87 | $params = [ |
||
88 | 6 | 'limit' => $this->limit, |
|
89 | 6 | 'offset' => $this->offset |
|
90 | ]; |
||
91 | |||
92 | 6 | if ($this->fields) { |
|
|
|||
93 | $params['fields'] = implode(',', (array)$this->fields); |
||
94 | } |
||
95 | |||
96 | 6 | $response = $this->client->getResponse($this->getUrl(__FUNCTION__), $params); |
|
97 | |||
98 | $this->exchangeArray($response['data']); |
||
99 | |||
100 | $this->loadStatus = $response['status']; |
||
101 | |||
102 | unset($response); |
||
103 | |||
104 | return $this; |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * @param int $offset |
||
109 | */ |
||
110 | 6 | public function setOffset($offset) |
|
118 | |||
119 | public function getIterator() |
||
123 | |||
124 | 2 | public function count() |
|
130 | |||
131 | public function getData() |
||
137 | |||
138 | 4 | public function reset() |
|
144 | |||
145 | /** |
||
146 | * @param array $data |
||
147 | * @return Model |
||
148 | */ |
||
149 | public function createModel(array $data = null) |
||
162 | |||
163 | public function end() |
||
169 | } |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.