Skip to content

Commit 56e7b18

Browse files
committed
Merge remote-tracking branch 'origin/AC-3109-fix-potential-issues-php-p3' into delivery-bunch-w21
2 parents f6a238f + 79a9228 commit 56e7b18

File tree

10 files changed

+41
-31
lines changed

10 files changed

+41
-31
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product/Validator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private function validateOption($attrCode, $possibleOptions, $value)
122122
*/
123123
protected function numericValidation($attrCode, $type)
124124
{
125-
$val = trim($this->_rowData[$attrCode]);
125+
$val = trim($this->_rowData[$attrCode] ?? '');
126126
if ($type == 'int') {
127127
$valid = (string)(int)$val === $val;
128128
} else {

app/code/Magento/CatalogImportExport/Model/Import/Uploader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public function move($fileName, $renameFileOff = false)
188188
{
189189
$this->setAllowRenameFiles(!$renameFileOff);
190190

191-
if (preg_match('/\bhttps?:\/\//i', $fileName, $matches)) {
191+
if ($fileName && preg_match('/\bhttps?:\/\//i', $fileName, $matches)) {
192192
$url = str_replace($matches[0], '', $fileName);
193193
$driver = ($matches[0] === $this->httpScheme) ? DriverPool::HTTP : DriverPool::HTTPS;
194194
$tmpFilePath = $this->downloadFileFromUrl($url, $driver);
@@ -206,7 +206,7 @@ public function move($fileName, $renameFileOff = false)
206206
$result['name'] = self::getCorrectFileName($result['name']);
207207

208208
// Directory and filename must be no more than 255 characters in length
209-
if (strlen($result['file']) > $this->maxFilenameLength) {
209+
if (strlen($result['file'] ?? '') > $this->maxFilenameLength) {
210210
throw new \LengthException(
211211
__('Filename is too long; must be %1 characters or less', $this->maxFilenameLength)
212212
);

app/code/Magento/CatalogInventory/Setup/Patch/Data/ConvertSerializedDataToJson.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
namespace Magento\CatalogInventory\Setup\Patch\Data;
88

9-
use Magento\Framework\App\ResourceConnection;
109
use Magento\Framework\DB\DataConverter\SerializedToJson;
1110
use Magento\Framework\DB\FieldDataConverterFactory;
1211
use Magento\Framework\DB\Select\QueryModifierFactory;
@@ -15,8 +14,7 @@
1514
use Magento\Framework\Setup\Patch\PatchVersionInterface;
1615

1716
/**
18-
* Class ConvertSerializedDataToJson
19-
* @package Magento\CatalogInventory\Setup\Patch
17+
* Class to convert serialized data to json.
2018
*/
2119
class ConvertSerializedDataToJson implements DataPatchInterface, PatchVersionInterface
2220
{
@@ -52,7 +50,7 @@ public function __construct(
5250
}
5351

5452
/**
55-
* {@inheritdoc}
53+
* @inheritdoc
5654
*/
5755
public function apply()
5856
{
@@ -86,6 +84,8 @@ public function apply()
8684
'value',
8785
$queryModifier
8886
);
87+
88+
return $this;
8989
}
9090

9191
/**
@@ -96,11 +96,11 @@ public function apply()
9696
*/
9797
private function isSerialized($value)
9898
{
99-
return (boolean) preg_match('/^((s|i|d|b|a|O|C):|N;)/', $value);
99+
return $value && preg_match('/^((s|i|d|b|a|O|C):|N;)/', $value);
100100
}
101101

102102
/**
103-
* {@inheritdoc}
103+
* @inheritdoc
104104
*/
105105
public static function getDependencies()
106106
{
@@ -110,15 +110,15 @@ public static function getDependencies()
110110
}
111111

112112
/**
113-
* {@inheritdoc}
113+
* @inheritdoc
114114
*/
115115
public static function getVersion()
116116
{
117117
return '2.2.1';
118118
}
119119

120120
/**
121-
* {@inheritdoc}
121+
* @inheritdoc
122122
*/
123123
public function getAliases()
124124
{

app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/NewActionHtml.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@
88

99
use Magento\Rule\Model\Action\AbstractAction;
1010

11+
/**
12+
* @SuppressWarnings(PHPMD.AllPurposeAction)
13+
*/
1114
class NewActionHtml extends \Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog
1215
{
1316
/**
17+
* Execute new action html.
18+
*
1419
* @return void
1520
*/
1621
public function execute()
1722
{
1823
$id = $this->getRequest()->getParam('id');
19-
$typeArr = explode('|', str_replace('-', '/', $this->getRequest()->getParam('type')));
24+
$typeArr = explode('|', str_replace('-', '/', $this->getRequest()->getParam('type', '')));
2025
$type = $typeArr[0];
2126

2227
$model = $this->_objectManager->create($type)

app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/NewConditionHtml.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
class NewConditionHtml extends CatalogAction implements HttpPostActionInterface, HttpGetActionInterface
1515
{
1616
/**
17+
* Execute new condition html.
18+
*
1719
* @return void
1820
*/
1921
public function execute()
2022
{
2123
$id = $this->getRequest()->getParam('id');
2224
$formName = $this->getRequest()->getParam('form_namespace');
23-
$typeArr = explode('|', str_replace('-', '/', $this->getRequest()->getParam('type')));
25+
$typeArr = explode('|', str_replace('-', '/', $this->getRequest()->getParam('type', '')));
2426
$type = $typeArr[0];
2527

2628
$model = $this->_objectManager->create($type)

app/code/Magento/CatalogRule/Model/Rule/Condition/MappableConditionsProcessor.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public function __construct(
4444
}
4545

4646
/**
47+
* Method to rebuild conditions tree.
48+
*
4749
* @param Combine $conditions
4850
* @return Combine
4951
*/
@@ -53,6 +55,8 @@ public function rebuildConditionsTree(CombinedCondition $conditions): CombinedCo
5355
}
5456

5557
/**
58+
* Method to rebuild combined condition.
59+
*
5660
* @param Combine $originalConditions
5761
* @return Combine
5862
* @throws InputException
@@ -89,9 +93,9 @@ private function rebuildCombinedCondition(CombinedCondition $originalConditions)
8993
__('Undefined condition type "%1" passed in.', $condition->getType())
9094
);
9195
}
92-
96+
$aggregator = $originalConditions->getAggregator() ? strtolower($originalConditions->getAggregator()) : '';
9397
// if resulted condition group has left no mappable conditions - we can remove it at all
94-
if (count($invalidConditions) > 0 && strtolower($originalConditions->getAggregator()) === 'any') {
98+
if (count($invalidConditions) > 0 && $aggregator === 'any') {
9599
$validConditions = [];
96100
}
97101

@@ -102,6 +106,8 @@ private function rebuildCombinedCondition(CombinedCondition $originalConditions)
102106
}
103107

104108
/**
109+
* Method to validate simple condition.
110+
*
105111
* @param Product $originalConditions
106112
* @return bool
107113
*/

app/code/Magento/CatalogSearch/Model/ResourceModel/Advanced.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ class Advanced extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
2121
protected $_eventManager = null;
2222

2323
/**
24-
* Store manager
25-
*
2624
* @var \Magento\Store\Model\StoreManagerInterface
2725
*/
2826
protected $_storeManager;
@@ -80,7 +78,7 @@ public function prepareCondition($attribute, $value)
8078
$condition = $value;
8179
}
8280
} else {
83-
if (strlen($value) > 0) {
81+
if ($value && strlen($value) > 0) {
8482
if (in_array($attribute->getBackendType(), ['varchar', 'text', 'static'])) {
8583
$condition = ['like' => $value]; // text search
8684
} else {

app/code/Magento/CatalogSearch/Model/Search/Catalog.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ class Catalog extends \Magento\Framework\DataObject
2727
protected $string;
2828

2929
/**
30-
* Adminhtml data
31-
*
3230
* @var \Magento\Backend\Helper\Data
3331
*/
3432
protected $_adminhtmlData = null;
@@ -71,7 +69,7 @@ public function load()
7169
->load();
7270

7371
foreach ($collection as $product) {
74-
$description = strip_tags($product->getDescription());
72+
$description = $product->getDescription() !== null ? strip_tags($product->getDescription()) : '';
7573
$result[] = [
7674
'id' => 'product/1/' . $product->getId(),
7775
'type' => __('Product'),

app/code/Magento/CatalogUrlRewrite/Model/Map/DataCategoryUrlRewriteDatabaseMap.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
class DataCategoryUrlRewriteDatabaseMap implements DatabaseMapInterface
1717
{
18-
const ENTITY_TYPE = 'category';
18+
public const ENTITY_TYPE = 'category';
1919

2020
/**
2121
* @var string[]
@@ -39,7 +39,7 @@ class DataCategoryUrlRewriteDatabaseMap implements DatabaseMapInterface
3939

4040
/**
4141
* @param ResourceConnection $connection
42-
* @param HashMapPool $hashMapPool,
42+
* @param HashMapPool $hashMapPool
4343
* @param TemporaryTableService $temporaryTableService
4444
*/
4545
public function __construct(
@@ -67,6 +67,7 @@ private function generateTableAdapter($categoryId)
6767

6868
/**
6969
* Queries the database for all category url rewrites that are affected by the category identified by $categoryId
70+
*
7071
* It returns the name of the temporary table where the resulting data is stored
7172
*
7273
* @param int $categoryId
@@ -110,7 +111,7 @@ private function generateData($categoryId)
110111
}
111112

112113
/**
113-
* {@inheritdoc}
114+
* @inheritdoc
114115
*/
115116
public function destroyTableAdapter($categoryId)
116117
{
@@ -134,7 +135,7 @@ public function getData($categoryId, $key)
134135
$this->generateTableAdapter($categoryId);
135136
$urlRewritesConnection = $this->connection->getConnection();
136137
$select = $urlRewritesConnection->select()->from(['e' => $this->createdTableAdapters[$categoryId]]);
137-
if (strlen($key) > 0) {
138+
if ($key && strlen($key) > 0) {
138139
$select->where('hash_key = ?', $key);
139140
}
140141

app/code/Magento/CatalogUrlRewrite/Model/Storage/DynamicStorage.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private function getCategoryUrlSuffix($storeId = null): string
159159
*/
160160
private function findProductRewriteByRequestPath(array $data): ?array
161161
{
162-
$requestPath = $data[UrlRewrite::REQUEST_PATH] ?? null;
162+
$requestPath = $data[UrlRewrite::REQUEST_PATH] ?? '';
163163

164164
$productUrl = $this->getBaseName($requestPath);
165165
$data[UrlRewrite::REQUEST_PATH] = [$productUrl];
@@ -185,13 +185,13 @@ private function findProductRewriteByRequestPath(array $data): ?array
185185

186186
if ($categoryFromDb[UrlRewrite::REDIRECT_TYPE]) {
187187
$productFromDb[UrlRewrite::REDIRECT_TYPE] = OptionProvider::PERMANENT;
188-
$categoryPath = str_replace($categorySuffix, '', $categoryFromDb[UrlRewrite::TARGET_PATH]);
188+
$categoryPath = str_replace($categorySuffix, '', $categoryFromDb[UrlRewrite::TARGET_PATH] ?? '');
189189
}
190190

191191
if (!$productResource->canBeShowInCategory(
192-
$productFromDb[UrlRewrite::ENTITY_ID],
193-
$categoryFromDb[UrlRewrite::ENTITY_ID]
194-
)
192+
$productFromDb[UrlRewrite::ENTITY_ID],
193+
$categoryFromDb[UrlRewrite::ENTITY_ID]
194+
)
195195
) {
196196
return null;
197197
}
@@ -237,7 +237,7 @@ private function findProductRewritesByFilter(array $data): array
237237
$productFromDb[UrlRewrite::REQUEST_PATH] = str_replace(
238238
$this->getCategoryUrlSuffix($data[UrlRewrite::STORE_ID]),
239239
'',
240-
$categoryFromDb[UrlRewrite::REQUEST_PATH]
240+
$categoryFromDb[UrlRewrite::REQUEST_PATH] ?? ''
241241
)
242242
. '/' . $productUrl;
243243
$rewrites[] = $productFromDb;

0 commit comments

Comments
 (0)