Skip to content

Commit d7e273f

Browse files
anzinandrewbess
authored andcommitted
AC-3109 fixed logic affected by "RFC: Deprecate passing null"
1 parent c60f4cf commit d7e273f

File tree

16 files changed

+88
-127
lines changed

16 files changed

+88
-127
lines changed

app/code/Magento/Catalog/Model/Product/Type/AbstractType.php

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@ abstract class AbstractType
6464
*/
6565
protected $_fileQueue = [];
6666

67-
const CALCULATE_CHILD = 0;
67+
public const CALCULATE_CHILD = 0;
6868

69-
const CALCULATE_PARENT = 1;
69+
public const CALCULATE_PARENT = 1;
7070

7171
/**#@+
7272
* values for shipment type (invoice etc)
7373
*/
74-
const SHIPMENT_SEPARATELY = 1;
74+
public const SHIPMENT_SEPARATELY = 1;
7575

76-
const SHIPMENT_TOGETHER = 0;
76+
public const SHIPMENT_TOGETHER = 0;
7777
/**#@-*/
7878

7979
/**
@@ -82,19 +82,19 @@ abstract class AbstractType
8282
* Full validation - all required options must be set, whole configuration
8383
* must be valid
8484
*/
85-
const PROCESS_MODE_FULL = 'full';
85+
public const PROCESS_MODE_FULL = 'full';
8686

8787
/**
8888
* Process modes
8989
*
9090
* Lite validation - only received options are validated
9191
*/
92-
const PROCESS_MODE_LITE = 'lite';
92+
public const PROCESS_MODE_LITE = 'lite';
9393

9494
/**
9595
* Item options prefix
9696
*/
97-
const OPTION_PREFIX = 'option_';
97+
public const OPTION_PREFIX = 'option_';
9898

9999
/**
100100
* @var \Magento\Framework\Filesystem
@@ -127,8 +127,6 @@ abstract class AbstractType
127127
abstract public function deleteTypeSpecificData(\Magento\Catalog\Model\Product $product);
128128

129129
/**
130-
* Core registry
131-
*
132130
* @var \Magento\Framework\Registry
133131
*/
134132
protected $_coreRegistry;
@@ -146,22 +144,16 @@ abstract public function deleteTypeSpecificData(\Magento\Catalog\Model\Product $
146144
protected $_logger;
147145

148146
/**
149-
* Catalog product type
150-
*
151147
* @var \Magento\Catalog\Model\Product\Type
152148
*/
153149
protected $_catalogProductType;
154150

155151
/**
156-
* Eav config
157-
*
158152
* @var \Magento\Eav\Model\Config
159153
*/
160154
protected $_eavConfig;
161155

162156
/**
163-
* Catalog product option
164-
*
165157
* @var \Magento\Catalog\Model\Product\Option
166158
*/
167159
protected $_catalogProductOption;
@@ -644,7 +636,7 @@ public function checkProductBuyState($product)
644636
foreach ($options as $option) {
645637
if ($option->getIsRequire()) {
646638
$customOption = $product->getCustomOption(self::OPTION_PREFIX . $option->getId());
647-
if (!$customOption || strlen($customOption->getValue()) == 0) {
639+
if (!$customOption || strlen($customOption->getValue() ?? '') == 0) {
648640
$product->setSkipCheckRequiredOption(true);
649641
throw new \Magento\Framework\Exception\LocalizedException(
650642
__('The product has required options. Enter the options and try again.')
@@ -673,7 +665,7 @@ public function getOrderOptions($product)
673665

674666
$optionIds = $product->getCustomOption('option_ids');
675667
if ($optionIds) {
676-
foreach (explode(',', $optionIds->getValue()) as $optionId) {
668+
foreach (explode(',', $optionIds->getValue() ?? '') as $optionId) {
677669
$option = $product->getOptionById($optionId);
678670
if ($option) {
679671
$confItemOption = $product->getCustomOption(self::OPTION_PREFIX . $option->getId());
@@ -824,7 +816,7 @@ public function getOptionSku($product, $sku = '')
824816
}
825817
$optionIds = $product->getCustomOption('option_ids');
826818
if ($optionIds) {
827-
foreach (explode(',', $optionIds->getValue()) as $optionId) {
819+
foreach (explode(',', $optionIds->getValue() ?? '') as $optionId) {
828820
$option = $product->getOptionById($optionId);
829821
if ($option) {
830822
$confItemOption = $product->getCustomOption(self::OPTION_PREFIX . $optionId);

app/code/Magento/Catalog/Model/Product/Type/Price.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Price
2828
/**
2929
* Product price cache tag
3030
*/
31-
const CACHE_TAG = 'PRODUCT_PRICE';
31+
public const CACHE_TAG = 'PRODUCT_PRICE';
3232

3333
/**
3434
* @var array
@@ -43,8 +43,6 @@ class Price
4343
protected $_eventManager;
4444

4545
/**
46-
* Customer session
47-
*
4846
* @var \Magento\Customer\Model\Session
4947
*/
5048
protected $_customerSession;
@@ -55,15 +53,11 @@ class Price
5553
protected $_localeDate;
5654

5755
/**
58-
* Store manager
59-
*
6056
* @var \Magento\Store\Model\StoreManagerInterface
6157
*/
6258
protected $_storeManager;
6359

6460
/**
65-
* Rule factory
66-
*
6761
* @var \Magento\CatalogRule\Model\ResourceModel\RuleFactory
6862
*/
6963
protected $_ruleFactory;
@@ -386,7 +380,7 @@ public function getTierPrices($product)
386380
if (isset($price['percentage_value'])) {
387381
$tierPrice->getExtensionAttributes()->setPercentageValue($price['percentage_value']);
388382
}
389-
$websiteId = isset($price['website_id']) ? $price['website_id'] : $this->getWebsiteForPriceScope();
383+
$websiteId = $price['website_id'] ?? $this->getWebsiteForPriceScope();
390384
$tierPrice->getExtensionAttributes()->setWebsiteId($websiteId);
391385
$prices[] = $tierPrice;
392386
}
@@ -480,10 +474,10 @@ public function getTierPriceCount($product)
480474
/**
481475
* Get formatted by currency tier price
482476
*
483-
* @param float $qty
484-
* @param Product $product
477+
* @param float $qty
478+
* @param Product $product
485479
*
486-
* @return array|float
480+
* @return array|float
487481
* @since 102.0.6
488482
*/
489483
public function getFormattedTierPrice($qty, $product)
@@ -521,8 +515,9 @@ public function getFormatedTierPrice($qty, $product)
521515
/**
522516
* Get formatted by currency product price
523517
*
524-
* @param Product $product
525-
* @return array|float
518+
* @param Product $product
519+
*
520+
* @return array|float
526521
* @since 102.0.6
527522
*/
528523
public function getFormattedPrice($product)
@@ -558,7 +553,7 @@ protected function _applyOptionsPrice($product, $qty, $finalPrice)
558553
$optionIds = $product->getCustomOption('option_ids');
559554
if ($optionIds) {
560555
$basePrice = $finalPrice;
561-
foreach (explode(',', $optionIds->getValue()) as $optionId) {
556+
foreach (explode(',', $optionIds->getValue() ?? '') as $optionId) {
562557
if ($option = $product->getOptionById($optionId)) {
563558
$confItemOption = $product->getCustomOption('option_' . $option->getId());
564559

app/code/Magento/Catalog/Model/ProductIdLocator.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ class ProductIdLocator implements \Magento\Catalog\Model\ProductIdLocatorInterfa
1919
private $idsLimit;
2020

2121
/**
22-
* Metadata pool.
23-
*
2422
* @var \Magento\Framework\EntityManager\MetadataPool
2523
*/
2624
private $metadataPool;
@@ -74,12 +72,13 @@ public function __construct(
7472
* $data['product_sku']['link_field_value' => 'product_type']
7573
*
7674
* @throws \Exception
75+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
7776
*/
7877
public function retrieveProductIdsBySkus(array $skus)
7978
{
8079
$neededSkus = [];
8180
foreach ($skus as $sku) {
82-
$unifiedSku = strtolower(trim($sku));
81+
$unifiedSku = $sku !== null ? strtolower(trim($sku)) : '';
8382
if (!isset($this->idsBySku[$unifiedSku])) {
8483
$neededSkus[] = $sku;
8584
}
@@ -97,7 +96,7 @@ public function retrieveProductIdsBySkus(array $skus)
9796
for ($currentPage = 1; $currentPage <= $pages; $currentPage++) {
9897
$collection->setCurPage($currentPage);
9998
foreach ($collection->getItems() as $item) {
100-
$sku = strtolower(trim($item->getSku()));
99+
$sku = $item->getSku() !== null ? strtolower(trim($item->getSku())) : '';
101100
$itemIdentifier = $item->getData($linkField);
102101
$this->idsBySku[$sku][$itemIdentifier] = $item->getTypeId();
103102
}
@@ -107,7 +106,7 @@ public function retrieveProductIdsBySkus(array $skus)
107106

108107
$productIds = [];
109108
foreach ($skus as $sku) {
110-
$unifiedSku = strtolower(trim($sku));
109+
$unifiedSku = $sku !== null ? strtolower(trim($sku)) : '';
111110
if (isset($this->idsBySku[$unifiedSku])) {
112111
$productIds[$sku] = $this->idsBySku[$unifiedSku];
113112
}

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ private function joinPositionField(
936936
foreach ($filterGroup->getFilters() as $filter) {
937937
if ($filter->getField() === 'category_id') {
938938
$filterValue = $filter->getValue();
939-
$categoryIds[] = is_array($filterValue) ? $filterValue : explode(',', $filterValue);
939+
$categoryIds[] = is_array($filterValue) ? $filterValue : explode(',', $filterValue ?? '');
940940
}
941941
}
942942
}

app/code/Magento/Catalog/Model/ResourceModel/Category/Flat.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,16 @@
1717
class Flat extends \Magento\Indexer\Model\ResourceModel\AbstractResource
1818
{
1919
/**
20-
* Store id
21-
*
2220
* @var int
2321
*/
2422
protected $_storeId;
2523

2624
/**
27-
* Loaded
28-
*
2925
* @var boolean
3026
*/
3127
protected $_loaded = false;
3228

3329
/**
34-
* Nodes
35-
*
3630
* @var array
3731
*/
3832
protected $_nodes = [];
@@ -52,30 +46,22 @@ class Flat extends \Magento\Indexer\Model\ResourceModel\AbstractResource
5246
protected $_eventManager;
5347

5448
/**
55-
* Catalog config
56-
*
5749
* @var \Magento\Catalog\Model\Config
5850
*/
5951
protected $_catalogConfig;
6052

6153
/**
62-
* Store manager
63-
*
6454
* @var \Magento\Store\Model\StoreManagerInterface
6555
*/
6656
protected $_storeManager;
6757

6858
/**
69-
* Category collection factory
70-
*
7159
* @var \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory
7260
* @deprecated 100.0.2
7361
*/
7462
protected $_categoryCollectionFactory;
7563

7664
/**
77-
* Category factory
78-
*
7965
* @var \Magento\Catalog\Model\CategoryFactory
8066
*/
8167
protected $_categoryFactory;
@@ -370,7 +356,7 @@ public function getNodes($parentId, $recursionLevel = 0, $storeId = 0)
370356
$nodes = $this->_loadNodes($parentNode, $recursionLevel, $storeId);
371357
$childrenItems = [];
372358
foreach ($nodes as $node) {
373-
$pathToParent = explode('/', $node->getPath());
359+
$pathToParent = explode('/', $node->getPath() ?? '');
374360
array_pop($pathToParent);
375361
$pathToParent = implode('/', $pathToParent);
376362
$childrenItems[$pathToParent][] = $node;

app/code/Magento/Catalog/Model/ResourceModel/Category/Tree.php

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
*/
1717
class Tree extends Dbp
1818
{
19-
const ID_FIELD = 'id';
19+
public const ID_FIELD = 'id';
2020

21-
const PATH_FIELD = 'path';
21+
public const PATH_FIELD = 'path';
2222

23-
const ORDER_FIELD = 'order';
23+
public const ORDER_FIELD = 'order';
2424

25-
const LEVEL_FIELD = 'level';
25+
public const LEVEL_FIELD = 'level';
2626

2727
/**
2828
* @var array
@@ -52,22 +52,16 @@ class Tree extends Dbp
5252
protected $_collection;
5353

5454
/**
55-
* Join URL rewrites data to collection flag
56-
*
5755
* @var boolean
5856
*/
5957
protected $_joinUrlRewriteIntoCollection = false;
6058

6159
/**
62-
* Inactive categories ids
63-
*
6460
* @var array
6561
*/
6662
protected $_inactiveCategoryIds = null;
6763

6864
/**
69-
* Store id
70-
*
7165
* @var integer
7266
*/
7367
protected $_storeId = null;
@@ -78,22 +72,16 @@ class Tree extends Dbp
7872
protected $_coreResource;
7973

8074
/**
81-
* Store manager
82-
*
8375
* @var \Magento\Store\Model\StoreManagerInterface
8476
*/
8577
protected $_storeManager;
8678

8779
/**
88-
* Cache
89-
*
9080
* @var \Magento\Framework\App\CacheInterface
9181
*/
9282
protected $_cache;
9383

9484
/**
95-
* Catalog category
96-
*
9785
* @var \Magento\Catalog\Model\ResourceModel\Category
9886
*/
9987
protected $_catalogCategory;
@@ -487,7 +475,7 @@ public function loadByIds($ids, $addCollectionData = true, $updateAnchorProductC
487475
$where = [$levelField . '=0' => true];
488476

489477
foreach ($this->_conn->fetchAll($select) as $item) {
490-
$pathIds = explode('/', $item['path']);
478+
$pathIds = explode('/', $item['path'] ?? '');
491479
$level = (int)$item['level'];
492480
while ($level > 0) {
493481
$pathIds[count($pathIds) - 1] = '%';
@@ -518,7 +506,7 @@ public function loadByIds($ids, $addCollectionData = true, $updateAnchorProductC
518506
}
519507
$childrenItems = [];
520508
foreach ($arrNodes as $key => $nodeInfo) {
521-
$pathToParent = explode('/', $nodeInfo[$this->_pathField]);
509+
$pathToParent = explode('/', $nodeInfo[$this->_pathField] ?? '');
522510
array_pop($pathToParent);
523511
$pathToParent = implode('/', $pathToParent);
524512
$childrenItems[$pathToParent][] = $nodeInfo;
@@ -537,7 +525,7 @@ public function loadByIds($ids, $addCollectionData = true, $updateAnchorProductC
537525
*/
538526
public function loadBreadcrumbsArray($path, $addCollectionData = true, $withRootNode = false)
539527
{
540-
$pathIds = explode('/', $path);
528+
$pathIds = explode('/', $path ?: '');
541529
if (!$withRootNode) {
542530
array_shift($pathIds);
543531
}

0 commit comments

Comments
 (0)