Skip to content

Commit 5934b72

Browse files
committed
Merge remote-tracking branch 'origin/AC-3161-fix-potential-issues-php-p12' into delivery-bunch-w22
2 parents a89f34c + e156d4f commit 5934b72

File tree

12 files changed

+35
-39
lines changed

12 files changed

+35
-39
lines changed

lib/internal/Magento/Framework/Config/Composer/Package.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function getJson($formatted = true, $format = null)
6565
*/
6666
public function get($propertyPath, $filter = null)
6767
{
68-
$result = $this->traverseGet($this->json, explode('->', $propertyPath));
68+
$result = $this->traverseGet($this->json, explode('->', $propertyPath ?: ''));
6969
if ($result && $filter) {
7070
foreach ($result as $key => $value) {
7171
if (!preg_match($filter, $key)) {

lib/internal/Magento/Framework/Config/Converter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
/**
1111
* Class Converter convert xml to appropriate array
12-
*
13-
* @package Magento\Framework\Config
1412
*/
1513
class Converter implements \Magento\Framework\Config\ConverterInterface
1614
{
@@ -103,9 +101,11 @@ protected function parseVarElement(\DOMElement $node)
103101
}
104102
}
105103
if (!count($result)) {
106-
$result = (strtolower($node->nodeValue) !== 'true' && strtolower($node->nodeValue) !== 'false')
107-
? $node->nodeValue
108-
: filter_var($node->nodeValue, FILTER_VALIDATE_BOOLEAN);
104+
$result = (
105+
$node->nodeValue !== null
106+
&& strtolower($node->nodeValue) !== 'true'
107+
&& strtolower($node->nodeValue) !== 'false'
108+
) ? $node->nodeValue : filter_var($node->nodeValue, FILTER_VALIDATE_BOOLEAN);
109109
}
110110
return $result;
111111
}

lib/internal/Magento/Framework/Config/Data/ConfigData.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@
1414
class ConfigData
1515
{
1616
/**
17-
* File key
18-
*
1917
* @var string
2018
*/
2119
private $fileKey;
2220

2321
/**
24-
* Data
25-
*
2622
* @var array
2723
*/
2824
private $data = [];
@@ -124,7 +120,7 @@ public function set($path, $value)
124120
*/
125121
private function expand($path)
126122
{
127-
$chunks = explode('/', $path);
123+
$chunks = explode('/', $path ?: '');
128124

129125
foreach ($chunks as $chunk) {
130126
if ('' == $chunk) {

lib/internal/Magento/Framework/Config/Dom.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
use Magento\Framework\Phrase;
1515

1616
/**
17-
* Class Dom
18-
*
1917
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2018
* @api
2119
* @since 100.0.2
@@ -25,12 +23,12 @@ class Dom
2523
/**
2624
* Prefix which will be used for root namespace
2725
*/
28-
const ROOT_NAMESPACE_PREFIX = 'x';
26+
public const ROOT_NAMESPACE_PREFIX = 'x';
2927

3028
/**
3129
* Format of items in errors array to be used by default. Available placeholders - fields of \LibXMLError.
3230
*/
33-
const ERROR_FORMAT_DEFAULT = "%message%\nLine: %line%\n";
31+
public const ERROR_FORMAT_DEFAULT = "%message%\nLine: %line%\n";
3432

3533
/**
3634
* @var \Magento\Framework\Config\ValidationStateInterface
@@ -262,6 +260,8 @@ private function findCdataSection($node)
262260
return $childNode;
263261
}
264262
}
263+
264+
return null;
265265
}
266266

267267
/**
@@ -407,9 +407,9 @@ private static function _renderErrorMessage(\LibXMLError $errorInfo, $format)
407407
foreach ($errorInfo as $field => $value) {
408408
$placeholder = '%' . $field . '%';
409409
$value = trim((string)$value);
410-
$result = str_replace($placeholder, $value, $result);
410+
$result = $result !== null ? str_replace($placeholder, $value, $result) : '';
411411
}
412-
if (strpos($result, '%') !== false) {
412+
if ($result && strpos($result, '%') !== false) {
413413
if (preg_match_all('/%.+%/', $result, $matches)) {
414414
$unsupported = [];
415415
foreach ($matches[0] as $placeholder) {

lib/internal/Magento/Framework/Config/Dom/NodePathMatcher.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public function match($pathPattern, $xpathSubject)
3232
*/
3333
protected function simplifyXpath($xpath)
3434
{
35-
$result = $xpath;
35+
$result = $xpath ?: '';
3636
$result = preg_replace('/\[@[^\]]+?\]/', '', $result);
37-
$result = preg_replace('/\/[^:]+?\:/', '/', $result);
38-
return $result;
37+
38+
return preg_replace('/\/[^:]+?\:/', '/', $result);
3939
}
4040
}

lib/internal/Magento/Framework/Config/Dom/UrnResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class UrnResolver
2929
*/
3030
public function getRealPath($schema)
3131
{
32-
if (strpos($schema, 'urn:') !== 0) {
32+
if ($schema && strpos($schema, 'urn:') !== 0) {
3333
return $schema;
3434
}
3535

@@ -75,7 +75,7 @@ public function getRealPath($schema)
7575
*/
7676
public function registerEntityLoader($public, $system, $context)
7777
{
78-
if (strpos($system, 'urn:') === 0) {
78+
if ($system && strpos($system, 'urn:') === 0) {
7979
$filePath = $this->getRealPath($system);
8080
} else {
8181
if (file_exists($system)) {

lib/internal/Magento/Framework/Config/View.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function getVarValue($module, $var)
9090
}
9191

9292
$value = $this->data['vars'][$module];
93-
foreach (explode('/', $var) as $node) {
93+
foreach (explode('/', $var ?: '') as $node) {
9494
if (is_array($value) && isset($value[$node])) {
9595
$value = $value[$node];
9696
} else {
@@ -200,7 +200,8 @@ protected function initData()
200200
}
201201

202202
/**
203-
* {@inheritdoc}
203+
* @inheritdoc
204+
*
204205
* @since 100.1.0
205206
*/
206207
public function read($scope = null)

lib/internal/Magento/Framework/Console/QuestionPerformer/YesNo.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function execute(array $messages, InputInterface $input, OutputInterface
6262
$question = $this->getConfirmationQuestion($messages);
6363
$answer = $this->questionHelper->ask($input, $output, $question);
6464

65-
return in_array(strtolower($answer), ['yes', 'y']);
65+
return in_array(strtolower($answer ?? ''), ['yes', 'y']);
6666
}
6767

6868
/**
@@ -80,7 +80,7 @@ private function getConfirmationQuestion(array $messages)
8080
]);
8181

8282
$question->setValidator(function ($answer) {
83-
if (!in_array(strtolower($answer), ['yes', 'y', 'no', 'n'])) {
83+
if (!in_array(strtolower($answer ?? ''), ['yes', 'y', 'no', 'n'])) {
8484
throw new LocalizedException(
8585
new Phrase('A [y]es or [n]o selection needs to be made. Select and try again.')
8686
);

lib/internal/Magento/Framework/Convert/DataSize.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ class DataSize
1313
{
1414
/**
1515
* Converts a size value to bytes
16+
*
1617
* Example input: 100 (bytes), 10K (kilobytes), 13M (megabytes), 2G (gigabytes)
1718
*
1819
* @param string $size
1920
* @return integer
2021
*/
2122
public function convertSizeToBytes($size)
2223
{
23-
if (!is_numeric($size)) {
24+
if ($size && !is_numeric($size)) {
2425
$type = strtoupper(substr($size, -1));
2526
$size = (int)$size;
2627

lib/internal/Magento/Framework/Crontab/CrontabManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function getTasks()
7878
$pattern = '!(' . $this->getTasksBlockStart() . ')(.*?)(' . $this->getTasksBlockEnd() . ')!s';
7979

8080
if (preg_match($pattern, $content, $matches)) {
81-
$tasks = trim($matches[2], PHP_EOL);
81+
$tasks = trim($matches[2] ?? '', PHP_EOL);
8282
$tasks = explode(PHP_EOL, $tasks);
8383
return $tasks;
8484
}

0 commit comments

Comments
 (0)