Skip to content

Commit 6e70a52

Browse files
anzinandrewbess
authored andcommitted
Fixed php 8.1 deprecations to pass Integration Tests
1 parent 40ceb70 commit 6e70a52

File tree

16 files changed

+105
-60
lines changed

16 files changed

+105
-60
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/AbstractRenderer.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,10 @@ public function renderHeader()
139139
{
140140
if (false !== $this->getColumn()->getSortable()) {
141141
$className = 'not-sort';
142-
$dir = strtolower($this->getColumn()->getDir());
142+
$dir = is_string($this->getColumn()->getDir()) ? strtolower($this->getColumn()->getDir()) : '';
143143
$nDir = $dir == 'asc' ? 'desc' : 'asc';
144-
if ($this->getColumn()->getDir()) {
144+
145+
if ($dir) {
145146
$className = '_' . $dir . 'end';
146147
}
147148
$out = '<th data-sort="' .

app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ class Toolbar extends \Magento\Framework\View\Element\Template
5050
protected $_enableViewSwitcher = true;
5151

5252
/**
53-
* Is Expanded
54-
*
5553
* @var bool
5654
*/
5755
protected $_isExpanded = true;
@@ -89,15 +87,11 @@ class Toolbar extends \Magento\Framework\View\Element\Template
8987
protected $_template = 'Magento_Catalog::product/list/toolbar.phtml';
9088

9189
/**
92-
* Catalog config
93-
*
9490
* @var \Magento\Catalog\Model\Config
9591
*/
9692
protected $_catalogConfig;
9793

9894
/**
99-
* Catalog session
100-
*
10195
* @var \Magento\Catalog\Model\Session
10296
* @deprecated 103.0.1
10397
*/
@@ -308,7 +302,9 @@ public function getCurrentDirection()
308302
}
309303

310304
$directions = ['asc', 'desc'];
311-
$dir = strtolower($this->toolbarMemorizer->getDirection());
305+
$dir = is_string($this->toolbarMemorizer->getDirection()) ?
306+
strtolower($this->toolbarMemorizer->getDirection()) : '';
307+
312308
if (!$dir || !in_array($dir, $directions)) {
313309
$dir = $this->_direction;
314310
}

app/code/Magento/Catalog/Controller/Category/View.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,16 @@
4040
class View extends Action implements HttpGetActionInterface, HttpPostActionInterface
4141
{
4242
/**
43-
* Core registry
44-
*
4543
* @var Registry
4644
*/
4745
protected $_coreRegistry = null;
4846

4947
/**
50-
* Catalog session
51-
*
5248
* @var Session
5349
*/
5450
protected $_catalogSession;
5551

5652
/**
57-
* Catalog design
58-
*
5953
* @var Design
6054
*/
6155
protected $_catalogDesign;
@@ -212,6 +206,7 @@ public function execute()
212206
$result = null;
213207

214208
if ($this->_request->getParam(ActionInterface::PARAM_NAME_URL_ENCODED)) {
209+
//phpcs:ignore Magento2.Legacy.ObsoleteResponse
215210
return $this->resultRedirectFactory->create()->setUrl($this->_redirect->getRedirectUrl());
216211
}
217212
$category = $this->_initCategory();
@@ -240,7 +235,9 @@ public function execute()
240235
$page->addPageLayoutHandles(['type' => $parentPageType], null, false);
241236
}
242237
$page->addPageLayoutHandles(['type' => $pageType], null, false);
243-
$page->addPageLayoutHandles(['displaymode' => strtolower($category->getDisplayMode())], null, false);
238+
$categoryDisplayMode = is_string($category->getDisplayMode()) ?
239+
strtolower($category->getDisplayMode()) : '';
240+
$page->addPageLayoutHandles(['displaymode' => $categoryDisplayMode], null, false);
244241
$page->addPageLayoutHandles(['id' => $category->getId()]);
245242

246243
// apply custom layout update once layout is loaded

app/code/Magento/Catalog/Model/Product/Option.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ class Option extends AbstractExtensibleModel implements ProductCustomOptionInter
4646
protected $optionRepository;
4747

4848
/**
49-
* Option type percent
49+
* Option type percent.
50+
*
51+
* @var string
5052
* @since 101.0.0
5153
*/
5254
protected static $typePercent = 'percent';
@@ -69,7 +71,9 @@ class Option extends AbstractExtensibleModel implements ProductCustomOptionInter
6971
const KEY_IMAGE_SIZE_X = 'image_size_x';
7072
/**#@-*/
7173

72-
/**#@-*/
74+
/**
75+
* @var Product
76+
*/
7377
protected $product;
7478

7579
/**
@@ -1003,9 +1007,10 @@ private function getMetadataPool()
10031007
*/
10041008
private function cleanFileExtensions()
10051009
{
1006-
$rawExtensions = $this->getFileExtension();
1010+
$rawExtensions = is_string($this->getFileExtension()) ? strtolower($this->getFileExtension()) : '';
10071011
$matches = [];
10081012
preg_match_all('/(?<extensions>[a-z0-9]+)/i', strtolower($rawExtensions), $matches);
1013+
10091014
if (!empty($matches)) {
10101015
$extensions = implode(', ', array_unique($matches['extensions']));
10111016
$this->setFileExtension($extensions);

app/code/Magento/Catalog/Model/Product/Option/Type/File/Validator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ protected function getValidatorErrors($errors, $fileInfo, $option)
126126
*/
127127
protected function parseExtensionsString($extensions)
128128
{
129-
if (preg_match_all('/(?<extension>[a-z0-9]+)/si', strtolower($extensions), $matches)) {
129+
$extensions = is_string($extensions) ? strtolower($extensions) : '';
130+
131+
if (preg_match_all('/(?<extension>[a-z0-9]+)/si', $extensions, $matches)) {
130132
return $matches['extension'] ?: null;
131133
}
132134
return null;

app/code/Magento/Catalog/Test/Unit/Block/Product/ProductList/ToolbarTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function testGetCurrentDirection()
198198
{
199199
$direction = 'desc';
200200

201-
$this->memorizer->expects($this->once())
201+
$this->memorizer->expects($this->any())
202202
->method('getDirection')
203203
->willReturn($direction);
204204

app/code/Magento/Catalog/Test/Unit/Controller/Category/ViewTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public function testApplyCustomLayoutUpdate(array $expectedData): void
245245
->willReturnOnConsecutiveCalls(
246246
$expectedData[1][0]['type'] === 'default'
247247
);
248-
$this->category->expects($this->once())
248+
$this->category->expects($this->any())
249249
->method('getDisplayMode')
250250
->willReturn($expectedData[2][0]['displaymode']);
251251
$this->expectationForPageLayoutHandles($expectedData);

app/code/Magento/CustomerImportExport/Model/Import/AbstractCustomer.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
/**
1414
* Import entity abstract customer model
1515
*
16+
* phpcs:disable Magento2.Classes.AbstractApi
1617
* @api
1718
*
1819
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -53,7 +54,9 @@ abstract class AbstractCustomer extends \Magento\ImportExport\Model\Import\Entit
5354

5455
/**#@-*/
5556

56-
/**#@-*/
57+
/**
58+
* @var string[]
59+
*/
5760
protected $_ignoredAttributes = ['website_id', 'store_id',
5861
self::COLUMN_DEFAULT_BILLING, self::COLUMN_DEFAULT_SHIPPING];
5962

@@ -77,7 +80,7 @@ abstract class AbstractCustomer extends \Magento\ImportExport\Model\Import\Entit
7780
protected $needColumnCheck = true;
7881

7982
/**
80-
* {@inheritdoc}
83+
* @var string
8184
*/
8285
protected $masterAttributeCode = '_email';
8386

@@ -264,9 +267,9 @@ public function getCustomerStorage()
264267
*/
265268
protected function getSelectAttrIdByValue(array $attributeParameters, $value)
266269
{
267-
return isset($attributeParameters['options'][strtolower($value)])
268-
? $attributeParameters['options'][strtolower($value)]
269-
: 0;
270+
$value = is_string($value) ? strtolower($value) : '';
271+
272+
return $attributeParameters['options'][$value] ?? 0;
270273
}
271274

272275
/**

app/code/Magento/Dhl/Model/Carrier.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@ class Carrier extends \Magento\Dhl\Model\AbstractDhl implements \Magento\Shippin
166166
protected $string;
167167

168168
/**
169-
* Carrier helper
170-
*
171169
* @var \Magento\Shipping\Helper\Carrier
172170
*/
173171
protected $_carrierHelper;
@@ -1586,7 +1584,7 @@ protected function _doRequest()
15861584
->getRecipientContactCompanyName() : $rawRequest
15871585
->getRecipientContactPersonName();
15881586

1589-
$nodeConsignee->addChild('CompanyName', substr($companyName, 0, 35));
1587+
$nodeConsignee->addChild('CompanyName', is_string($companyName) ? substr($companyName, 0, 35) : '');
15901588

15911589
$address = $rawRequest->getRecipientAddressStreet1() . ' ' . $rawRequest->getRecipientAddressStreet2();
15921590
$address = $this->string->split($address, 35, false, true);
@@ -1610,8 +1608,12 @@ protected function _doRequest()
16101608
$this->getCountryParams($rawRequest->getRecipientAddressCountryCode())->getName()
16111609
);
16121610
$nodeContact = $nodeConsignee->addChild('Contact');
1613-
$nodeContact->addChild('PersonName', substr($rawRequest->getRecipientContactPersonName(), 0, 34));
1614-
$nodeContact->addChild('PhoneNumber', substr($rawRequest->getRecipientContactPhoneNumber(), 0, 24));
1611+
$recipientContactPersonName = is_string($rawRequest->getRecipientContactPersonName()) ?
1612+
substr($rawRequest->getRecipientContactPersonName(), 0, 34) : '';
1613+
$recipientContactPhoneNumber = is_string($rawRequest->getRecipientContactPhoneNumber()) ?
1614+
substr($rawRequest->getRecipientContactPhoneNumber(), 0, 24) : '';
1615+
$nodeContact->addChild('PersonName', $recipientContactPersonName);
1616+
$nodeContact->addChild('PhoneNumber', $recipientContactPhoneNumber);
16151617

16161618
/**
16171619
* Commodity
@@ -1675,8 +1677,12 @@ protected function _doRequest()
16751677
$this->getCountryParams($rawRequest->getShipperAddressCountryCode())->getName()
16761678
);
16771679
$nodeContact = $nodeShipper->addChild('Contact', '', '');
1678-
$nodeContact->addChild('PersonName', substr($rawRequest->getShipperContactPersonName(), 0, 34));
1679-
$nodeContact->addChild('PhoneNumber', substr($rawRequest->getShipperContactPhoneNumber(), 0, 24));
1680+
$shipperContactPersonName = is_string($rawRequest->getShipperContactPersonName()) ?
1681+
substr($rawRequest->getShipperContactPersonName(), 0, 34) : '';
1682+
$shipperContactPhoneNumber = is_string($rawRequest->getShipperContactPhoneNumber()) ?
1683+
substr($rawRequest->getShipperContactPhoneNumber(), 0, 24) : '';
1684+
$nodeContact->addChild('PersonName', $shipperContactPersonName);
1685+
$nodeContact->addChild('PhoneNumber', $shipperContactPhoneNumber);
16801686

16811687
$xml->addChild('LabelImageFormat', 'PDF', '');
16821688

@@ -2080,7 +2086,7 @@ protected function _prepareShippingLabelContent(\SimpleXMLElement $xml)
20802086
*
20812087
* @return bool
20822088
*/
2083-
protected function isDutiable($origCountryId, $destCountryId) : bool
2089+
protected function isDutiable($origCountryId, $destCountryId): bool
20842090
{
20852091
$this->_checkDomesticStatus($origCountryId, $destCountryId);
20862092

app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private function addEmptyOption(array $options)
149149
public function getOptionText($value)
150150
{
151151
$isMultiple = false;
152-
if (strpos($value, ',') !== false) {
152+
if (is_string($value) && strpos($value, ',') !== false) {
153153
$isMultiple = true;
154154
$value = explode(',', $value);
155155
}

0 commit comments

Comments
 (0)