Skip to content

Commit fdf2944

Browse files
committed
Merge remote-tracking branch 'origin/AC-3109-fix-potential-issues-php-p9' into delivery-bunch-w21
2 parents ff3d130 + 86ae43a commit fdf2944

File tree

9 files changed

+56
-45
lines changed

9 files changed

+56
-45
lines changed

app/code/Magento/Store/Model/ResourceModel/Website.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function readAllWebsites()
6868
*/
6969
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
7070
{
71-
if (!preg_match('/^[a-z]+[a-z0-9_]*$/i', $object->getCode())) {
71+
if (!$object->getCode() || !preg_match('/^[a-z]+[a-z0-9_]*$/i', $object->getCode())) {
7272
throw new \Magento\Framework\Exception\LocalizedException(
7373
__(
7474
'Website code may only contain letters (a-z), numbers (0-9) or underscore (_),'

app/code/Magento/Store/Model/Store.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Store\Model;
77

8+
use Laminas\Uri\UriFactory;
89
use Magento\Catalog\Model\Category;
910
use Magento\Directory\Model\Currency;
1011
use Magento\Framework\App\Config\ScopeConfigInterface;
@@ -19,7 +20,6 @@
1920
use Magento\Framework\Url\ScopeInterface as UrlScopeInterface;
2021
use Magento\Framework\UrlInterface;
2122
use Magento\Store\Api\Data\StoreInterface;
22-
use Laminas\Uri\UriFactory;
2323

2424
/**
2525
* Store model
@@ -653,12 +653,12 @@ public function getBaseUrl($type = UrlInterface::URL_TYPE_LINK, $secure = null)
653653
throw new \InvalidArgumentException('Invalid base url type');
654654
}
655655

656-
if (false !== strpos($url, self::BASE_URL_PLACEHOLDER)) {
656+
if ($url && false !== strpos($url, self::BASE_URL_PLACEHOLDER)) {
657657
$url = str_replace(self::BASE_URL_PLACEHOLDER, $this->_request->getDistroBaseUrl(), $url);
658658
}
659659

660660
$this->_baseUrlCache[$cacheKey] = $this->urlModifier->execute(
661-
rtrim($url, '/') . '/',
661+
$url !== null ? rtrim($url, '/') . '/' : '/',
662662
ModifierInterface::MODE_BASE
663663
);
664664
}
@@ -887,7 +887,7 @@ public function getDefaultCurrency()
887887
*/
888888
public function setCurrentCurrencyCode($code)
889889
{
890-
$code = is_string($code) && '' !== $code ? strtoupper($code): '';
890+
$code = is_string($code) && '' !== $code ? strtoupper($code) : '';
891891
if (in_array($code, $this->getAvailableCurrencyCodes())) {
892892
$this->_getSession()->setCurrencyCode($code);
893893

@@ -933,7 +933,7 @@ public function getAvailableCurrencyCodes($skipBaseNotAllowed = false)
933933
{
934934
$codes = $this->getData('available_currency_codes');
935935
if (null === $codes) {
936-
$codes = explode(',', $this->getConfig(Currency::XML_PATH_CURRENCY_ALLOW));
936+
$codes = explode(',', $this->getConfig(Currency::XML_PATH_CURRENCY_ALLOW) ?? '');
937937
// add base currency, if it is not in allowed currencies
938938
$baseCurrencyCode = $this->getBaseCurrencyCode();
939939
if (!in_array($baseCurrencyCode, $codes)) {
@@ -964,7 +964,7 @@ public function getAvailableCurrencyCodes($skipBaseNotAllowed = false)
964964
*/
965965
public function getAllowedCurrencies()
966966
{
967-
return explode(',', $this->getConfig($this->_currencyInstalled));
967+
return explode(',', $this->getConfig($this->_currencyInstalled) ?? '');
968968
}
969969

970970
/**

app/code/Magento/Store/Ui/Component/Listing/Column/Store/Options.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@
1919
class Options implements OptionSourceInterface
2020
{
2121
/**
22-
* Escaper
23-
*
2422
* @var Escaper
2523
*/
2624
protected $escaper;
2725

2826
/**
29-
* System store
30-
*
3127
* @var SystemStore
3228
*/
3329
protected $systemStore;
@@ -82,7 +78,7 @@ public function toOptionArray()
8278
protected function sanitizeName($name)
8379
{
8480
$matches = [];
85-
preg_match('/\$[:]*{(.)*}/', $name, $matches);
81+
preg_match('/\$[:]*{(.)*}/', $name ?: '', $matches);
8682
if (count($matches) > 0) {
8783
$name = $this->escaper->escapeHtml($this->escaper->escapeJs($name));
8884
} else {

app/code/Magento/Swatches/Helper/Media.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Media extends \Magento\Framework\App\Helper\AbstractHelper
2222
* Swatch area inside media folder
2323
*
2424
*/
25-
const SWATCH_MEDIA_PATH = 'attribute/swatch';
25+
public const SWATCH_MEDIA_PATH = 'attribute/swatch';
2626

2727
/**
2828
* @var \Magento\Catalog\Model\Product\Media\Config
@@ -42,8 +42,6 @@ class Media extends \Magento\Framework\App\Helper\AbstractHelper
4242
protected $fileStorageDb = null;
4343

4444
/**
45-
* Store manager
46-
*
4745
* @var \Magento\Store\Model\StoreManagerInterface
4846
*/
4947
protected $storeManager;
@@ -112,6 +110,8 @@ public function __construct(
112110
}
113111

114112
/**
113+
* Method to get swatch attribute image.
114+
*
115115
* @param string $swatchType
116116
* @param string $file
117117
* @return string
@@ -138,6 +138,14 @@ public function getSwatchAttributeImage($swatchType, $file)
138138
return $basePath . '/' . $this->getRelativeTransformationParametersPath($swatchType, $file);
139139
}
140140

141+
/**
142+
* Method to get relative transformation parameters path.
143+
*
144+
* @param string $swatchType
145+
* @param string $file
146+
* @return string
147+
* @throws \Magento\Framework\Exception\NoSuchEntityException
148+
*/
141149
private function getRelativeTransformationParametersPath($swatchType, $file)
142150
{
143151
$imageConfig = $this->getImageConfig();
@@ -150,14 +158,14 @@ private function getRelativeTransformationParametersPath($swatchType, $file)
150158
}
151159

152160
/**
153-
* move image from tmp to catalog dir
161+
* Move image from tmp to catalog dir
154162
*
155163
* @param string $file
156164
* @return string path
157165
*/
158166
public function moveImageFromTmp($file)
159167
{
160-
if (strrpos($file, '.tmp') == strlen($file) - 4) {
168+
if ($file && strrpos($file, '.tmp') == strlen($file) - 4) {
161169
$file = substr($file, 0, strlen($file) - 4);
162170
}
163171
$destinationFile = $this->getUniqueFileName($file);
@@ -182,7 +190,7 @@ public function moveImageFromTmp($file)
182190
);
183191
}
184192

185-
return str_replace('\\', '/', $destinationFile);
193+
return $destinationFile !== null ? str_replace('\\', '/', $destinationFile) : '';
186194
}
187195

188196
/**
@@ -199,6 +207,7 @@ protected function getUniqueFileName($file)
199207
$file
200208
);
201209
} else {
210+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
202211
$destFile = dirname($file) . '/' . \Magento\MediaStorage\Model\File\Uploader::getNewFileName(
203212
$this->getOriginalFilePath($file)
204213
);
@@ -207,6 +216,12 @@ protected function getUniqueFileName($file)
207216
return $destFile;
208217
}
209218

219+
/**
220+
* Method to get original file path.
221+
*
222+
* @param string $file
223+
* @return string
224+
*/
210225
private function getOriginalFilePath($file)
211226
{
212227
return $this->mediaDirectory->getAbsolutePath($this->getAttributeSwatchPath($file));
@@ -278,7 +293,7 @@ protected function generateNamePath($imageConfig, $imageUrl, $swatchType)
278293
* Generate folder name WIDTHxHEIGHT based on config in view.xml
279294
*
280295
* @param string $swatchType
281-
* @param null $imageConfig
296+
* @param array|null $imageConfig
282297
* @return string
283298
*/
284299
public function getFolderNameSize($swatchType, $imageConfig = null)
@@ -314,7 +329,7 @@ public function getImageConfig()
314329
*/
315330
protected function prepareFileName($imageUrl)
316331
{
317-
$fileArray = explode('/', $imageUrl);
332+
$fileArray = explode('/', $imageUrl ?: '');
318333
$fileName = array_pop($fileArray);
319334
$filePath = implode('/', $fileArray);
320335
return ['name' => $fileName, 'path' => $filePath];
@@ -372,6 +387,6 @@ public function getSwatchCachePath($swatchType)
372387
*/
373388
protected function prepareFile($file)
374389
{
375-
return ltrim(str_replace('\\', '/', $file), '/');
390+
return $file !== null ? ltrim(str_replace('\\', '/', $file), '/') : '';
376391
}
377392
}

app/code/Magento/Swatches/view/frontend/templates/product/layered/renderer.phtml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@
5454
data-option-tooltip-value="">
5555
</div>
5656
<?php
57-
$element = 'swatchImageOption' .$escaper->escapeJs($option);
58-
$script = 'var ' .$element
59-
.' = document.querySelector(\'div[data-option-id="' .$escaper->escapeJs($option)
60-
.'"]\');' .PHP_EOL;
61-
$script .= $element .'.style.background = "url(\''
62-
.$escapedUrl .'\') no-repeat center";' .PHP_EOL;
63-
$script .= $element .'.style.backgroundSize = "initial";';
57+
$element = 'swatchImageOption' . $escaper->escapeJs($option);
58+
$script = 'var ' . $element
59+
. ' = document.querySelector(\'div[data-option-id="' . $escaper->escapeJs($option)
60+
. '"]\');' . PHP_EOL;
61+
$script .= $element . '.style.background = "url(\''
62+
. $escapedUrl . '\') no-repeat center";' . PHP_EOL;
63+
$script .= $element . '.style.backgroundSize = "initial";';
6464
?>
6565
<?= /* @noEscape*/ $secureRenderer->renderTag('script', [], $script, false); ?>
6666
<?php break;
@@ -77,16 +77,16 @@
7777
) ?>">
7878
</div>
7979
<?php
80-
$element = 'swatchImageOption' .$escaper->escapeJs($option);
81-
$backgroundValue = $escaper->escapeJs(
80+
$element = 'swatchImageOption' . $escaper->escapeJs($option);
81+
$backgroundValue = isset($swatchData['swatches'][$option]['value']) ? $escaper->escapeJs(
8282
str_replace('\'', '\\\'', $swatchData['swatches'][$option]['value'])
83-
);
84-
$script = 'var ' .$element
85-
.' = document.querySelector(\'div[data-option-id="' .$escaper->escapeJs($option)
86-
.'"]\');' .PHP_EOL;
87-
$script .= $element .'.style.background = "' .$backgroundValue
88-
.' no-repeat center";' .PHP_EOL;
89-
$script .= $element .'.style.backgroundSize = "initial";';
83+
) : '';
84+
$script = 'var ' . $element
85+
. ' = document.querySelector(\'div[data-option-id="' . $escaper->escapeJs($option)
86+
. '"]\');' . PHP_EOL;
87+
$script .= $element . '.style.background = "' . $backgroundValue
88+
. ' no-repeat center";' . PHP_EOL;
89+
$script .= $element . '.style.backgroundSize = "initial";';
9090
?>
9191
<?= /* @noEscape*/ $secureRenderer->renderTag('script', [], $script, false); ?>
9292
<?php break;

app/code/Magento/Tax/Controller/Adminhtml/Rate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ abstract class Rate extends \Magento\Backend\App\Action
2020
*
2121
* @see _isAllowed()
2222
*/
23-
const ADMIN_RESOURCE = 'Magento_Tax::manage_tax';
23+
public const ADMIN_RESOURCE = 'Magento_Tax::manage_tax';
2424

2525
/**
2626
* @var \Magento\Framework\Registry
@@ -68,7 +68,7 @@ protected function _processRateData($rateData)
6868
if (is_array($value)) {
6969
$result[$key] = $this->_processRateData($value);
7070
} else {
71-
$result[$key] = trim($value);
71+
$result[$key] = $value !== null ? trim($value) : '';
7272
}
7373
}
7474
return $result;

app/code/Magento/Tax/Model/Calculation/Rate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function beforeSave()
142142
$zipFrom = $this->getZipFrom();
143143
$zipTo = $this->getZipTo();
144144

145-
if (strlen($zipFrom) > 9 || strlen($zipTo) > 9) {
145+
if (($zipFrom && strlen($zipFrom) > 9) || ($zipTo && strlen($zipTo) > 9)) {
146146
throw new \Magento\Framework\Exception\LocalizedException(
147147
__(
148148
'The ZIP Code length is invalid. '

app/code/Magento/Tax/Model/Calculation/RateRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ private function validate(TaxRateInterface $taxRate)
278278
}
279279

280280
if ($taxRate->getCode() === null
281-
|| !\Zend_Validate::is(trim($taxRate->getCode()), 'NotEmpty')
281+
|| !\Zend_Validate::is(trim($taxRate->getCode() ?? ''), 'NotEmpty')
282282
) {
283283
$exception->addError(__('"%fieldName" is required. Enter and try again.', ['fieldName' => 'code']));
284284
}
@@ -303,7 +303,7 @@ private function validate(TaxRateInterface $taxRate)
303303
}
304304
} else {
305305
if ($taxRate->getTaxPostcode() === null
306-
|| !\Zend_Validate::is(trim($taxRate->getTaxPostcode()), 'NotEmpty')
306+
|| !\Zend_Validate::is(trim($taxRate->getTaxPostcode() ?? ''), 'NotEmpty')
307307
) {
308308
$exception->addError(
309309
__('"%fieldName" is required. Enter and try again.', ['fieldName' => 'postcode'])

app/code/Magento/Tax/Model/Calculation/Rule/Validator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ public function isValid($value)
5757
}
5858

5959
// Priority is required and must be 0 or greater
60-
if (!\Zend_Validate::is(trim($value->getPriority()), 'NotEmpty')) {
60+
if (!\Zend_Validate::is(trim($value->getPriority() ?? ''), 'NotEmpty')) {
6161
$this->addErrorMessage(
6262
$messages,
6363
'"%fieldName" is required. Enter and try again.',
6464
['fieldName' => 'priority']
6565
);
6666
}
67-
if (!\Zend_Validate::is(trim($value->getPriority()), 'GreaterThan', [-1])) {
67+
if (!\Zend_Validate::is(trim($value->getPriority() ?? ''), 'GreaterThan', [-1])) {
6868
$this->addErrorMessage(
6969
$messages,
7070
'The %fieldName value of "%value" must be greater than or equal to %minValue.',
@@ -73,7 +73,7 @@ public function isValid($value)
7373
}
7474

7575
// Code is required
76-
if ($value->getCode() === null || !\Zend_Validate::is(trim($value->getCode()), 'NotEmpty')) {
76+
if ($value->getCode() === null || !\Zend_Validate::is(trim($value->getCode() ?? ''), 'NotEmpty')) {
7777
$this->addErrorMessage(
7878
$messages,
7979
'"%fieldName" is required. Enter and try again.',

0 commit comments

Comments
 (0)