Skip to content

Commit 8047729

Browse files
committed
Merge remote-tracking branch 'origin/AC-3109-fix-potential-issues-php-p8' into delivery-bunch-w21
2 parents eca2d2b + 9cd49b8 commit 8047729

File tree

11 files changed

+44
-52
lines changed

11 files changed

+44
-52
lines changed

app/code/Magento/Rule/Model/Condition/Product/AbstractProduct.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* phpcs:disable Magento2.Classes.AbstractApi
1616
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
1717
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18+
* phpcs:disable Magento2.Classes.AbstractApi
1819
* @api
1920
* @since 100.0.2
2021
*/
@@ -553,7 +554,7 @@ public function validate(\Magento\Framework\Model\AbstractModel $model)
553554

554555
if ($attr && $attr->getFrontendInput() == 'multiselect') {
555556
$value = $model->getData($attrCode);
556-
$value = strlen($value) ? explode(',', $value) : [];
557+
$value = ($value && strlen($value)) ? explode(',', $value) : [];
557558
return $this->validateAttribute($value);
558559
}
559560

@@ -569,7 +570,7 @@ public function validate(\Magento\Framework\Model\AbstractModel $model)
569570
if ($attr && $attr->getBackendType() == 'datetime') {
570571
$value = strtotime($value);
571572
} elseif ($attr && $attr->getFrontendInput() == 'multiselect') {
572-
$value = strlen($value) ? explode(',', $value) : [];
573+
$value = ($value && strlen($value)) ? explode(',', $value) : [];
573574
}
574575

575576
$model->setData($attrCode, $value);

app/code/Magento/Sales/Block/Adminhtml/Order/Create/Items/Grid.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,26 @@ class Grid extends \Magento\Sales\Block\Adminhtml\Order\Create\AbstractCreate
3030
protected $_moveToCustomerStorage = true;
3131

3232
/**
33-
* Tax data
34-
*
3533
* @var \Magento\Tax\Helper\Data
3634
*/
3735
protected $_taxData;
3836

3937
/**
40-
* Wishlist factory
41-
*
4238
* @var \Magento\Wishlist\Model\WishlistFactory
4339
*/
4440
protected $_wishlistFactory;
4541

4642
/**
47-
* Gift message save
48-
*
4943
* @var \Magento\GiftMessage\Model\Save
5044
*/
5145
protected $_giftMessageSave;
5246

5347
/**
54-
* Tax config
55-
*
5648
* @var \Magento\Tax\Model\Config
5749
*/
5850
protected $_taxConfig;
5951

6052
/**
61-
* Message helper
62-
*
6353
* @var \Magento\GiftMessage\Helper\Message
6454
*/
6555
protected $_messageHelper;
@@ -440,7 +430,7 @@ public function getCustomOptions(Item $item)
440430
$optionStr = '';
441431
$this->_moveToCustomerStorage = true;
442432
if ($optionIds = $item->getOptionByCode('option_ids')) {
443-
foreach (explode(',', $optionIds->getValue()) as $optionId) {
433+
foreach (explode(',', $optionIds->getValue() ?? '') as $optionId) {
444434
$option = $item->getProduct()->getOptionById($optionId);
445435
if ($option) {
446436
$optionStr .= $option->getTitle() . ':';

app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ protected function _isAllowed()
401401
*/
402402
protected function _getAclResource()
403403
{
404-
$action = strtolower($this->getRequest()->getActionName());
404+
$action = strtolower($this->getRequest()->getActionName() ?? '');
405405
if (in_array($action, ['index', 'save', 'cancel']) && $this->_getSession()->getReordered()) {
406406
$action = 'reorder';
407407
}

app/code/Magento/Sales/Controller/Download/DownloadCustomOption.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
use Magento\Catalog\Model\Product\Type\AbstractType;
1515
use Magento\Framework\Controller\Result\ForwardFactory;
1616

17-
/**
18-
* Class DownloadCustomOption
19-
*
20-
* @package Magento\Sales\Controller\Download
21-
*/
2217
class DownloadCustomOption extends \Magento\Framework\App\Action\Action implements HttpGetActionInterface
2318
{
2419
/**
@@ -87,7 +82,7 @@ public function execute()
8782
}
8883

8984
$optionId = null;
90-
if (strpos($option->getCode(), AbstractType::OPTION_PREFIX) === 0) {
85+
if ($option->getCode() && strpos($option->getCode(), AbstractType::OPTION_PREFIX) === 0) {
9186
$optionId = str_replace(AbstractType::OPTION_PREFIX, '', $option->getCode());
9287
if ((int)$optionId != $optionId) {
9388
$optionId = null;

app/code/Magento/Sales/Model/AdminOrder/Create.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ public function moveQuoteItem($item, $moveTo, $qty)
822822
$item = $this->_getQuoteItem($item);
823823
if ($item) {
824824
$removeItem = false;
825-
$moveTo = explode('_', $moveTo);
825+
$moveTo = explode('_', $moveTo ?: '');
826826
switch ($moveTo[0]) {
827827
case 'order':
828828
$info = $item->getBuyRequest();
@@ -1308,7 +1308,7 @@ protected function _prepareOptionsForRequest($item)
13081308
$newInfoOptions = [];
13091309
$optionIds = $item->getOptionByCode('option_ids');
13101310
if ($optionIds) {
1311-
foreach (explode(',', $optionIds->getValue()) as $optionId) {
1311+
foreach (explode(',', $optionIds->getValue() ?? '') as $optionId) {
13121312
$option = $item->getProduct()->getOptionById($optionId);
13131313
$optionValue = $item->getOptionByCode('option_' . $optionId)->getValue();
13141314

app/code/Magento/Sales/Model/Order/Address.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class Address extends AbstractModel implements OrderAddressInterface, AddressMod
2424
/**
2525
* Possible customer address types
2626
*/
27-
const TYPE_BILLING = 'billing';
27+
public const TYPE_BILLING = 'billing';
2828

29-
const TYPE_SHIPPING = 'shipping';
29+
public const TYPE_SHIPPING = 'shipping';
3030

3131
/**
3232
* @var \Magento\Sales\Model\Order
@@ -240,7 +240,7 @@ public function getStreet()
240240
if (is_array($this->getData(OrderAddressInterface::STREET))) {
241241
return $this->getData(OrderAddressInterface::STREET);
242242
}
243-
return explode(PHP_EOL, $this->getData(OrderAddressInterface::STREET));
243+
return explode(PHP_EOL, $this->getData(OrderAddressInterface::STREET) ?? '');
244244
}
245245

246246
/**
@@ -601,7 +601,7 @@ public function setEmail($email)
601601
*/
602602
public function setTelephone($telephone)
603603
{
604-
return $this->setData(OrderAddressInterface::TELEPHONE, trim($telephone));
604+
return $this->setData(OrderAddressInterface::TELEPHONE, trim($telephone ?: ''));
605605
}
606606

607607
/**

app/code/Magento/Sales/Model/Order/Pdf/AbstractPdf.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ protected function insertAddress(&$page, $store = null)
340340
$value = preg_replace('/<br[^>]*>/i', "\n", $value);
341341
foreach ($this->string->split($value, 45, true, true) as $_value) {
342342
$page->drawText(
343-
trim(strip_tags($_value)),
343+
trim(strip_tags($_value ?: '')),
344344
$this->getAlignRight($_value, 130, 440, $font, 10),
345345
$top,
346346
'UTF-8'
@@ -361,7 +361,9 @@ protected function insertAddress(&$page, $store = null)
361361
protected function _formatAddress($address)
362362
{
363363
$return = [];
364-
foreach (explode('|', $address) as $str) {
364+
$values = $address !== null ? explode('|', $address) : [];
365+
366+
foreach ($values as $str) {
365367
foreach ($this->string->split($str, 45, true, true) as $part) {
366368
if (empty($part)) {
367369
continue;
@@ -463,10 +465,10 @@ protected function insertOrder(&$page, $obj, $putOrderId = true)
463465

464466
/* Payment */
465467
$paymentInfo = $this->_paymentData->getInfoBlock($order->getPayment())->setIsSecureMode(true)->toPdf();
466-
$paymentInfo = htmlspecialchars_decode($paymentInfo, ENT_QUOTES);
468+
$paymentInfo = $paymentInfo !== null ? htmlspecialchars_decode($paymentInfo, ENT_QUOTES) : '';
467469
$payment = explode('{{pdf_row_separator}}', $paymentInfo);
468470
foreach ($payment as $key => $value) {
469-
if (strip_tags(trim($value)) == '') {
471+
if ($value && strip_tags(trim($value)) == '') {
470472
unset($payment[$key]);
471473
}
472474
}
@@ -510,7 +512,7 @@ protected function insertOrder(&$page, $obj, $putOrderId = true)
510512
$text[] = $this->rtlTextHandler->reverseRtlText($_value);
511513
}
512514
foreach ($text as $part) {
513-
$page->drawText(strip_tags(ltrim($part)), 35, $this->y, 'UTF-8');
515+
$page->drawText(strip_tags(ltrim($part ?: '')), 35, $this->y, 'UTF-8');
514516
$this->y -= 15;
515517
}
516518
}
@@ -528,7 +530,7 @@ protected function insertOrder(&$page, $obj, $putOrderId = true)
528530
$text[] = $this->rtlTextHandler->reverseRtlText($_value);
529531
}
530532
foreach ($text as $part) {
531-
$page->drawText(strip_tags(ltrim($part)), 285, $this->y, 'UTF-8');
533+
$page->drawText(strip_tags(ltrim($part ?: '')), 285, $this->y, 'UTF-8');
532534
$this->y -= 15;
533535
}
534536
}
@@ -562,11 +564,11 @@ protected function insertOrder(&$page, $obj, $putOrderId = true)
562564
}
563565

564566
foreach ($payment as $value) {
565-
if (trim($value) != '') {
567+
if ($value && trim($value) != '') {
566568
//Printing "Payment Method" lines
567569
$value = preg_replace('/<br[^>]*>/i', "\n", $value);
568570
foreach ($this->string->split($value, 45, true, true) as $_value) {
569-
$page->drawText(strip_tags(trim($_value)), $paymentLeft, $yPayments, 'UTF-8');
571+
$page->drawText(strip_tags(trim($_value ?: '')), $paymentLeft, $yPayments, 'UTF-8');
570572
$yPayments -= 15;
571573
}
572574
}
@@ -587,7 +589,7 @@ protected function insertOrder(&$page, $obj, $putOrderId = true)
587589

588590
if (isset($shippingMethod) && \is_string($shippingMethod)) {
589591
foreach ($this->string->split($shippingMethod, 45, true, true) as $_value) {
590-
$page->drawText(strip_tags(trim($_value)), 285, $this->y, 'UTF-8');
592+
$page->drawText(strip_tags(trim($_value ?: '')), 285, $this->y, 'UTF-8');
591593
$this->y -= 15;
592594
}
593595
}
@@ -623,8 +625,9 @@ protected function insertOrder(&$page, $obj, $putOrderId = true)
623625
$this->_setFontRegular($page, 8);
624626
foreach ($tracks as $track) {
625627
$maxTitleLen = 45;
626-
$endOfTitle = strlen($track->getTitle()) > $maxTitleLen ? '...' : '';
627-
$truncatedTitle = substr($track->getTitle(), 0, $maxTitleLen) . $endOfTitle;
628+
$trackTitle = $track->getTitle() ?? '';
629+
$endOfTitle = strlen($trackTitle) > $maxTitleLen ? '...' : '';
630+
$truncatedTitle = substr($trackTitle, 0, $maxTitleLen) . $endOfTitle;
628631
$page->drawText($truncatedTitle, 292, $yShipments, 'UTF-8');
629632
$page->drawText($track->getNumber(), 410, $yShipments, 'UTF-8');
630633
$yShipments -= $topMargin - 5;

app/code/Magento/Sales/Model/Service/OrderService.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
use Psr\Log\LoggerInterface;
1111

1212
/**
13-
* Class OrderService
14-
*
1513
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1614
*/
1715
class OrderService implements OrderManagementInterface
@@ -141,8 +139,8 @@ public function addComment($id, \Magento\Sales\Api\Data\OrderStatusHistoryInterf
141139
$order = $this->orderRepository->get($id);
142140
$order->addStatusHistory($statusHistory);
143141
$this->orderRepository->save($order);
144-
$notify = isset($statusHistory['is_customer_notified']) ? $statusHistory['is_customer_notified'] : false;
145-
$comment = trim(strip_tags($statusHistory->getComment()));
142+
$notify = $statusHistory['is_customer_notified'] ?? false;
143+
$comment = $statusHistory->getComment() !== null ? trim(strip_tags($statusHistory->getComment())) : '';
146144
$this->orderCommentSender->send($order, $notify, $comment);
147145
return true;
148146
}

app/code/Magento/Sales/Setup/SalesSetup.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Magento\Eav\Setup\EavSetup;
1414
use Magento\Framework\App\CacheInterface;
1515
use Magento\Framework\App\Config\ScopeConfigInterface;
16-
use Magento\Framework\App\ResourceConnection;
1716
use Magento\Framework\Encryption\EncryptorInterface;
1817
use Magento\Framework\Setup\ModuleDataSetupInterface;
1918

@@ -29,22 +28,22 @@ class SalesSetup extends EavSetup
2928
/**
3029
* This should be set explicitly
3130
*/
32-
const ORDER_ENTITY_TYPE_ID = 5;
31+
public const ORDER_ENTITY_TYPE_ID = 5;
3332

3433
/**
3534
* This should be set explicitly
3635
*/
37-
const INVOICE_PRODUCT_ENTITY_TYPE_ID = 6;
36+
public const INVOICE_PRODUCT_ENTITY_TYPE_ID = 6;
3837

3938
/**
4039
* This should be set explicitly
4140
*/
42-
const CREDITMEMO_PRODUCT_ENTITY_TYPE_ID = 7;
41+
public const CREDITMEMO_PRODUCT_ENTITY_TYPE_ID = 7;
4342

4443
/**
4544
* This should be set explicitly
4645
*/
47-
const SHIPMENT_PRODUCT_ENTITY_TYPE_ID = 8;
46+
public const SHIPMENT_PRODUCT_ENTITY_TYPE_ID = 8;
4847

4948
/**
5049
* @var ScopeConfigInterface
@@ -210,7 +209,7 @@ protected function _addGridAttribute($table, $attribute, $attr, $entityTypeId)
210209
protected function _getAttributeColumnDefinition($code, $data)
211210
{
212211
// Convert attribute type to column info
213-
$data['type'] = isset($data['type']) ? $data['type'] : 'varchar';
212+
$data['type'] = $data['type'] ?? 'varchar';
214213
$type = null;
215214
$length = null;
216215
switch ($data['type']) {
@@ -242,12 +241,14 @@ protected function _getAttributeColumnDefinition($code, $data)
242241
$data['length'] = $length;
243242
}
244243

245-
$data['nullable'] = isset($data['required']) ? !$data['required'] : true;
246-
$data['comment'] = isset($data['comment']) ? $data['comment'] : ucwords(str_replace('_', ' ', $code));
244+
$data['nullable'] = !isset($data['required']) || !$data['required'];
245+
$data['comment'] = $data['comment'] ?? $code !== null ? ucwords(str_replace('_', ' ', $code)) : '';
247246
return $data;
248247
}
249248

250249
/**
250+
* Method to get default entities.
251+
*
251252
* @return array
252253
*/
253254
public function getDefaultEntities()
@@ -300,6 +301,8 @@ public function getConfigModel()
300301
}
301302

302303
/**
304+
* Method to get encryptor.
305+
*
303306
* @return EncryptorInterface
304307
*/
305308
public function getEncryptor()
@@ -308,6 +311,8 @@ public function getEncryptor()
308311
}
309312

310313
/**
314+
* Method to get connection.
315+
*
311316
* @return \Magento\Framework\DB\Adapter\AdapterInterface
312317
*/
313318
public function getConnection()

app/code/Magento/Sales/Test/Mftf/Helper/SalesHelper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ private function evaluateIsWebDriverOnExpectedUrl(
107107
string $expectedUrl,
108108
string $expectedUrlComparisonType
109109
): bool {
110-
$currentWebDriverUrlPath = parse_url($webDriver->getCurrentURL(), PHP_URL_PATH);
110+
$currentWebDriverUrlPath = $webDriver->getCurrentURL() !== null ?
111+
parse_url($webDriver->getCurrentURL(), PHP_URL_PATH) : '';
111112

112113
switch ($expectedUrlComparisonType) {
113114
case self::COMPARISON_PATH_EXACT_MATCH:

0 commit comments

Comments
 (0)