Skip to content

Commit b254764

Browse files
committed
magento#26986 Remove "feature" that overrides the currentPage value
1 parent a6f76f3 commit b254764

File tree

1 file changed

+39
-38
lines changed

1 file changed

+39
-38
lines changed

lib/internal/Magento/Framework/Data/Collection.php

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
namespace Magento\Framework\Data;
88

9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Framework\Data\Collection\EntityFactoryInterface;
11+
use Magento\Framework\DataObject;
12+
use Magento\Framework\Exception\AlreadyExistsException;
1013
use Magento\Framework\Option\ArrayInterface;
1114

1215
/**
@@ -25,7 +28,7 @@ class Collection implements \IteratorAggregate, \Countable, ArrayInterface, Coll
2528
/**
2629
* Collection items
2730
*
28-
* @var \Magento\Framework\DataObject[]
31+
* @var DataObject[]
2932
*/
3033
protected $_items = [];
3134

@@ -34,7 +37,7 @@ class Collection implements \IteratorAggregate, \Countable, ArrayInterface, Coll
3437
*
3538
* @var string
3639
*/
37-
protected $_itemObjectClass = \Magento\Framework\DataObject::class;
40+
protected $_itemObjectClass = DataObject::class;
3841

3942
/**
4043
* Order configuration
@@ -46,7 +49,7 @@ class Collection implements \IteratorAggregate, \Countable, ArrayInterface, Coll
4649
/**
4750
* Filters configuration
4851
*
49-
* @var \Magento\Framework\DataObject[]
52+
* @var DataObject[]
5053
*/
5154
protected $_filters = [];
5255

@@ -117,7 +120,7 @@ public function __construct(EntityFactoryInterface $entityFactory)
117120
*/
118121
public function addFilter($field, $value, $type = 'and')
119122
{
120-
$filter = new \Magento\Framework\DataObject();
123+
$filter = new DataObject();
121124
// implements ArrayAccess
122125
$filter['field'] = $field;
123126
$filter['value'] = $value;
@@ -163,9 +166,9 @@ public function addFilter($field, $value, $type = 'and')
163166
*
164167
* @param string|array $field
165168
* @param string|int|array $condition
166-
* @throws \Magento\Framework\Exception\LocalizedException if some error in the input could be detected.
167169
* @return $this
168170
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
171+
* @throws \Magento\Framework\Exception\LocalizedException if some error in the input could be detected.
169172
*/
170173
public function addFieldToFilter($field, $condition)
171174
{
@@ -182,7 +185,7 @@ public function addFieldToFilter($field, $condition)
182185
* - array() -- get all filters
183186
*
184187
* @param string|string[] $field
185-
* @return \Magento\Framework\DataObject|\Magento\Framework\DataObject[]|void
188+
* @return DataObject|DataObject[]|void
186189
*/
187190
public function getFilter($field)
188191
{
@@ -234,18 +237,16 @@ protected function _setIsLoaded($flag = true)
234237
/**
235238
* Get current collection page
236239
*
237-
* @param int $displacement
240+
* @param int $displacement
238241
* @return int
239242
*/
240243
public function getCurPage($displacement = 0)
241244
{
242245
if ($this->_curPage + $displacement < 1) {
243246
return 1;
244-
} elseif ($this->_curPage + $displacement > $this->getLastPageNumber()) {
245-
return $this->getLastPageNumber();
246-
} else {
247-
return $this->_curPage + $displacement;
248247
}
248+
249+
return $this->_curPage + $displacement;
249250
}
250251

251252
/**
@@ -260,9 +261,9 @@ public function getLastPageNumber()
260261
return 1;
261262
} elseif ($this->_pageSize) {
262263
return (int)ceil($collectionSize / $this->_pageSize);
263-
} else {
264-
return 1;
265264
}
265+
266+
return 1;
266267
}
267268

268269
/**
@@ -292,7 +293,7 @@ public function getSize()
292293
/**
293294
* Retrieve collection first item
294295
*
295-
* @return \Magento\Framework\DataObject
296+
* @return DataObject
296297
*/
297298
public function getFirstItem()
298299
{
@@ -309,7 +310,7 @@ public function getFirstItem()
309310
/**
310311
* Retrieve collection last item
311312
*
312-
* @return \Magento\Framework\DataObject
313+
* @return DataObject
313314
*/
314315
public function getLastItem()
315316
{
@@ -325,7 +326,7 @@ public function getLastItem()
325326
/**
326327
* Retrieve collection items
327328
*
328-
* @return \Magento\Framework\DataObject[]
329+
* @return DataObject[]
329330
*/
330331
public function getItems()
331332
{
@@ -336,7 +337,7 @@ public function getItems()
336337
/**
337338
* Retrieve field values from all items
338339
*
339-
* @param string $colName
340+
* @param string $colName
340341
* @return array
341342
*/
342343
public function getColumnValues($colName)
@@ -353,8 +354,8 @@ public function getColumnValues($colName)
353354
/**
354355
* Search all items by field value
355356
*
356-
* @param string $column
357-
* @param mixed $value
357+
* @param string $column
358+
* @param array $value
358359
* @return array
359360
*/
360361
public function getItemsByColumnValue($column, $value)
@@ -373,9 +374,9 @@ public function getItemsByColumnValue($column, $value)
373374
/**
374375
* Search first item by field value
375376
*
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
379380
*/
380381
public function getItemByColumnValue($column, $value)
381382
{
@@ -392,11 +393,11 @@ public function getItemByColumnValue($column, $value)
392393
/**
393394
* Adding item to item array
394395
*
395-
* @param \Magento\Framework\DataObject $item
396+
* @param DataObject $item
396397
* @return $this
397398
* @throws \Exception
398399
*/
399-
public function addItem(\Magento\Framework\DataObject $item)
400+
public function addItem(DataObject $item)
400401
{
401402
$itemId = $this->_getItemId($item);
402403

@@ -417,7 +418,7 @@ public function addItem(\Magento\Framework\DataObject $item)
417418
/**
418419
* Add item that has no id to collection
419420
*
420-
* @param \Magento\Framework\DataObject $item
421+
* @param DataObject $item
421422
* @return $this
422423
*/
423424
protected function _addItem($item)
@@ -429,10 +430,10 @@ protected function _addItem($item)
429430
/**
430431
* Retrieve item id
431432
*
432-
* @param \Magento\Framework\DataObject $item
433-
* @return mixed
433+
* @param DataObject $item
434+
* @return string|int
434435
*/
435-
protected function _getItemId(\Magento\Framework\DataObject $item)
436+
protected function _getItemId(DataObject $item)
436437
{
437438
return $item->getId();
438439
}
@@ -454,7 +455,7 @@ public function getAllIds()
454455
/**
455456
* Remove item from collection by item key
456457
*
457-
* @param mixed $key
458+
* @param string $key
458459
* @return $this
459460
*/
460461
public function removeItemByKey($key)
@@ -542,8 +543,8 @@ public function each($objMethod, $args = [])
542543
/**
543544
* Setting data for all collection items
544545
*
545-
* @param mixed $key
546-
* @param mixed $value
546+
* @param string $key
547+
* @param string|int|null $value
547548
* @return $this
548549
*/
549550
public function setDataToAll($key, $value = null)
@@ -606,7 +607,7 @@ public function setOrder($field, $direction = self::SORT_ORDER_DESC)
606607
*/
607608
public function setItemObjectClass($className)
608609
{
609-
if (!is_a($className, \Magento\Framework\DataObject::class, true)) {
610+
if (!is_a($className, DataObject::class, true)) {
610611
throw new \InvalidArgumentException($className . ' does not extend \Magento\Framework\DataObject');
611612
}
612613
$this->_itemObjectClass = $className;
@@ -616,7 +617,7 @@ public function setItemObjectClass($className)
616617
/**
617618
* Retrieve collection empty item
618619
*
619-
* @return \Magento\Framework\DataObject
620+
* @return DataObject
620621
*/
621622
public function getNewEmptyItem()
622623
{
@@ -748,8 +749,8 @@ public function toArray($arrRequiredFields = [])
748749
* Return items array
749750
* array(
750751
* $index => array(
751-
* 'value' => mixed
752-
* 'label' => mixed
752+
* 'value' => string
753+
* 'label' => string
753754
* )
754755
* )
755756
*
@@ -815,8 +816,8 @@ protected function _toOptionHash($valueField = 'id', $labelField = 'name')
815816
/**
816817
* Retrieve item by id
817818
*
818-
* @param mixed $idValue
819-
* @return \Magento\Framework\DataObject
819+
* @param string|int $idValue
820+
* @return DataObject
820821
*/
821822
public function getItemById($idValue)
822823
{
@@ -910,7 +911,7 @@ public function __sleep()
910911
*/
911912
public function __wakeup()
912913
{
913-
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
914+
$objectManager = ObjectManager::getInstance();
914915
$this->_entityFactory = $objectManager->get(EntityFactoryInterface::class);
915916
}
916917
}

0 commit comments

Comments
 (0)