Skip to content

Commit c29e938

Browse files
committed
Merge remote-tracking branch 'karyna/fix-webapi-for-php8.1' into ph-delivery
2 parents ca9e71f + 1ece084 commit c29e938

File tree

17 files changed

+113
-106
lines changed

17 files changed

+113
-106
lines changed

app/code/Magento/Catalog/Helper/Image.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
*
1717
* @api
1818
* @SuppressWarnings(PHPMD.TooManyFields)
19+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1920
* @since 100.0.2
2021
*/
2122
class Image extends AbstractHelper implements ArgumentInterface
2223
{
2324
/**
2425
* Media config node
2526
*/
26-
const MEDIA_TYPE_CONFIG_NODE = 'images';
27+
public const MEDIA_TYPE_CONFIG_NODE = 'images';
2728

2829
/**
2930
* Current model
@@ -47,8 +48,6 @@ class Image extends AbstractHelper implements ArgumentInterface
4748
protected $_scheduleRotate = false;
4849

4950
/**
50-
* Angle
51-
*
5251
* @var int
5352
*/
5453
protected $_angle;
@@ -61,22 +60,16 @@ class Image extends AbstractHelper implements ArgumentInterface
6160
protected $_watermark;
6261

6362
/**
64-
* Watermark Position
65-
*
6663
* @var string
6764
*/
6865
protected $_watermarkPosition;
6966

7067
/**
71-
* Watermark Size
72-
*
7368
* @var string
7469
*/
7570
protected $_watermarkSize;
7671

7772
/**
78-
* Watermark Image opacity
79-
*
8073
* @var int
8174
*/
8275
protected $_watermarkImageOpacity;
@@ -89,8 +82,6 @@ class Image extends AbstractHelper implements ArgumentInterface
8982
protected $_product;
9083

9184
/**
92-
* Image File
93-
*
9485
* @var string
9586
*/
9687
protected $_imageFile;
@@ -108,8 +99,6 @@ class Image extends AbstractHelper implements ArgumentInterface
10899
protected $_assetRepo;
109100

110101
/**
111-
* Product image factory
112-
*
113102
* @var \Magento\Catalog\Model\Product\ImageFactory
114103
*/
115104
protected $_productImageFactory;
@@ -787,8 +776,8 @@ protected function getImageFile()
787776
*/
788777
protected function parseSize($string)
789778
{
790-
$size = explode('x', strtolower($string));
791-
if (count($size) == 2) {
779+
$size = $string !== null ? explode('x', strtolower($string)) : [];
780+
if (count($size) === 2) {
792781
return ['width' => $size[0] > 0 ? $size[0] : null, 'height' => $size[1] > 0 ? $size[1] : null];
793782
}
794783
return false;

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

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,33 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements
4848
* Entity code.
4949
* Can be used as part of method name for entity processing
5050
*/
51-
const ENTITY = 'catalog_category';
51+
public const ENTITY = 'catalog_category';
5252

5353
/**#@+
5454
* Category display modes
5555
*/
56-
const DM_PRODUCT = 'PRODUCTS';
56+
public const DM_PRODUCT = 'PRODUCTS';
5757

58-
const DM_PAGE = 'PAGE';
58+
public const DM_PAGE = 'PAGE';
5959

60-
const DM_MIXED = 'PRODUCTS_AND_PAGE';
60+
public const DM_MIXED = 'PRODUCTS_AND_PAGE';
6161
/**#@-*/
6262

6363
/**
6464
* Id of root category
6565
*/
66-
const ROOT_CATEGORY_ID = 0;
66+
public const ROOT_CATEGORY_ID = 0;
6767

6868
/**
6969
* Id of category tree root
7070
*/
71-
const TREE_ROOT_ID = 1;
71+
public const TREE_ROOT_ID = 1;
7272

73-
const CACHE_TAG = 'cat_c';
73+
public const CACHE_TAG = 'cat_c';
7474

75-
/**#@-*/
75+
/**
76+
* @var string
77+
*/
7678
protected $_eventPrefix = 'catalog_category';
7779

7880
/**
@@ -157,29 +159,21 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements
157159
protected $filter;
158160

159161
/**
160-
* Catalog config
161-
*
162162
* @var \Magento\Catalog\Model\Config
163163
*/
164164
protected $_catalogConfig;
165165

166166
/**
167-
* Product collection factory
168-
*
169167
* @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
170168
*/
171169
protected $_productCollectionFactory;
172170

173171
/**
174-
* Store collection factory
175-
*
176172
* @var \Magento\Store\Model\ResourceModel\Store\CollectionFactory
177173
*/
178174
protected $_storeCollectionFactory;
179175

180176
/**
181-
* Category tree factory
182-
*
183177
* @var \Magento\Catalog\Model\ResourceModel\Category\TreeFactory
184178
*/
185179
protected $_categoryTreeFactory;
@@ -852,7 +846,7 @@ public function getPathIds()
852846
{
853847
$ids = $this->getData('path_ids');
854848
if ($ids === null) {
855-
$ids = explode('/', $this->getPath());
849+
$ids = $this->getPath() ? explode('/', $this->getPath()) : [];
856850
$this->setData('path_ids', $ids);
857851
}
858852
return $ids;
@@ -866,7 +860,7 @@ public function getPathIds()
866860
public function getLevel()
867861
{
868862
if (!$this->hasLevel()) {
869-
return count(explode('/', $this->getPath())) - 1;
863+
return $this->getPath() ? count(explode('/', $this->getPath())) - 1 : 0;
870864
}
871865
return $this->getData(self::KEY_LEVEL);
872866
}

app/code/Magento/Catalog/Model/View/Asset/Image.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ public function getPath()
201201
*/
202202
public function getSourceFile()
203203
{
204-
return $this->mediaConfig->getBaseMediaPath()
205-
. DIRECTORY_SEPARATOR . ltrim($this->getFilePath(), DIRECTORY_SEPARATOR);
204+
$path = $this->getFilePath() ? ltrim($this->getFilePath(), DIRECTORY_SEPARATOR) : '';
205+
return $this->mediaConfig->getBaseMediaPath() . DIRECTORY_SEPARATOR . $path;
206206
}
207207

208208
/**

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/DataProvider.php

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,11 @@ class DataProvider
6969
private $productAttributeCollectionFactory;
7070

7171
/**
72-
* Eav config
73-
*
7472
* @var Config
7573
*/
7674
private $eavConfig;
7775

7876
/**
79-
* Catalog product type
80-
*
8177
* @var Type
8278
*/
8379
private $catalogProductType;
@@ -90,8 +86,6 @@ class DataProvider
9086
private $eventManager;
9187

9288
/**
93-
* Store manager
94-
*
9589
* @var StoreManagerInterface
9690
*/
9791
private $storeManager;
@@ -155,6 +149,7 @@ class DataProvider
155149
* @param int $antiGapMultiplier
156150
* @param GetSearchableProductsSelect|null $getSearchableProductsSelect
157151
* @throws Exception
152+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
158153
*/
159154
public function __construct(
160155
ResourceConnection $resource,
@@ -178,7 +173,8 @@ public function __construct(
178173
$this->engine = $engineProvider->get();
179174
$this->metadata = $metadataPool->getMetadata(ProductInterface::class);
180175
$this->antiGapMultiplier = $antiGapMultiplier;
181-
$this->selectSearchableProducts = $getSearchableProductsSelect ?: ObjectManager::getInstance()->get(GetSearchableProductsSelect::class);
176+
$this->selectSearchableProducts = $getSearchableProductsSelect ?:
177+
ObjectManager::getInstance()->get(GetSearchableProductsSelect::class);
182178
}
183179

184180
/**
@@ -210,7 +206,13 @@ public function getSearchableProducts(
210206
$lastProductId = 0,
211207
$batch = 100
212208
) {
213-
$select = $this->selectSearchableProducts->execute((int)$storeId, $staticFields, $productIds, $lastProductId, $batch);
209+
$select = $this->selectSearchableProducts->execute(
210+
(int) $storeId,
211+
$staticFields,
212+
$productIds,
213+
$lastProductId,
214+
$batch
215+
);
214216
if ($productIds === null) {
215217
$select->where(
216218
'e.entity_id < ?',
@@ -221,7 +223,13 @@ public function getSearchableProducts(
221223
if ($productIds === null && !$products) {
222224
// try to search without limit entity_id by batch size for cover case with a big gap between entity ids
223225
$products = $this->connection->fetchAll(
224-
$this->selectSearchableProducts->execute((int)$storeId, $staticFields, $productIds, $lastProductId, $batch)
226+
$this->selectSearchableProducts->execute(
227+
(int) $storeId,
228+
$staticFields,
229+
$productIds,
230+
$lastProductId,
231+
$batch
232+
)
225233
);
226234
}
227235

@@ -576,12 +584,14 @@ private function getAttributeValue($attributeId, $valueIds, $storeId)
576584
* @param int $attributeId
577585
* @param int|string $valueIds
578586
* @param int $storeId
587+
*
579588
* @return null|string
589+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
580590
*/
581591
private function getAttributeOptionValue($attributeId, $valueIds, $storeId)
582592
{
583593
$optionKey = $attributeId . '-' . $storeId;
584-
$attributeValueIds = explode(',', $valueIds);
594+
$attributeValueIds = $valueIds !== null ? explode(',', $valueIds) : [];
585595
$attributeOptionValue = '';
586596
if (!array_key_exists($optionKey, $this->attributeOptions)
587597
) {
@@ -615,11 +625,11 @@ function ($value) {
615625
/**
616626
* Remove whitespaces and tags from attribute value
617627
*
618-
* @param string $value
628+
* @param string|null $value
619629
* @return string
620630
*/
621-
private function filterAttributeValue($value)
631+
private function filterAttributeValue(?string $value)
622632
{
623-
return preg_replace('/\s+/iu', ' ', trim(strip_tags($value)));
633+
return $value !== null ? preg_replace('/\s+/iu', ' ', trim(strip_tags($value))) : '';
624634
}
625635
}

app/code/Magento/Indexer/Console/Command/IndexerReindexCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
115115
$resultTime = microtime(true) - $startTime;
116116

117117
$output->writeln(
118-
__('has been rebuilt successfully in %time', ['time' => gmdate('H:i:s', $resultTime)])
118+
__('has been rebuilt successfully in %time', ['time' => gmdate('H:i:s', (int) $resultTime)])
119119
);
120120
} catch (\Throwable $e) {
121121
$output->writeln('process error during indexation process:');

app/code/Magento/Quote/Model/Quote/Address.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@
132132
class Address extends AbstractAddress implements
133133
\Magento\Quote\Api\Data\AddressInterface
134134
{
135-
const RATES_FETCH = 1;
135+
public const RATES_FETCH = 1;
136136

137-
const RATES_RECALCULATE = 2;
137+
public const RATES_RECALCULATE = 2;
138138

139-
const ADDRESS_TYPE_BILLING = 'billing';
139+
public const ADDRESS_TYPE_BILLING = 'billing';
140140

141-
const ADDRESS_TYPE_SHIPPING = 'shipping';
141+
public const ADDRESS_TYPE_SHIPPING = 'shipping';
142142

143143
private const CACHED_ITEMS_ALL = 'cached_items_all';
144144

@@ -553,6 +553,7 @@ public function importCustomerAddressData(AddressInterface $address)
553553
);
554554

555555
$quote = $this->getQuote();
556+
// @phpstan-ignore-next-line as $quote can be empty
556557
if ($address->getCustomerId() && (!empty($quote) && $address->getCustomerId() == $quote->getCustomerId())) {
557558
$customer = $quote->getCustomer();
558559
$this->setEmail($customer->getEmail());
@@ -1451,7 +1452,8 @@ public function setCountryId($countryId)
14511452
*/
14521453
public function getStreet()
14531454
{
1454-
$street = $this->getData(self::KEY_STREET);
1455+
$street = $this->getData(self::KEY_STREET) ?? [''];
1456+
14551457
return is_array($street) ? $street : explode("\n", $street);
14561458
}
14571459

app/code/Magento/Quote/Model/Quote/TotalsCollector.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ class TotalsCollector
5353
protected $collectorList;
5454

5555
/**
56-
* Quote validator
57-
*
5856
* @var \Magento\Quote\Model\QuoteValidator
5957
*/
6058
protected $quoteValidator;
@@ -194,7 +192,7 @@ public function collect(\Magento\Quote\Model\Quote $quote)
194192
protected function _validateCouponCode(\Magento\Quote\Model\Quote $quote)
195193
{
196194
$code = $quote->getData('coupon_code');
197-
if (strlen($code)) {
195+
if ($code !== null && strlen($code)) {
198196
$addressHasCoupon = false;
199197
$addresses = $quote->getAllAddresses();
200198
if (count($addresses) > 0) {

0 commit comments

Comments
 (0)