Skip to content

Commit e409883

Browse files
committed
Merge remote-tracking branch 'origin/AC-3109-fix-potential-issues-php-p6' into delivery-bunch-w21
2 parents 7ded2f9 + 88d2e4f commit e409883

File tree

14 files changed

+62
-75
lines changed

14 files changed

+62
-75
lines changed

app/code/Magento/ImportExport/Model/Import/Entity/AbstractEav.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,14 @@ abstract class AbstractEav extends \Magento\ImportExport\Model\Import\AbstractEn
2222
*
2323
* Name of collection class
2424
*/
25-
const ATTRIBUTE_COLLECTION_NAME = \Magento\Framework\Data\Collection::class;
25+
public const ATTRIBUTE_COLLECTION_NAME = \Magento\Framework\Data\Collection::class;
2626

2727
/**
28-
* Store manager
29-
*
3028
* @var \Magento\Store\Model\StoreManagerInterface
3129
*/
3230
protected $_storeManager;
3331

3432
/**
35-
* Entity type id
36-
*
3733
* @var int
3834
*/
3935
protected $_entityTypeId;
@@ -46,8 +42,6 @@ abstract class AbstractEav extends \Magento\ImportExport\Model\Import\AbstractEn
4642
protected $_indexValueAttributes = [];
4743

4844
/**
49-
* Website code-to-ID
50-
*
5145
* @var array
5246
*/
5347
protected $_websiteCodeToId = [];
@@ -74,8 +68,6 @@ abstract class AbstractEav extends \Magento\ImportExport\Model\Import\AbstractEn
7468
protected $_attributes = [];
7569

7670
/**
77-
* Attributes collection
78-
*
7971
* @var \Magento\Framework\Data\Collection
8072
*/
8173
protected $_attributeCollection;
@@ -109,9 +101,7 @@ public function __construct(
109101
parent::__construct($string, $scopeConfig, $importFactory, $resourceHelper, $resource, $errorAggregator, $data);
110102

111103
$this->_storeManager = $storeManager;
112-
$this->_attributeCollection = isset(
113-
$data['attribute_collection']
114-
) ? $data['attribute_collection'] : $collectionFactory->create(
104+
$this->_attributeCollection = $data['attribute_collection'] ?? $collectionFactory->create(
115105
static::ATTRIBUTE_COLLECTION_NAME
116106
);
117107

@@ -229,8 +219,8 @@ public function getAttributeOptions(
229219
$value = is_array($option['value']) ? $option['value'] : [$option];
230220
foreach ($value as $innerOption) {
231221
// skip ' -- Please Select -- ' option
232-
if (strlen($innerOption['value'])) {
233-
$options[mb_strtolower($innerOption[$index])] = $innerOption['value'];
222+
if (strlen($innerOption['value'] ?? '')) {
223+
$options[mb_strtolower($innerOption[$index] ?? '')] = $innerOption['value'];
234224
}
235225
}
236226
}

app/code/Magento/ImportExport/Model/Import/Entity/AbstractEntity.php

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
/**
1818
* Import entity abstract model
1919
*
20+
* phpcs:disable Magento2.Classes.AbstractApi
2021
* @api
2122
*
2223
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -28,25 +29,25 @@ abstract class AbstractEntity
2829
/**
2930
* Database constants
3031
*/
31-
const DB_MAX_PACKET_COEFFICIENT = 900000;
32+
public const DB_MAX_PACKET_COEFFICIENT = 900000;
3233

33-
const DB_MAX_PACKET_DATA = 1048576;
34+
public const DB_MAX_PACKET_DATA = 1048576;
3435

35-
const DB_MAX_VARCHAR_LENGTH = 256;
36+
public const DB_MAX_VARCHAR_LENGTH = 256;
3637

37-
const DB_MAX_TEXT_LENGTH = 65536;
38+
public const DB_MAX_TEXT_LENGTH = 65536;
3839

39-
const ERROR_CODE_SYSTEM_EXCEPTION = 'systemException';
40-
const ERROR_CODE_COLUMN_NOT_FOUND = 'columnNotFound';
41-
const ERROR_CODE_COLUMN_EMPTY_HEADER = 'columnEmptyHeader';
42-
const ERROR_CODE_COLUMN_NAME_INVALID = 'columnNameInvalid';
43-
const ERROR_CODE_ATTRIBUTE_NOT_VALID = 'attributeNotInvalid';
44-
const ERROR_CODE_DUPLICATE_UNIQUE_ATTRIBUTE = 'duplicateUniqueAttribute';
45-
const ERROR_CODE_ILLEGAL_CHARACTERS = 'illegalCharacters';
46-
const ERROR_CODE_INVALID_ATTRIBUTE = 'invalidAttributeName';
47-
const ERROR_CODE_WRONG_QUOTES = 'wrongQuotes';
48-
const ERROR_CODE_COLUMNS_NUMBER = 'wrongColumnsNumber';
49-
const ERROR_CODE_CATEGORY_NOT_VALID = 'categoryNotValid';
40+
public const ERROR_CODE_SYSTEM_EXCEPTION = 'systemException';
41+
public const ERROR_CODE_COLUMN_NOT_FOUND = 'columnNotFound';
42+
public const ERROR_CODE_COLUMN_EMPTY_HEADER = 'columnEmptyHeader';
43+
public const ERROR_CODE_COLUMN_NAME_INVALID = 'columnNameInvalid';
44+
public const ERROR_CODE_ATTRIBUTE_NOT_VALID = 'attributeNotInvalid';
45+
public const ERROR_CODE_DUPLICATE_UNIQUE_ATTRIBUTE = 'duplicateUniqueAttribute';
46+
public const ERROR_CODE_ILLEGAL_CHARACTERS = 'illegalCharacters';
47+
public const ERROR_CODE_INVALID_ATTRIBUTE = 'invalidAttributeName';
48+
public const ERROR_CODE_WRONG_QUOTES = 'wrongQuotes';
49+
public const ERROR_CODE_COLUMNS_NUMBER = 'wrongColumnsNumber';
50+
public const ERROR_CODE_CATEGORY_NOT_VALID = 'categoryNotValid';
5051

5152
/**
5253
* @var array
@@ -86,9 +87,7 @@ abstract class AbstractEntity
8687
protected $_dataValidated = false;
8788

8889
/**
89-
* Valid column names
90-
*
91-
* @array
90+
* @var array
9291
*/
9392
protected $validColumnNames = [];
9493

@@ -107,8 +106,6 @@ abstract class AbstractEntity
107106
protected $_dataSourceModel;
108107

109108
/**
110-
* Entity type id.
111-
*
112109
* @var int
113110
*/
114111
protected $_entityTypeId;
@@ -191,15 +188,11 @@ abstract class AbstractEntity
191188
protected $_uniqueAttributes = [];
192189

193190
/**
194-
* Import export data
195-
*
196191
* @var \Magento\ImportExport\Helper\Data
197192
*/
198193
protected $_importExportData;
199194

200195
/**
201-
* Json Helper
202-
*
203196
* @var \Magento\Framework\Json\Helper\Data
204197
*/
205198
protected $jsonHelper;
@@ -423,7 +416,7 @@ protected function _saveValidatedBunches()
423416
if ($this->validateRow($rowData, $source->key())) {
424417
// add row to bunch for save
425418
$rowData = $this->_prepareRowForDb($rowData);
426-
$rowSize = strlen($this->jsonHelper->jsonEncode($rowData));
419+
$rowSize = strlen($this->jsonHelper->jsonEncode($rowData) ?? '');
427420

428421
$isBunchSizeExceeded = $bunchSize > 0 && count($bunchRows) >= $bunchSize;
429422

@@ -438,7 +431,7 @@ protected function _saveValidatedBunches()
438431
$source->next();
439432
}
440433
}
441-
$this->_processedEntitiesCount = (count($skuSet)) ? : $this->_processedRowsCount;
434+
$this->_processedEntitiesCount = (count($skuSet)) ?: $this->_processedRowsCount;
442435

443436
return $this;
444437
}
@@ -532,12 +525,13 @@ public function getAttributeOptions(
532525
foreach ($attribute->getSource()->getAllOptions(false) as $option) {
533526
$value = is_array($option['value']) ? $option['value'] : [$option];
534527
foreach ($value as $innerOption) {
535-
if (strlen($innerOption['value'])) {
528+
if (strlen($innerOption['value'] ?? '')) {
536529
// skip ' -- Please Select -- ' option
537-
$options[strtolower($innerOption[$index])] = $innerOption['value'];
530+
$options[strtolower($innerOption[$index] ?? '')] = $innerOption['value'];
538531
}
539532
}
540533
}
534+
// phpcs:disable Magento2.CodeAnalysis.EmptyBlock.DetectedCatch
541535
} catch (\Exception $e) {
542536
// ignore exceptions connected with source models
543537
}
@@ -657,19 +651,19 @@ public function isAttributeValid($attrCode, array $attrParams, array $rowData, $
657651
$valid = $this->string->strlen($val) < self::DB_MAX_VARCHAR_LENGTH;
658652
break;
659653
case 'decimal':
660-
$val = trim($rowData[$attrCode]);
654+
$val = trim($rowData[$attrCode] ?? '');
661655
$valid = (double)$val == $val;
662656
break;
663657
case 'select':
664658
case 'multiselect':
665-
$valid = isset($attrParams['options'][strtolower($rowData[$attrCode])]);
659+
$valid = isset($attrParams['options'][strtolower($rowData[$attrCode] ?? '')]);
666660
break;
667661
case 'int':
668-
$val = trim($rowData[$attrCode]);
662+
$val = trim($rowData[$attrCode] ?? '');
669663
$valid = (int)$val == $val;
670664
break;
671665
case 'datetime':
672-
$val = trim($rowData[$attrCode]);
666+
$val = trim($rowData[$attrCode] ?? '');
673667
$valid = strtotime($val) !== false;
674668
break;
675669
case 'text':
@@ -809,9 +803,9 @@ public function validateData()
809803
foreach ($this->getSource()->getColNames() as $columnName) {
810804
$columnNumber++;
811805
if (!$this->isAttributeParticular($columnName)) {
812-
if (trim($columnName) == '') {
806+
if (trim($columnName ?? '') == '') {
813807
$emptyHeaderColumns[] = $columnNumber;
814-
} elseif (!preg_match('/^[a-z][a-z0-9_]*$/', $columnName)) {
808+
} elseif (!$columnName || !preg_match('/^[a-z][a-z0-9_]*$/', $columnName)) {
815809
$invalidColumns[] = $columnName;
816810
} elseif ($this->needColumnCheck && !in_array($columnName, $this->getValidColumnNames())) {
817811
$invalidAttributes[] = $columnName;

app/code/Magento/ImportExport/Model/Import/Source/Csv.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ class Csv extends \Magento\ImportExport\Model\Import\AbstractSource
1818
protected $_file;
1919

2020
/**
21-
* Delimiter.
22-
*
2321
* @var string
2422
*/
2523
protected $_delimiter = ',';
@@ -96,7 +94,7 @@ protected function _getNextRow()
9694
$parsed = $this->_file->readCsv(0, $this->_delimiter, $this->_enclosure);
9795
if (is_array($parsed) && count($parsed) != $this->_colQty) {
9896
foreach ($parsed as $element) {
99-
if (strpos($element, "'") !== false) {
97+
if ($element && strpos($element, "'") !== false) {
10098
$this->_foundWrongQuoteFlag = true;
10199
break;
102100
}
@@ -112,6 +110,7 @@ protected function _getNextRow()
112110
*
113111
* @return void
114112
*/
113+
#[\ReturnTypeWillChange]
115114
public function rewind()
116115
{
117116
$this->_file->seek(0);

app/code/Magento/ImportExport/Ui/DataProvider/ExportFileDataProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private function getPathToExportFile($file): string
136136

137137
$filePath = explode(
138138
$delimiter,
139-
$file['dirname']
139+
$file['dirname'] ?? ''
140140
);
141141

142142
return ltrim(

app/code/Magento/Integration/Model/Oauth/Consumer.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,16 @@ public function beforeSave()
113113

114114
/**
115115
* @inheritDoc
116+
*
117+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
116118
*/
117119
public function validate()
118120
{
119121
if ($this->getCallbackUrl() || $this->getRejectedCallbackUrl()) {
120-
$this->setCallbackUrl(trim($this->getCallbackUrl()));
121-
$this->setRejectedCallbackUrl(trim($this->getRejectedCallbackUrl()));
122+
$this->setCallbackUrl($this->getCallbackUrl() !== null ? trim($this->getCallbackUrl()) : '');
123+
$this->setRejectedCallbackUrl(
124+
$this->getRejectedCallbackUrl() !== null ? trim($this->getRejectedCallbackUrl()) : ''
125+
);
122126

123127
if ($this->getCallbackUrl() && !$this->urlValidator->isValid($this->getCallbackUrl())) {
124128
throw new \Magento\Framework\Exception\LocalizedException(__('Invalid Callback URL'));

app/code/Magento/Integration/Model/Oauth/Token/Provider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,15 @@ public function validateAccessToken($accessToken)
172172
*/
173173
public function validateOauthToken($oauthToken)
174174
{
175-
return strlen($oauthToken) == \Magento\Framework\Oauth\Helper\Oauth::LENGTH_TOKEN;
175+
return $oauthToken && strlen($oauthToken) == \Magento\Framework\Oauth\Helper\Oauth::LENGTH_TOKEN;
176176
}
177177

178178
/**
179179
* @inheritdoc
180180
*/
181181
public function getConsumerByKey($consumerKey)
182182
{
183-
if (strlen($consumerKey) != \Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_KEY) {
183+
if ($consumerKey && strlen($consumerKey) != \Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_KEY) {
184184
throw new \Magento\Framework\Oauth\Exception(
185185
__('Consumer key is not the correct length')
186186
);

app/code/Magento/Integration/Setup/Patch/Data/UpgradeOauthToken.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
*/
2323
class UpgradeOauthToken implements DataPatchInterface, PatchVersionInterface
2424
{
25-
2625
/**
2726
* @var TokenCollection
2827
*/
@@ -90,7 +89,7 @@ public function apply()
9089
foreach ($this->tokenCollection as $token) {
9190
$existingSecret = $token->getSecret();
9291
$entityId = $token->getEntityId();
93-
$type = strtolower($token->getType());
92+
$type = $token->getType() !== null ? strtolower($token->getType()) : '';
9493

9594
if ($entityId && $existingSecret && $type === TokenModel::TYPE_ACCESS) {
9695
if (strlen($existingSecret) <= OauthHelper::LENGTH_TOKEN_SECRET) {

app/code/Magento/LoginAsCustomerGraphQl/Model/Resolver/RequestCustomerToken.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
use Magento\Framework\Exception\LocalizedException;
1212
use Magento\Framework\Exception\NoSuchEntityException;
1313
use Magento\Framework\GraphQl\Config\Element\Field;
14+
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
15+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
16+
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
17+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
1418
use Magento\Framework\GraphQl\Query\Resolver\Value;
1519
use Magento\Framework\GraphQl\Query\ResolverInterface;
1620
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
17-
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
18-
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
19-
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
20-
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
2121
use Magento\LoginAsCustomerApi\Api\ConfigInterface as LoginAsCustomerConfig;
2222
use Magento\LoginAsCustomerGraphQl\Model\LoginAsCustomer\CreateCustomerToken;
2323

@@ -76,7 +76,8 @@ public function resolve(
7676
array $args = null
7777
) {
7878
$isAllowedLogin = $this->authorization->isAllowed('Magento_LoginAsCustomer::login');
79-
$isAlllowedShoppingAssistance = $this->authorization->isAllowed('Magento_LoginAsCustomer::allow_shopping_assistance');
79+
$isAlllowedShoppingAssistance =
80+
$this->authorization->isAllowed('Magento_LoginAsCustomer::allow_shopping_assistance');
8081
$isEnabled = $this->config->isEnabled();
8182

8283
/* Get input params */
@@ -86,7 +87,7 @@ public function resolve(
8687
throw new GraphQlInputException(__('Check input params.'));
8788
}
8889

89-
if (empty(trim($args['customer_email'], " "))) {
90+
if (empty($args['customer_email']) || !trim($args['customer_email'], " ")) {
9091
throw new GraphQlInputException(__('Specify the "customer email" value.'));
9192
}
9293

@@ -103,7 +104,7 @@ public function resolve(
103104
__('Allow remote shopping assistance is disabled.')
104105
);
105106
}
106-
107+
107108
return $this->createCustomerToken->execute(
108109
$args['customer_email'],
109110
$context->getExtensionAttributes()->getStore()

app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function execute(array $paths): void
6060
continue;
6161
}
6262
try {
63+
$path = $path !== null ? $path : '';
6364
//phpcs:ignore Magento2.Functions.DiscouragedFunction
6465
$name = basename($path);
6566
//phpcs:ignore Magento2.Functions.DiscouragedFunction

app/code/Magento/MediaGallery/Model/Directory/IsExcluded.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
namespace Magento\MediaGallery\Model\Directory;
99

1010
use Magento\Framework\App\Config\ScopeConfigInterface;
11-
use Magento\Framework\App\ObjectManager;
12-
use Magento\Framework\Filesystem\File\WriteInterface;
1311
use Magento\Framework\App\Filesystem\DirectoryList;
12+
use Magento\Framework\App\ObjectManager;
1413
use Magento\Framework\Filesystem;
14+
use Magento\Framework\Filesystem\File\WriteInterface;
1515
use Magento\MediaGalleryApi\Api\IsPathExcludedInterface;
1616
use Magento\MediaGalleryApi\Model\ExcludedPatternsConfigInterface;
1717

@@ -61,7 +61,6 @@ public function __construct(
6161
$this->filesystem = $filesystem;
6262
$this->mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
6363
$this->coreConfig = $coreConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class);
64-
6564
}
6665

6766
/**
@@ -90,8 +89,8 @@ private function getAllowedPathPattern()
9089
);
9190
$regExp = '/^(';
9291
$or = '';
93-
foreach($mediaGalleryImageFolders as $folder) {
94-
$folderPattern = str_replace('/', '[\/]+', $folder);
92+
foreach ($mediaGalleryImageFolders as $folder) {
93+
$folderPattern = $folder !== null ? str_replace('/', '[\/]+', $folder) : '';
9594
$regExp .= $or . $folderPattern . '\b(?!-)(?:\/?[^\/]+)*\/?$';
9695
$or = '|';
9796
}

0 commit comments

Comments
 (0)