Skip to content

Commit

Permalink
AC-3109 fixed logic affected by "RFC: Deprecate passing null"
Browse files Browse the repository at this point in the history
  • Loading branch information
anzin authored and Andrii Beziazychnyi committed May 26, 2022
1 parent 9661597 commit f629205
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ class RelativePathConverter
* @param string $relativePath
* @return string
* @throws \InvalidArgumentException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function convert($nodePath, $relativePath)
{
$nodePath = trim($nodePath);
$relativePath = trim($relativePath);
$nodePath = $nodePath !== null ? trim($nodePath) : '';
$relativePath = $relativePath !== null ? trim($relativePath) : '';

if (empty($nodePath) || empty($relativePath)) {
throw new \InvalidArgumentException('Invalid arguments');
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Config/Setup/Patch/Data/UnsetTinymce3.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace Magento\Config\Setup\Patch\Data;

use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchVersionInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

/**
* Update config to Tinymce4 if Tinymce3 adapter is used.
Expand Down Expand Up @@ -46,7 +46,7 @@ public function apply()
)
->where('path = ?', 'cms/wysiwyg/editor');

if (strpos($connection->fetchOne($select), 'Tinymce3/tinymce3Adapter') !== false) {
if (strpos($connection->fetchOne($select) ?? '', 'Tinymce3/tinymce3Adapter') !== false) {
$row = [
'value' => 'mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter'
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php
/**
* Import entity configurable product type model
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
Expand All @@ -25,21 +23,21 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ
/**
* Error codes.
*/
const ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST = 'attrCodeDoesNotExist';
public const ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST = 'attrCodeDoesNotExist';

const ERROR_ATTRIBUTE_CODE_NOT_GLOBAL_SCOPE = 'attrCodeNotGlobalScope';
public const ERROR_ATTRIBUTE_CODE_NOT_GLOBAL_SCOPE = 'attrCodeNotGlobalScope';

const ERROR_ATTRIBUTE_CODE_NOT_TYPE_SELECT = 'attrCodeNotTypeSelect';
public const ERROR_ATTRIBUTE_CODE_NOT_TYPE_SELECT = 'attrCodeNotTypeSelect';

const ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER = 'attrCodeIsNotSuper';
public const ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER = 'attrCodeIsNotSuper';

const ERROR_INVALID_OPTION_VALUE = 'invalidOptionValue';
public const ERROR_INVALID_OPTION_VALUE = 'invalidOptionValue';

const ERROR_INVALID_WEBSITE = 'invalidSuperAttrWebsite';
public const ERROR_INVALID_WEBSITE = 'invalidSuperAttrWebsite';

const ERROR_DUPLICATED_VARIATIONS = 'duplicatedVariations';
public const ERROR_DUPLICATED_VARIATIONS = 'duplicatedVariations';

const ERROR_UNIDENTIFIABLE_VARIATION = 'unidentifiableVariation';
public const ERROR_UNIDENTIFIABLE_VARIATION = 'unidentifiableVariation';

/**
* Validation failure message template definitions
Expand Down Expand Up @@ -170,15 +168,11 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ
protected $_productColFac;

/**
* Product data.
*
* @var array
*/
protected $_productData;

/**
* Product super data.
*
* @var array
*/
protected $_productSuperData;
Expand All @@ -191,8 +185,6 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ
protected $_simpleIdsToDelete;

/**
* Super attributes data.
*
* @var array
*/
protected $_superAttributesData;
Expand All @@ -205,8 +197,6 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ
protected $_nextAttrId;

/**
* Product entity identifier field
*
* @var string
*/
private $productEntityIdentifierField;
Expand Down Expand Up @@ -449,8 +439,8 @@ protected function _loadSkuSuperDataForBunch(array $bunch)
$oldSku = $this->_entityModel->getOldSku();
$productIds = [];
foreach ($bunch as $rowData) {
$sku = strtolower($rowData[ImportProduct::COL_SKU]);
$productData = isset($newSku[$sku]) ? $newSku[$sku] : $oldSku[$sku];
$sku = isset($rowData[ImportProduct::COL_SKU]) ? strtolower($rowData[ImportProduct::COL_SKU]) : '';
$productData = $newSku[$sku] ?? $oldSku[$sku];
$productIds[] = $productData[$this->getProductEntityLinkField()];
}

Expand Down Expand Up @@ -574,10 +564,10 @@ protected function _parseVariations($rowData)
$fieldAndValuePairs = [];
foreach ($fieldAndValuePairsText as $nameAndValue) {
$nameAndValue = explode(ImportProduct::PAIR_NAME_VALUE_SEPARATOR, $nameAndValue, 2);
if (!empty($nameAndValue)) {
if ($nameAndValue) {
$value = isset($nameAndValue[1]) ? trim($nameAndValue[1]) : '';
// Ignoring field names' case.
$fieldName = strtolower(trim($nameAndValue[0]));
$fieldName = isset($nameAndValue[0]) ? strtolower(trim($nameAndValue[0])) : '';
if ($fieldName) {
$fieldAndValuePairs[$fieldName] = $value;
}
Expand All @@ -588,7 +578,7 @@ protected function _parseVariations($rowData)
$position = 0;
$additionalRow['_super_products_sku'] = strtolower($fieldAndValuePairs['sku']);
unset($fieldAndValuePairs['sku']);
$additionalRow['display'] = isset($fieldAndValuePairs['display']) ? $fieldAndValuePairs['display'] : 1;
$additionalRow['display'] = $fieldAndValuePairs['display'] ?? 1;
unset($fieldAndValuePairs['display']);
foreach ($fieldAndValuePairs as $attrCode => $attrValue) {
$additionalRow['_super_attribute_code'] = $attrCode;
Expand Down Expand Up @@ -635,9 +625,9 @@ protected function _parseVariationLabels($rowData)

foreach ($pairFieldAndValue as $nameAndValue) {
$nameAndValue = explode(ImportProduct::PAIR_NAME_VALUE_SEPARATOR, $nameAndValue);
if (!empty($nameAndValue)) {
if ($nameAndValue) {
$value = isset($nameAndValue[1]) ? trim($nameAndValue[1]) : '';
$attrCode = trim($nameAndValue[0]);
$attrCode = isset($nameAndValue[0]) ? trim($nameAndValue[0]) : '';
if ($attrCode) {
$labels[$attrCode] = $value;
}
Expand Down Expand Up @@ -790,8 +780,10 @@ protected function _collectAssocIds($data)
if (isset($data['display']) && $data['display'] == 0) {
$this->_simpleIdsToDelete[] = $superProductRowId;
} else {
$this->_productSuperData['assoc_ids'][$superProductRowId] = true;
$this->_productSuperData['assoc_entity_ids'][$superProductRowId] = $superProductEntityId;
if (isset($superProductEntityId)) {
$this->_productSuperData['assoc_ids'][$superProductRowId] = true;
$this->_productSuperData['assoc_entity_ids'][$superProductRowId] = $superProductEntityId;
}
}
}
}
Expand All @@ -814,9 +806,7 @@ protected function _collectSuperDataLabels($data, $productSuperAttrId, $productI
'product_super_attribute_id' => $productSuperAttrId,
'position' => $data['_super_attribute_position'],
];
$label = isset($variationLabels[$data['_super_attribute_code']])
? $variationLabels[$data['_super_attribute_code']]
: $attrParams['frontend_label'];
$label = $variationLabels[$data['_super_attribute_code']] ?? $attrParams['frontend_label'];
$this->_superAttributesData['labels'][$productSuperAttrId] = [
'product_super_attribute_id' => $productSuperAttrId,
'store_id' => 0,
Expand Down Expand Up @@ -868,7 +858,7 @@ public function saveData()
if (ImportProduct::SCOPE_DEFAULT == $scope &&
!empty($rowData[ImportProduct::COL_SKU])) {
$sku = strtolower($rowData[ImportProduct::COL_SKU]);
$this->_productData = isset($newSku[$sku]) ? $newSku[$sku] : $oldSku[$sku];
$this->_productData = $newSku[$sku] ?? $oldSku[$sku];

if ($this->_type != $this->_productData['type_id']) {
$this->_productData = null;
Expand Down Expand Up @@ -898,7 +888,7 @@ protected function configurableInBunch($bunch)
{
$newSku = $this->_entityModel->getNewSku();
foreach ($bunch as $rowNum => $rowData) {
$productData = $newSku[strtolower($rowData[ImportProduct::COL_SKU])];
$productData = $newSku[strtolower($rowData[ImportProduct::COL_SKU] ?? '')];
if (($this->_type == $productData['type_id']) &&
($rowData == $this->_entityModel->isRowAllowedToImport($rowData, $rowNum))
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ protected function _prepareForm()
$fieldsToRemove = ['attribute_code', 'is_unique', 'frontend_class'];

foreach ($fieldset->getElements() as $element) {
$elementId = $element->getId() ?? '';

/** @var \Magento\Framework\Data\Form\AbstractForm $element */
if (substr($element->getId(), 0, strlen('default_value')) == 'default_value') {
$fieldsToRemove[] = $element->getId();
if (substr($elementId, 0, strlen('default_value')) == 'default_value') {
$fieldsToRemove[] = $elementId;
}
}
foreach ($fieldsToRemove as $id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ protected function getOptionImages()
'caption' => $image->getLabel(),
'position' => $image->getPosition(),
'isMain' => $image->getFile() == $product->getImage(),
'type' => str_replace('external-', '', $image->getMediaType()),
'type' => $image->getMediaType() ? str_replace('external-', '', $image->getMediaType()) : '',
'videoUrl' => $image->getVideoUrl(),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p
* to be sure that it will be unique as its parent
*/
if ($optionIds = $product->getCustomOption('option_ids')) {
$optionIds = explode(',', $optionIds->getValue());
$optionIds = explode(',', $optionIds->getValue() ?? '');
foreach ($optionIds as $optionId) {
if ($option = $product->getCustomOption('option_' . $optionId)) {
$_result[0]->addCustomOption('option_' . $optionId, $option->getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public function extract(array $selectionUids): array
{
$attributeOption = [];
foreach ($selectionUids as $uid) {
$optionData = explode(self::UID_SEPARATOR, $this->idEncoder->decode($uid));
$decodedUid = $this->idEncoder->decode($uid);
$optionData = $decodedUid !== null ? explode(self::UID_SEPARATOR, $decodedUid) : [];
if (count($optionData) === 3) {
$attributeOption[(int)$optionData[1]] = (int)$optionData[2];
}
Expand Down
8 changes: 4 additions & 4 deletions app/code/Magento/Cron/Model/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function _construct()
*/
public function setCronExpr($expr)
{
$e = preg_split('#\s+#', $expr, -1, PREG_SPLIT_NO_EMPTY);
$e = $expr !== null ? preg_split('#\s+#', $expr, -1, PREG_SPLIT_NO_EMPTY) : [];
if (count($e) < 5 || count($e) > 6) {
throw new CronException(__('Invalid cron expression: %1', $expr));
}
Expand Down Expand Up @@ -164,7 +164,7 @@ public function matchCronExpression($expr, $num)
}

// handle multiple options
if (strpos($expr, ',') !== false) {
if ($expr && strpos($expr, ',') !== false) {
foreach (explode(',', $expr) as $e) {
if ($this->matchCronExpression($e, $num)) {
return true;
Expand All @@ -174,7 +174,7 @@ public function matchCronExpression($expr, $num)
}

// handle modulus
if (strpos($expr, '/') !== false) {
if ($expr && strpos($expr, '/') !== false) {
$e = explode('/', $expr);
if (count($e) !== 2) {
throw new CronException(__('Invalid cron expression, expecting \'match/modulus\': %1', $expr));
Expand All @@ -193,7 +193,7 @@ public function matchCronExpression($expr, $num)
if ($expr === '*') {
$from = 0;
$to = 60;
} elseif (strpos($expr, '-') !== false) {
} elseif ($expr && strpos($expr, '-') !== false) {
// handle range
$e = explode('-', $expr);
if (count($e) !== 2) {
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Customer/Block/Widget/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function getPrefixOptions()

if ($this->getObject() && !empty($prefixOptions)) {
$prefixOption = $this->getObject()->getPrefix();
$oldPrefix = $this->escapeHtml(trim($prefixOption));
$oldPrefix = $this->escapeHtml(trim($prefixOption ?? ''));
if ($prefixOption !== null && !isset($prefixOptions[$oldPrefix]) && !isset($prefixOptions[$prefixOption])) {
$prefixOptions[$oldPrefix] = $oldPrefix;
}
Expand Down Expand Up @@ -165,7 +165,7 @@ public function getSuffixOptions()
$suffixOptions = $this->options->getNameSuffixOptions();
if ($this->getObject() && !empty($suffixOptions)) {
$suffixOption = $this->getObject()->getSuffix();
$oldSuffix = $this->escapeHtml(trim($suffixOption));
$oldSuffix = $this->escapeHtml(trim($suffixOption ?? ''));
if ($suffixOption !== null && !isset($suffixOptions[$oldSuffix]) && !isset($suffixOptions[$suffixOption])) {
$suffixOptions[$oldSuffix] = $oldSuffix;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Viewfile extends Action implements HttpGetActionInterface
/**
* Authorization level of a basic admin session
*/
const ADMIN_RESOURCE = 'Magento_Customer::manage';
public const ADMIN_RESOURCE = 'Magento_Customer::manage';

/**
* @var RawFactory
Expand Down Expand Up @@ -159,17 +159,16 @@ public function execute()
*/
private function getFileParams() : array
{
$file = null;
$plain = false;
if ($this->getRequest()->getParam('file')) {
if ($this->getRequest()->getParam('file', '')) {
// download file
$file = $this->urlDecoder->decode(
$this->getRequest()->getParam('file')
$this->getRequest()->getParam('file', '')
);
} elseif ($this->getRequest()->getParam('image')) {
} elseif ($this->getRequest()->getParam('image', '')) {
// show plain image
$file = $this->urlDecoder->decode(
$this->getRequest()->getParam('image')
$this->getRequest()->getParam('image', '')
);
$plain = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ private function getMetadataForm($entityType, $formCode, $scope)
}

if ($entityType == AddressMetadataInterface::ENTITY_TYPE_ADDRESS) {
$scopeData = explode('/', $scope);
$scopeData = $scope !== null ? explode('/', $scope) : [];
if (isset($scopeData[1]) && is_numeric($scopeData[1])) {
$customerAddress = $this->addressRepository->getById($scopeData[1]);
$attributeValues = $this->addressMapper->toFlatArray($customerAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,16 @@ public function execute()
*/
private function getFileParams()
{
$file = null;
$plain = false;
if ($this->getRequest()->getParam('file')) {
if ($this->getRequest()->getParam('file', '')) {
// download file
$file = $this->urlDecoder->decode(
$this->getRequest()->getParam('file')
$this->getRequest()->getParam('file', '')
);
} elseif ($this->getRequest()->getParam('image')) {
} elseif ($this->getRequest()->getParam('image', '')) {
// show plain image
$file = $this->urlDecoder->decode(
$this->getRequest()->getParam('image')
$this->getRequest()->getParam('image', '')
);
$plain = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function testExecuteGetParamImage()
$stat = ['size' => 10, 'mtime' => 10];

$this->requestMock->expects($this->any())->method('getParam')
->willReturnMap([['file', null, null], ['image', null, $decodedFile]]);
->willReturnMap([['file', '', ''], ['image', '', $decodedFile]]);

$this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($fileName)->willReturn($path);
$this->directoryMock->expects($this->once())->method('stat')->with($fileName)->willReturn($stat);
Expand Down

0 comments on commit f629205

Please sign in to comment.