6
6
7
7
namespace Magento \Framework \Data ;
8
8
9
+ use Magento \Framework \App \ObjectManager ;
9
10
use Magento \Framework \Data \Collection \EntityFactoryInterface ;
11
+ use Magento \Framework \DataObject ;
12
+ use Magento \Framework \Exception \AlreadyExistsException ;
10
13
use Magento \Framework \Option \ArrayInterface ;
11
14
12
15
/**
@@ -25,7 +28,7 @@ class Collection implements \IteratorAggregate, \Countable, ArrayInterface, Coll
25
28
/**
26
29
* Collection items
27
30
*
28
- * @var \Magento\Framework\ DataObject[]
31
+ * @var DataObject[]
29
32
*/
30
33
protected $ _items = [];
31
34
@@ -34,7 +37,7 @@ class Collection implements \IteratorAggregate, \Countable, ArrayInterface, Coll
34
37
*
35
38
* @var string
36
39
*/
37
- protected $ _itemObjectClass = \ Magento \ Framework \ DataObject::class;
40
+ protected $ _itemObjectClass = DataObject::class;
38
41
39
42
/**
40
43
* Order configuration
@@ -46,7 +49,7 @@ class Collection implements \IteratorAggregate, \Countable, ArrayInterface, Coll
46
49
/**
47
50
* Filters configuration
48
51
*
49
- * @var \Magento\Framework\ DataObject[]
52
+ * @var DataObject[]
50
53
*/
51
54
protected $ _filters = [];
52
55
@@ -117,7 +120,7 @@ public function __construct(EntityFactoryInterface $entityFactory)
117
120
*/
118
121
public function addFilter ($ field , $ value , $ type = 'and ' )
119
122
{
120
- $ filter = new \ Magento \ Framework \ DataObject ();
123
+ $ filter = new DataObject ();
121
124
// implements ArrayAccess
122
125
$ filter ['field ' ] = $ field ;
123
126
$ filter ['value ' ] = $ value ;
@@ -163,9 +166,9 @@ public function addFilter($field, $value, $type = 'and')
163
166
*
164
167
* @param string|array $field
165
168
* @param string|int|array $condition
166
- * @throws \Magento\Framework\Exception\LocalizedException if some error in the input could be detected.
167
169
* @return $this
168
170
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
171
+ * @throws \Magento\Framework\Exception\LocalizedException if some error in the input could be detected.
169
172
*/
170
173
public function addFieldToFilter ($ field , $ condition )
171
174
{
@@ -182,7 +185,7 @@ public function addFieldToFilter($field, $condition)
182
185
* - array() -- get all filters
183
186
*
184
187
* @param string|string[] $field
185
- * @return \Magento\Framework\ DataObject|\Magento\Framework\ DataObject[]|void
188
+ * @return DataObject|DataObject[]|void
186
189
*/
187
190
public function getFilter ($ field )
188
191
{
@@ -234,18 +237,16 @@ protected function _setIsLoaded($flag = true)
234
237
/**
235
238
* Get current collection page
236
239
*
237
- * @param int $displacement
240
+ * @param int $displacement
238
241
* @return int
239
242
*/
240
243
public function getCurPage ($ displacement = 0 )
241
244
{
242
245
if ($ this ->_curPage + $ displacement < 1 ) {
243
246
return 1 ;
244
- } elseif ($ this ->_curPage + $ displacement > $ this ->getLastPageNumber ()) {
245
- return $ this ->getLastPageNumber ();
246
- } else {
247
- return $ this ->_curPage + $ displacement ;
248
247
}
248
+
249
+ return $ this ->_curPage + $ displacement ;
249
250
}
250
251
251
252
/**
@@ -260,9 +261,9 @@ public function getLastPageNumber()
260
261
return 1 ;
261
262
} elseif ($ this ->_pageSize ) {
262
263
return (int )ceil ($ collectionSize / $ this ->_pageSize );
263
- } else {
264
- return 1 ;
265
264
}
265
+
266
+ return 1 ;
266
267
}
267
268
268
269
/**
@@ -292,7 +293,7 @@ public function getSize()
292
293
/**
293
294
* Retrieve collection first item
294
295
*
295
- * @return \Magento\Framework\ DataObject
296
+ * @return DataObject
296
297
*/
297
298
public function getFirstItem ()
298
299
{
@@ -309,7 +310,7 @@ public function getFirstItem()
309
310
/**
310
311
* Retrieve collection last item
311
312
*
312
- * @return \Magento\Framework\ DataObject
313
+ * @return DataObject
313
314
*/
314
315
public function getLastItem ()
315
316
{
@@ -325,7 +326,7 @@ public function getLastItem()
325
326
/**
326
327
* Retrieve collection items
327
328
*
328
- * @return \Magento\Framework\ DataObject[]
329
+ * @return DataObject[]
329
330
*/
330
331
public function getItems ()
331
332
{
@@ -336,7 +337,7 @@ public function getItems()
336
337
/**
337
338
* Retrieve field values from all items
338
339
*
339
- * @param string $colName
340
+ * @param string $colName
340
341
* @return array
341
342
*/
342
343
public function getColumnValues ($ colName )
@@ -353,8 +354,8 @@ public function getColumnValues($colName)
353
354
/**
354
355
* Search all items by field value
355
356
*
356
- * @param string $column
357
- * @param mixed $value
357
+ * @param string $column
358
+ * @param array $value
358
359
* @return array
359
360
*/
360
361
public function getItemsByColumnValue ($ column , $ value )
@@ -373,9 +374,9 @@ public function getItemsByColumnValue($column, $value)
373
374
/**
374
375
* Search first item by field value
375
376
*
376
- * @param string $column
377
- * @param mixed $value
378
- * @return \Magento\Framework\ DataObject || null
377
+ * @param string $column
378
+ * @param string|int $value
379
+ * @return DataObject| null
379
380
*/
380
381
public function getItemByColumnValue ($ column , $ value )
381
382
{
@@ -392,11 +393,11 @@ public function getItemByColumnValue($column, $value)
392
393
/**
393
394
* Adding item to item array
394
395
*
395
- * @param \Magento\Framework\ DataObject $item
396
+ * @param DataObject $item
396
397
* @return $this
397
398
* @throws \Exception
398
399
*/
399
- public function addItem (\ Magento \ Framework \ DataObject $ item )
400
+ public function addItem (DataObject $ item )
400
401
{
401
402
$ itemId = $ this ->_getItemId ($ item );
402
403
@@ -417,7 +418,7 @@ public function addItem(\Magento\Framework\DataObject $item)
417
418
/**
418
419
* Add item that has no id to collection
419
420
*
420
- * @param \Magento\Framework\ DataObject $item
421
+ * @param DataObject $item
421
422
* @return $this
422
423
*/
423
424
protected function _addItem ($ item )
@@ -429,10 +430,10 @@ protected function _addItem($item)
429
430
/**
430
431
* Retrieve item id
431
432
*
432
- * @param \Magento\Framework\ DataObject $item
433
- * @return mixed
433
+ * @param DataObject $item
434
+ * @return string|int
434
435
*/
435
- protected function _getItemId (\ Magento \ Framework \ DataObject $ item )
436
+ protected function _getItemId (DataObject $ item )
436
437
{
437
438
return $ item ->getId ();
438
439
}
@@ -454,7 +455,7 @@ public function getAllIds()
454
455
/**
455
456
* Remove item from collection by item key
456
457
*
457
- * @param mixed $key
458
+ * @param string $key
458
459
* @return $this
459
460
*/
460
461
public function removeItemByKey ($ key )
@@ -542,8 +543,8 @@ public function each($objMethod, $args = [])
542
543
/**
543
544
* Setting data for all collection items
544
545
*
545
- * @param mixed $key
546
- * @param mixed $value
546
+ * @param string $key
547
+ * @param string|int|null $value
547
548
* @return $this
548
549
*/
549
550
public function setDataToAll ($ key , $ value = null )
@@ -606,7 +607,7 @@ public function setOrder($field, $direction = self::SORT_ORDER_DESC)
606
607
*/
607
608
public function setItemObjectClass ($ className )
608
609
{
609
- if (!is_a ($ className , \ Magento \ Framework \ DataObject::class, true )) {
610
+ if (!is_a ($ className , DataObject::class, true )) {
610
611
throw new \InvalidArgumentException ($ className . ' does not extend \Magento\Framework\DataObject ' );
611
612
}
612
613
$ this ->_itemObjectClass = $ className ;
@@ -616,7 +617,7 @@ public function setItemObjectClass($className)
616
617
/**
617
618
* Retrieve collection empty item
618
619
*
619
- * @return \Magento\Framework\ DataObject
620
+ * @return DataObject
620
621
*/
621
622
public function getNewEmptyItem ()
622
623
{
@@ -748,8 +749,8 @@ public function toArray($arrRequiredFields = [])
748
749
* Return items array
749
750
* array(
750
751
* $index => array(
751
- * 'value' => mixed
752
- * 'label' => mixed
752
+ * 'value' => string
753
+ * 'label' => string
753
754
* )
754
755
* )
755
756
*
@@ -815,8 +816,8 @@ protected function _toOptionHash($valueField = 'id', $labelField = 'name')
815
816
/**
816
817
* Retrieve item by id
817
818
*
818
- * @param mixed $idValue
819
- * @return \Magento\Framework\ DataObject
819
+ * @param string|int $idValue
820
+ * @return DataObject
820
821
*/
821
822
public function getItemById ($ idValue )
822
823
{
@@ -910,7 +911,7 @@ public function __sleep()
910
911
*/
911
912
public function __wakeup ()
912
913
{
913
- $ objectManager = \ Magento \ Framework \ App \ ObjectManager::getInstance ();
914
+ $ objectManager = ObjectManager::getInstance ();
914
915
$ this ->_entityFactory = $ objectManager ->get (EntityFactoryInterface::class);
915
916
}
916
917
}
0 commit comments