Skip to content

Commit 050900a

Browse files
committed
Merge remote-tracking branch 'origin/AC-3109-fix-potential-issues-php-p1' into delivery-bunch-w20
2 parents 73928eb + ab27698 commit 050900a

File tree

13 files changed

+151
-115
lines changed

13 files changed

+151
-115
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Text.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @deprecated 100.2.0 in favour of UI component implementation
1515
* @since 100.0.2
1616
*/
17-
class Text extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
17+
class Text extends AbstractRenderer
1818
{
1919
/**
2020
* Format variables pattern
@@ -61,11 +61,11 @@ private function getSimpleValue(DataObject $row)
6161
*/
6262
private function getFormattedValue(DataObject $row)
6363
{
64-
$value = $this->getColumn()->getFormat() ?: null;
64+
$value = $this->getColumn()->getFormat() ?: '';
6565
if (true === $this->getColumn()->getTranslate()) {
6666
$value = __($value);
6767
}
68-
if (preg_match_all($this->_variablePattern, $value, $matches)) {
68+
if ($value && preg_match_all($this->_variablePattern, $value, $matches)) {
6969
foreach ($matches[0] as $index => $match) {
7070
$replacement = $row->getData($matches[1][$index]);
7171
$value = str_replace($match, $replacement, $value);

app/code/Magento/Backend/Block/Widget/Grid/Export.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ public function getCsvFile()
343343
* Retrieve Grid data as CSV
344344
*
345345
* @return string
346+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
346347
*/
347348
public function getCsv()
348349
{
@@ -364,7 +365,7 @@ public function getCsv()
364365
$data[] = '"' . str_replace(
365366
['"', '\\'],
366367
['""', '\\\\'],
367-
$column->getRowFieldExport($item)
368+
$column->getRowFieldExport($item) ?: ''
368369
) . '"';
369370
}
370371
}
@@ -378,7 +379,7 @@ public function getCsv()
378379
$data[] = '"' . str_replace(
379380
['"', '\\'],
380381
['""', '\\\\'],
381-
$column->getRowFieldExport($this->_getTotals())
382+
$column->getRowFieldExport($this->_getTotals()) ?: ''
382383
) . '"';
383384
}
384385
}

app/code/Magento/Backend/Block/Widget/Grid/Extended.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ class Extended extends \Magento\Backend\Block\Widget\Grid implements \Magento\Ba
8787
protected $_massactionIdFilter;
8888

8989
/**
90-
* Massaction block name
91-
*
9290
* @var string
9391
*/
9492
protected $_massactionBlockName = \Magento\Backend\Block\Widget\Grid\Massaction\Extended::class;
@@ -122,8 +120,6 @@ class Extended extends \Magento\Backend\Block\Widget\Grid implements \Magento\Ba
122120
protected $_headersVisibility = true;
123121

124122
/**
125-
* Filter visibility
126-
*
127123
* @var boolean
128124
*/
129125
protected $_filterVisibility = true;
@@ -148,15 +144,11 @@ class Extended extends \Magento\Backend\Block\Widget\Grid implements \Magento\Ba
148144
protected $_isCollapsed;
149145

150146
/**
151-
* Count subtotals
152-
*
153147
* @var boolean
154148
*/
155149
protected $_countSubTotals = false;
156150

157151
/**
158-
* SubTotals
159-
*
160152
* @var \Magento\Framework\DataObject[]
161153
*/
162154
protected $_subtotals = [];
@@ -1048,6 +1040,7 @@ public function getCsvFile()
10481040
* Retrieve Grid data as CSV
10491041
*
10501042
* @return string
1043+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
10511044
*/
10521045
public function getCsv()
10531046
{
@@ -1074,7 +1067,7 @@ public function getCsv()
10741067
$data[] = '"' . str_replace(
10751068
['"', '\\'],
10761069
['""', '\\\\'],
1077-
$column->getRowFieldExport($item)
1070+
$column->getRowFieldExport($item) ?: ''
10781071
) . '"';
10791072
}
10801073
}
@@ -1088,7 +1081,7 @@ public function getCsv()
10881081
$data[] = '"' . str_replace(
10891082
['"', '\\'],
10901083
['""', '\\\\'],
1091-
$column->getRowFieldExport($this->getTotals())
1084+
$column->getRowFieldExport($this->getTotals()) ?: ''
10921085
) . '"';
10931086
}
10941087
}

app/code/Magento/Backend/Model/Menu/Config/Menu/Dom.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Backend\Model\Menu\Config\Menu;
77

8+
use DOMElement;
9+
use Magento\Framework\Exception\LocalizedException;
10+
811
/**
912
* Menu configuration files handler
1013
* @api
@@ -16,13 +19,13 @@ class Dom extends \Magento\Framework\Config\Dom
1619
* Getter for node by path
1720
*
1821
* @param string $nodePath
19-
* @return \DOMElement|null
20-
* @throws \Magento\Framework\Exception\LocalizedException an exception is possible if original document contains
22+
* @return DOMElement|null
23+
* @throws LocalizedException an exception is possible if original document contains
2124
* multiple fixed nodes
2225
*/
2326
protected function _getMatchedNode($nodePath)
2427
{
25-
if (!preg_match('/^\/config(\/menu)?$/i', $nodePath)) {
28+
if (!$nodePath || !preg_match('/^\/config(\/menu)?$/i', $nodePath)) {
2629
return null;
2730
}
2831
return parent::_getMatchedNode($nodePath);

app/code/Magento/Backend/Model/Widget/Grid/Parser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ class Parser
2727
public function parseExpression($expression)
2828
{
2929
$stack = [];
30-
$expression = trim($expression);
30+
$expression = $expression ? trim($expression) : '';
3131
foreach ($this->_operations as $operation) {
3232
$splittedExpr = preg_split('/\\' . $operation . '/', $expression, -1, PREG_SPLIT_DELIM_CAPTURE);
3333
$count = count($splittedExpr);
3434
if ($count > 1) {
3535
for ($i = 0; $i < $count; $i++) {
36+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
3637
$stack = array_merge($stack, $this->parseExpression($splittedExpr[$i]));
3738
if ($i > 0) {
3839
$stack[] = $operation;

app/code/Magento/Backup/Helper/Data.php

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,51 @@
88

99
namespace Magento\Backup\Helper;
1010

11+
use Magento\Backup\Model\Backup;
12+
use Magento\Framework\App\Cache\TypeListInterface;
1113
use Magento\Framework\App\Filesystem\DirectoryList;
14+
use Magento\Framework\App\Helper\AbstractHelper;
15+
use Magento\Framework\App\Helper\Context;
1216
use Magento\Framework\App\MaintenanceMode;
17+
use Magento\Framework\AuthorizationInterface;
18+
use Magento\Framework\Backup\Factory;
1319
use Magento\Framework\Filesystem;
1420

1521
/**
1622
* Backup data helper
1723
* @api
1824
* @since 100.0.2
1925
*/
20-
class Data extends \Magento\Framework\App\Helper\AbstractHelper
26+
class Data extends AbstractHelper
2127
{
2228
/**
2329
* @var Filesystem
2430
*/
2531
protected $_filesystem;
2632

2733
/**
28-
* @var \Magento\Framework\AuthorizationInterface
34+
* @var AuthorizationInterface
2935
*/
3036
protected $_authorization;
3137

3238
/**
33-
* @var \Magento\Framework\App\Cache\TypeListInterface
39+
* @var TypeListInterface
3440
*/
3541
protected $_cacheTypeList;
3642

3743
/**
3844
* Construct
3945
*
40-
* @param \Magento\Framework\App\Helper\Context $context
46+
* @param Context $context
4147
* @param Filesystem $filesystem
42-
* @param \Magento\Framework\AuthorizationInterface $authorization
43-
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
48+
* @param AuthorizationInterface $authorization
49+
* @param TypeListInterface $cacheTypeList
4450
*/
4551
public function __construct(
46-
\Magento\Framework\App\Helper\Context $context,
52+
Context $context,
4753
Filesystem $filesystem,
48-
\Magento\Framework\AuthorizationInterface $authorization,
49-
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
54+
AuthorizationInterface $authorization,
55+
TypeListInterface $cacheTypeList
5056
) {
5157
parent::__construct($context);
5258
$this->_authorization = $authorization;
@@ -62,10 +68,10 @@ public function __construct(
6268
public function getBackupTypes()
6369
{
6470
return [
65-
\Magento\Framework\Backup\Factory::TYPE_DB => __('Database'),
66-
\Magento\Framework\Backup\Factory::TYPE_MEDIA => __('Database and Media'),
67-
\Magento\Framework\Backup\Factory::TYPE_SYSTEM_SNAPSHOT => __('System'),
68-
\Magento\Framework\Backup\Factory::TYPE_SNAPSHOT_WITHOUT_MEDIA => __('System (excluding Media)')
71+
Factory::TYPE_DB => __('Database'),
72+
Factory::TYPE_MEDIA => __('Database and Media'),
73+
Factory::TYPE_SYSTEM_SNAPSHOT => __('System'),
74+
Factory::TYPE_SNAPSHOT_WITHOUT_MEDIA => __('System (excluding Media)')
6975
];
7076
}
7177

@@ -77,10 +83,10 @@ public function getBackupTypes()
7783
public function getBackupTypesList()
7884
{
7985
return [
80-
\Magento\Framework\Backup\Factory::TYPE_DB,
81-
\Magento\Framework\Backup\Factory::TYPE_SYSTEM_SNAPSHOT,
82-
\Magento\Framework\Backup\Factory::TYPE_SNAPSHOT_WITHOUT_MEDIA,
83-
\Magento\Framework\Backup\Factory::TYPE_MEDIA
86+
Factory::TYPE_DB,
87+
Factory::TYPE_SYSTEM_SNAPSHOT,
88+
Factory::TYPE_SNAPSHOT_WITHOUT_MEDIA,
89+
Factory::TYPE_MEDIA
8490
];
8591
}
8692

@@ -91,7 +97,7 @@ public function getBackupTypesList()
9197
*/
9298
public function getDefaultBackupType()
9399
{
94-
return \Magento\Framework\Backup\Factory::TYPE_DB;
100+
return Factory::TYPE_DB;
95101
}
96102

97103
/**
@@ -124,22 +130,22 @@ public function getExtensionByType($type)
124130
public function getExtensions()
125131
{
126132
return [
127-
\Magento\Framework\Backup\Factory::TYPE_SYSTEM_SNAPSHOT => 'tgz',
128-
\Magento\Framework\Backup\Factory::TYPE_SNAPSHOT_WITHOUT_MEDIA => 'tgz',
129-
\Magento\Framework\Backup\Factory::TYPE_MEDIA => 'tgz',
130-
\Magento\Framework\Backup\Factory::TYPE_DB => 'sql'
133+
Factory::TYPE_SYSTEM_SNAPSHOT => 'tgz',
134+
Factory::TYPE_SNAPSHOT_WITHOUT_MEDIA => 'tgz',
135+
Factory::TYPE_MEDIA => 'tgz',
136+
Factory::TYPE_DB => 'sql'
131137
];
132138
}
133139

134140
/**
135141
* Generate backup download name
136142
*
137-
* @param \Magento\Backup\Model\Backup $backup
143+
* @param Backup $backup
138144
* @return string
139145
*/
140-
public function generateBackupDownloadName(\Magento\Backup\Model\Backup $backup)
146+
public function generateBackupDownloadName(Backup $backup)
141147
{
142-
$additionalExtension = $backup->getType() == \Magento\Framework\Backup\Factory::TYPE_DB ? '.sql' : '';
148+
$additionalExtension = $backup->getType() == Factory::TYPE_DB ? '.sql' : '';
143149
return $backup->getTime() .
144150
'_' .
145151
$backup->getType() .
@@ -213,12 +219,12 @@ public function getRollbackIgnorePaths()
213219
public function getCreateSuccessMessageByType($type)
214220
{
215221
$messagesMap = [
216-
\Magento\Framework\Backup\Factory::TYPE_SYSTEM_SNAPSHOT => __('You created the system backup.'),
217-
\Magento\Framework\Backup\Factory::TYPE_SNAPSHOT_WITHOUT_MEDIA => __(
222+
Factory::TYPE_SYSTEM_SNAPSHOT => __('You created the system backup.'),
223+
Factory::TYPE_SNAPSHOT_WITHOUT_MEDIA => __(
218224
'You created the system backup (excluding media).'
219225
),
220-
\Magento\Framework\Backup\Factory::TYPE_MEDIA => __('You created the database and media backup.'),
221-
\Magento\Framework\Backup\Factory::TYPE_DB => __('You created the database backup.'),
226+
Factory::TYPE_MEDIA => __('You created the database and media backup.'),
227+
Factory::TYPE_DB => __('You created the database backup.'),
222228
];
223229

224230
if (!isset($messagesMap[$type])) {
@@ -263,7 +269,7 @@ public function extractDataFromFilename($filename)
263269
{
264270
$extensions = $this->getExtensions();
265271

266-
$filenameWithoutExtension = $filename;
272+
$filenameWithoutExtension = $filename ?: '';
267273

268274
foreach ($extensions as $extension) {
269275
$filenameWithoutExtension = preg_replace(

app/code/Magento/Backup/Model/ResourceModel/Helper.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Magento\Backup\Model\ResourceModel;
88

9+
use Magento\Framework\App\ResourceConnection;
10+
use Magento\Framework\Stdlib\DateTime\DateTime;
11+
912
/**
1013
* @api
1114
* @since 100.0.2
@@ -21,21 +24,19 @@ class Helper extends \Magento\Framework\DB\Helper
2124
protected $_foreignKeys = [];
2225

2326
/**
24-
* Core Date
25-
*
26-
* @var \Magento\Framework\Stdlib\DateTime\DateTime
27+
* @var DateTime
2728
*/
2829
protected $_coreDate;
2930

3031
/**
31-
* @param \Magento\Framework\App\ResourceConnection $resource
32+
* @param ResourceConnection $resource
3233
* @param string $modulePrefix
33-
* @param \Magento\Framework\Stdlib\DateTime\DateTime $coreDate
34+
* @param DateTime $coreDate
3435
*/
3536
public function __construct(
36-
\Magento\Framework\App\ResourceConnection $resource,
37+
ResourceConnection $resource,
3738
$modulePrefix,
38-
\Magento\Framework\Stdlib\DateTime\DateTime $coreDate
39+
DateTime $coreDate
3940
) {
4041
parent::__construct($resource, $modulePrefix);
4142
$this->_coreDate = $coreDate;
@@ -153,8 +154,8 @@ public function getTableCreateSql($tableName, $withForeignKeys = false)
153154
$connection->quoteIdentifier($match[2]),
154155
$connection->quoteIdentifier($match[3]),
155156
$connection->quoteIdentifier($match[4]),
156-
isset($match[5]) ? $match[5] : '',
157-
isset($match[7]) ? $match[7] : ''
157+
$match[5] ?? '',
158+
$match[7] ?? ''
158159
);
159160
}
160161
}
@@ -307,7 +308,7 @@ protected function _quoteRow($tableName, array $row)
307308
foreach ($row as $key => $data) {
308309
if ($data === null) {
309310
$value = 'NULL';
310-
} elseif (in_array(strtolower($describe[$key]['DATA_TYPE']), $dataTypes)) {
311+
} elseif (in_array(strtolower($describe[$key]['DATA_TYPE'] ?? ''), $dataTypes)) {
311312
$value = $data;
312313
} else {
313314
$value = $connection->quoteInto('?', $data);
@@ -350,7 +351,7 @@ public function restoreTransactionIsolationLevel()
350351
public function getTableTriggersSql($tableName, $addDropIfExists = false, $stripDefiner = true)
351352
{
352353
$script = "--\n-- Triggers structure for table `{$tableName}`\n--\n";
353-
$triggers = $this->getConnection()->query('SHOW TRIGGERS LIKE \''. $tableName . '\'')->fetchAll();
354+
$triggers = $this->getConnection()->query('SHOW TRIGGERS LIKE \'' . $tableName . '\'')->fetchAll();
354355

355356
if (!$triggers) {
356357
return '';
@@ -361,7 +362,7 @@ public function getTableTriggersSql($tableName, $addDropIfExists = false, $strip
361362
}
362363
$script .= "delimiter ;;\n";
363364

364-
$triggerData = $this->getConnection()->query('SHOW CREATE TRIGGER '. $trigger['Trigger'])->fetch();
365+
$triggerData = $this->getConnection()->query('SHOW CREATE TRIGGER ' . $trigger['Trigger'])->fetch();
365366
if ($stripDefiner) {
366367
$cleanedScript = preg_replace('/DEFINER=[^\s]*/', '', $triggerData['SQL Original Statement']);
367368
$script .= $cleanedScript . "\n";

0 commit comments

Comments
 (0)