@@ -25,18 +25,11 @@ trait CollectionTrait{
2525 static protected $ pagination ;
2626
2727 /**
28- * Get pagination data
28+ * Instance of Database Paginate Method
2929 *
3030 * @var mixed
3131 */
32- static protected $ pagination_data = [];
33-
34- /**
35- * Instance of Database Paginate request method
36- *
37- * @var mixed
38- */
39- static protected $ check_paginate ;
32+ static protected $ is_paginate ;
4033
4134 /**
4235 * The methods that can be proxied.
@@ -115,7 +108,7 @@ static protected function getTrace()
115108 self ::$ instance = $ interest [0 ] ?? null ;
116109
117110 // instance of DB Paginate request
118- self ::$ check_paginate = in_array (self ::$ instance , self ::$ proxies ['paginate ' ]);
111+ self ::$ is_paginate = in_array (self ::$ instance , self ::$ proxies ['paginate ' ]);
119112 }
120113
121114 /**
@@ -127,15 +120,10 @@ static protected function getTrace()
127120 */
128121 protected function wrapArrayIntoCollectionMappers (mixed $ items )
129122 {
130- // if pagination request is true\ The collect the Pagination `data`
131- // Otherwise, get the `items` passed as param
132- $ items = self ::$ check_paginate
133- ? self ::$ pagination_data
134- : $ items ;
135-
123+ // check if valid array data
136124 if (is_array ($ items ) && count ($ items ) > 0 ) {
137125 return array_map (function ($ item , $ key ){
138- return new CollectionMapper ($ item , $ key , self ::$ check_paginate , self ::$ pagination );
126+ return new CollectionMapper ($ item , $ key , self ::$ is_paginate , self ::$ pagination );
139127 }, $ items , array_keys ($ items ));
140128 }
141129
@@ -166,7 +154,7 @@ protected function getArrayItems($items)
166154 */
167155 public function getPagination ()
168156 {
169- if (self ::$ check_paginate ){
157+ if (self ::$ is_paginate ){
170158 $ pagination = self ::$ pagination ->pagination ;
171159 return (object ) [
172160 'limit ' => (int ) $ pagination ->limit ,
@@ -228,13 +216,13 @@ public function isEmpty()
228216 */
229217 public function count (): int
230218 {
231- if (self ::$ check_paginate ){
232- return count (self ::$ pagination_data );
233- } elseif ($ this ->unescapeIsObjectWithoutArray ){
234- return 1 ;
219+ if ($ this ->unescapeIsObjectWithoutArray ){
220+ return 0 ;
235221 }
236222
237- return $ this ->isArray () ? count ($ this ->items ): 0 ;
223+ return $ this ->isArray ()
224+ ? count ($ this ->items )
225+ : 0 ;
238226 }
239227
240228 /**
@@ -244,7 +232,7 @@ public function count(): int
244232 */
245233 public function toArray ()
246234 {
247- return json_decode ( json_encode ($ this ->getItemsData () ), true );
235+ return json_decode ( json_encode ($ this ->items ), true );
248236 }
249237
250238 /**
@@ -254,7 +242,7 @@ public function toArray()
254242 */
255243 public function toObject ()
256244 {
257- return json_decode ( json_encode ($ this ->getItemsData () ), false );
245+ return json_decode ( json_encode ($ this ->items ), false );
258246 }
259247
260248 /**
@@ -264,7 +252,7 @@ public function toObject()
264252 */
265253 public function toJson ()
266254 {
267- return json_encode ($ this ->getItemsData () );
255+ return json_encode ($ this ->items );
268256 }
269257
270258 /**
@@ -277,16 +265,6 @@ private function isArray()
277265 return is_array ($ this ->items ) ? true : false ;
278266 }
279267
280- /**
281- * Determine if pagination Data is to be returned or Items Data
282- *
283- * @return mixed
284- */
285- private function getItemsData ()
286- {
287- return self ::$ check_paginate ? self ::$ pagination_data : $ this ->items ;
288- }
289-
290268 /**
291269 * Convert data to an array on Initializaiton
292270 * @param mixed $items
0 commit comments