Skip to content

Commit 473bac9

Browse files
committed
Merge remote-tracking branch 'origin/AC-3162-p14' into delivery-bunch-w22
2 parents 5934b72 + 87efa82 commit 473bac9

File tree

14 files changed

+81
-46
lines changed

14 files changed

+81
-46
lines changed

lib/internal/Magento/Framework/Setup/SchemaListener.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ class SchemaListener
2121
/**
2222
* Ignore all ddl queries.
2323
*/
24-
const IGNORE_ON = 0;
24+
public const IGNORE_ON = 0;
2525

2626
/**
2727
* Disable ignore mode.
2828
*/
29-
const IGNORE_OFF = 1;
29+
public const IGNORE_OFF = 1;
3030

3131
/**
3232
* Staging FK keys installer key. Indicates that changes should be moved from ordinary module to staging module.
3333
*/
34-
const STAGING_FK_KEYS = 2;
34+
public const STAGING_FK_KEYS = 2;
3535

3636
/**
3737
* @var array
@@ -131,7 +131,7 @@ private function castColumnDefinition($definition, $columnName)
131131
$definition = ['type' => $definition];
132132
}
133133
$definition = $this->doColumnMapping($definition);
134-
$definition['name'] = strtolower($columnName);
134+
$definition['name'] = $columnName !== null ? strtolower($columnName) : '';
135135
$definitionType = $definition['type'] === 'int' ? 'integer' : $definition['type'];
136136
$columnComment = $definition['comment'] ?? null;
137137
$definition = $this->definitionMappers[$definitionType]->convertToDefinition($definition);
@@ -160,7 +160,7 @@ private function addPrimaryKeyIfExists($tableName, $columnName, $definition, $pr
160160
'type' => 'primary',
161161
'name' => $primaryKeyName,
162162
'disabled' => false,
163-
'columns' => [$columnName => strtolower($columnName)]
163+
'columns' => [$columnName => $columnName !== null ? strtolower($columnName) : '']
164164
];
165165

166166
$this->log($tableName, $dataToLog);
@@ -180,9 +180,9 @@ private function addPrimaryKeyIfExists($tableName, $columnName, $definition, $pr
180180
public function renameTable($oldTableName, $newTableName)
181181
{
182182
$moduleName = $this->getModuleName();
183-
183+
$oldTableName = (string)$oldTableName;
184184
if (isset($this->tables[$moduleName][strtolower($oldTableName)])) {
185-
$this->tables[$moduleName][strtolower($newTableName)] =
185+
$this->tables[$moduleName][strtolower((string)$newTableName)] =
186186
$this->tables[$moduleName][strtolower($oldTableName)];
187187
unset($this->tables[$moduleName][strtolower($oldTableName)]);
188188
}
@@ -224,7 +224,7 @@ public function addColumn($tableName, $columnName, $definition, $primaryKeyName
224224
$definition = $this->castColumnDefinition($definition, $columnName);
225225
$definition = $this->addPrimaryKeyIfExists($tableName, $columnName, $definition, $primaryKeyName);
226226
$definition['onCreate'] = $onCreate;
227-
$dataToLog['columns'][strtolower($columnName)] = $definition;
227+
$dataToLog['columns'][strtolower((string)$columnName)] = $definition;
228228
$this->log($tableName, $dataToLog);
229229
}
230230

@@ -258,7 +258,7 @@ public function dropIndex($tableName, $keyName, $indexType)
258258
*/
259259
public function dropColumn($tableName, $columnName)
260260
{
261-
$dataToLog['columns'][strtolower($columnName)] = [
261+
$dataToLog['columns'][strtolower((string)$columnName)] = [
262262
'disabled' => true
263263
];
264264
$this->log($tableName, $dataToLog);
@@ -332,6 +332,7 @@ public function log($tableName, array $dataToLog)
332332
return;
333333
}
334334
$moduleName = $this->getModuleName();
335+
$tableName = (string)$tableName;
335336
if (isset($this->tables[$moduleName][strtolower($tableName)])) {
336337
$this->tables[$moduleName][strtolower($tableName)] = array_replace_recursive(
337338
$this->tables[$moduleName][strtolower($tableName)],
@@ -364,10 +365,10 @@ public function addForeignKey(
364365
) {
365366
$dataToLog['constraints']['foreign'][$fkName] =
366367
[
367-
'table' => strtolower($tableName),
368-
'column' => strtolower($columnName),
369-
'referenceTable' => strtolower($refTableName),
370-
'referenceColumn' => strtolower($refColumnName),
368+
'table' => $tableName !== null ? strtolower($tableName) : '',
369+
'column' => $columnName !== null ? strtolower($columnName) : '',
370+
'referenceTable' => $refTableName !== null ? strtolower($refTableName) : '',
371+
'referenceColumn' => $refColumnName !== null ? strtolower($refColumnName) : '',
371372
'onDelete' => $onDelete,
372373
'disabled' => false
373374
];
@@ -486,7 +487,7 @@ private function prepareConstraintsAndIndexes(array $foreignKeys, array $indexes
486487
*/
487488
public function createTable(Table $table)
488489
{
489-
$engine = strtolower($table->getOption('type'));
490+
$engine = strtolower($table->getOption('type') ?? '');
490491
$this->tables[$this->getModuleName()][strtolower($table->getName())] =
491492
[
492493
'engine' => $engine,
@@ -523,6 +524,7 @@ public function toogleIgnore($flag)
523524
*/
524525
public function dropTable($tableName)
525526
{
527+
$tableName = (string)$tableName;
526528
if (isset($this->tables[$this->getModuleName()][strtolower($tableName)])) {
527529
unset($this->tables[$this->getModuleName()][strtolower($tableName)]);
528530
} else {

lib/internal/Magento/Framework/Shell/ComplexParameter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ComplexParameter
1616
/**
1717
* Default regex pattern for searching the parameter
1818
*/
19-
const DEFAULT_PATTERN = '/^\-\-%s=(.+)$/';
19+
public const DEFAULT_PATTERN = '/^\-\-%s=(.+)$/';
2020

2121
/**
2222
* Argument name
@@ -69,7 +69,7 @@ public function getFromArray($input)
6969
*/
7070
public function getFromString($string)
7171
{
72-
if (preg_match($this->pcre, $string, $matches)) {
72+
if (preg_match((string)$this->pcre, (string)$string, $matches)) {
7373
parse_str($matches[1], $result);
7474
return $result;
7575
}

lib/internal/Magento/Framework/Simplexml/Element.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public function descend($path)
112112
// Simple exploding by / does not suffice,
113113
// as an attribute value may contain a / inside
114114
// Note that there are three matches for different kinds of attribute values specification
115+
$path = $path !== null ? $path : '';
115116
if (strpos($path, "@") === false) {
116117
$pathArr = explode('/', $path);
117118
} else {
@@ -126,10 +127,10 @@ public function descend($path)
126127
foreach ($pathArr as $nodeName) {
127128
if (strpos($nodeName, '@') !== false) {
128129
$a = explode('@', $nodeName);
129-
$b = explode('=', $a[1]);
130+
$b = explode('=', $a[1] ?? '');
130131
$nodeName = $a[0];
131132
$attributeName = $b[0];
132-
$attributeValue = $b[1];
133+
$attributeValue = $b[1] ?? '';
133134
//
134135
// Does a very simplistic trimming of attribute value.
135136
//
@@ -446,7 +447,7 @@ public function extendChild($source, $overwrite = false)
446447
*/
447448
public function setNode($path, $value, $overwrite = true)
448449
{
449-
$arr1 = explode('/', $path);
450+
$arr1 = explode('/', (string)$path);
450451
$arr = [];
451452
foreach ($arr1 as $v) {
452453
if (!empty($v)) {

lib/internal/Magento/Framework/Stdlib/StringUtils.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class StringUtils
2828
*/
2929
public function upperCaseWords($str, $sourceSeparator = '_', $destinationSeparator = '_')
3030
{
31+
$destinationSeparator = $destinationSeparator !== null ? $destinationSeparator : '';
32+
$sourceSeparator = $sourceSeparator !== null ? $sourceSeparator : '';
33+
$str = $str !== null ? $str : '';
3134
return str_replace(' ', $destinationSeparator, ucwords(str_replace($sourceSeparator, ' ', $str)));
3235
}
3336

@@ -79,6 +82,7 @@ public function split($value, $length = 1, $keepWords = false, $trim = false, $w
7982
if (!$strLen || !is_int($length) || $length <= 0) {
8083
return $result;
8184
}
85+
$value = $value !== null ? $value : '';
8286
if ($trim) {
8387
$value = trim(preg_replace('/\s{2,}/siu', ' ', $value));
8488
}
@@ -209,6 +213,6 @@ public function strrev($str)
209213
*/
210214
public function strpos($haystack, $needle, $offset = null)
211215
{
212-
return mb_strpos($haystack, $needle, $offset ?? 0, self::ICONV_CHARSET);
216+
return mb_strpos((string)$haystack, (string)$needle, $offset ?? 0, self::ICONV_CHARSET);
213217
}
214218
}

lib/internal/Magento/Framework/System/Ftp.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Ftp
2727
protected function checkConnected()
2828
{
2929
if (!$this->_conn) {
30+
// phpcs:ignore Magento2.Exceptions.DirectThrow
3031
throw new \Exception(__CLASS__ . " - no connection established with server");
3132
}
3233
}
@@ -53,7 +54,7 @@ public function mdkir($name)
5354
public function mkdirRecursive($path, $mode = 0777)
5455
{
5556
$this->checkConnected();
56-
$dir = explode("/", $path);
57+
$dir = explode("/", (string)$path);
5758
$path = "";
5859
$ret = true;
5960
for ($i = 0, $count = count($dir); $i < $count; $i++) {
@@ -84,6 +85,7 @@ public function login($login = "anonymous", $password = "test@gmail.com")
8485
$this->checkConnected();
8586
$res = @ftp_login($this->_conn, $login, $password);
8687
if (!$res) {
88+
// phpcs:ignore Magento2.Exceptions.DirectThrow
8789
throw new \Exception("Invalid login credentials");
8890
}
8991
return $res;
@@ -100,17 +102,19 @@ public function validateConnectionString($string)
100102
{
101103
$data = parse_url($string);
102104
if (false === $data) {
105+
// phpcs:ignore Magento2.Exceptions.DirectThrow
103106
throw new \Exception("Connection string invalid: '{$string}'");
104107
}
105108
if ($data['scheme'] != 'ftp') {
109+
// phpcs:ignore Magento2.Exceptions.DirectThrow
106110
throw new \Exception("Support for scheme unsupported: '{$data['scheme']}'");
107111
}
108-
112+
109113
// Decode user & password strings from URL
110114
foreach (array_intersect(array_keys($data), ['user','pass']) as $key) {
111115
$data[$key] = urldecode($data[$key]);
112116
}
113-
117+
114118
return $data;
115119
}
116120

@@ -132,6 +136,7 @@ public function connect($string, $timeout = 900)
132136
$this->_conn = ftp_connect($params['host'], $port, $timeout);
133137

134138
if (!$this->_conn) {
139+
// phpcs:ignore Magento2.Exceptions.DirectThrow
135140
throw new \Exception("Cannot connect to host: {$params['host']}");
136141
}
137142
if (isset($params['user']) && isset($params['pass'])) {
@@ -141,6 +146,7 @@ public function connect($string, $timeout = 900)
141146
}
142147
if (isset($params['path'])) {
143148
if (!$this->chdir($params['path'])) {
149+
// phpcs:ignore Magento2.Exceptions.DirectThrow
144150
throw new \Exception("Cannot chdir after login to: {$params['path']}");
145151
}
146152
}
@@ -151,7 +157,7 @@ public function connect($string, $timeout = 900)
151157
*
152158
* @param string $remoteFile
153159
* @param resource $handle
154-
* @param int $mode FTP_BINARY | FTP_ASCII
160+
* @param int $mode FTP_BINARY | FTP_ASCII
155161
* @param int $startPos
156162
* @return bool
157163
*/
@@ -184,7 +190,7 @@ public function put($remoteFile, $localFile, $mode = FTP_BINARY, $startPos = 0)
184190
public function getcwd()
185191
{
186192
$d = $this->raw("pwd");
187-
$data = explode(" ", $d[0], 3);
193+
$data = explode(" ", $d[0] ?? '', 3);
188194
if (empty($data[1])) {
189195
return false;
190196
}
@@ -228,19 +234,23 @@ public function upload($remote, $local, $dirMode = 0777, $ftpMode = FTP_BINARY)
228234
$this->checkConnected();
229235

230236
if (!file_exists($local)) {
237+
// phpcs:ignore Magento2.Exceptions.DirectThrow
231238
throw new \Exception("Local file doesn't exist: {$local}");
232239
}
233240
if (!is_readable($local)) {
241+
// phpcs:ignore Magento2.Exceptions.DirectThrow
234242
throw new \Exception("Local file is not readable: {$local}");
235243
}
236244
if (is_dir($local)) {
245+
// phpcs:ignore Magento2.Exceptions.DirectThrow
237246
throw new \Exception("Directory given instead of file: {$local}");
238247
}
239248

240-
$globalPathMode = substr($remote, 0, 1) == "/";
249+
$globalPathMode = substr((string)$remote, 0, 1) == "/";
241250
$dirname = dirname($remote);
242251
$cwd = $this->getcwd();
243252
if (false === $cwd) {
253+
// phpcs:ignore Magento2.Exceptions.DirectThrow
244254
throw new \Exception("Server returns something awful on PWD command");
245255
}
246256

@@ -262,7 +272,7 @@ public function upload($remote, $local, $dirMode = 0777, $ftpMode = FTP_BINARY)
262272
*
263273
* @param string $remote
264274
* @param string $local
265-
* @param int $ftpMode FTP_BINARY|FTP_ASCII
275+
* @param int $ftpMode FTP_BINARY|FTP_ASCII
266276
* @return bool
267277
*/
268278
public function download($remote, $local, $ftpMode = FTP_BINARY)
@@ -336,7 +346,7 @@ public function cdup()
336346
*
337347
* @param string $localFile
338348
* @param string $remoteFile
339-
* @param int $fileMode FTP_BINARY | FTP_ASCII
349+
* @param int $fileMode FTP_BINARY | FTP_ASCII
340350
* @param int $resumeOffset
341351
* @return bool
342352
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
@@ -397,7 +407,7 @@ public static function byteconvert($bytes)
397407
public static function chmodnum($chmod)
398408
{
399409
$trans = ['-' => '0', 'r' => '4', 'w' => '2', 'x' => '1'];
400-
$chmod = substr(strtr($chmod, $trans), 1);
410+
$chmod = $chmod !== null ? substr(strtr($chmod, $trans), 1) : '';
401411
$array = str_split($chmod, 3);
402412
return array_sum(str_split($array[0])) . array_sum(str_split($array[1])) . array_sum(str_split($array[2]));
403413
}
@@ -477,6 +487,10 @@ public function ls($dir = "/", $recursive = false)
477487
*/
478488
public function correctFilePath($str)
479489
{
490+
if ($str === null) {
491+
return '';
492+
}
493+
480494
$str = str_replace("\\", "/", $str);
481495
$str = preg_replace("/^.\//", "", $str);
482496
return $str;

lib/internal/Magento/Framework/TestFramework/Unit/Autoloader/ExtensionAttributesGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function generate($className)
4545
private function isExtension($className)
4646
{
4747
$suffix = "Extension";
48-
$sourceName = rtrim(substr($className, 0, -strlen($suffix)), '\\');
48+
$sourceName = $className !== null ? rtrim(substr($className, 0, -strlen($suffix)), '\\') : '';
4949
return $sourceName . $suffix == $className;
5050
}
5151
}

lib/internal/Magento/Framework/TestFramework/Unit/Autoloader/ExtensionAttributesInterfaceGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function generate($className)
4545
private function isExtensionInterface($className)
4646
{
4747
$suffix = "ExtensionInterface";
48-
$sourceName = rtrim(substr($className, 0, -strlen($suffix)), '\\');
48+
$sourceName = $className !== null ? rtrim(substr($className, 0, -strlen($suffix)), '\\') : '';
4949
return $sourceName . $suffix == $className;
5050
}
5151
}

lib/internal/Magento/Framework/TestFramework/Unit/Autoloader/FactoryGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function generate($className)
4343
*/
4444
private function isFactory($className)
4545
{
46-
if (!preg_match('/[\\\A-Z]/', substr(ltrim($className), 0, 1))) {
46+
if ($className === null || !preg_match('/[\\\A-Z]/', substr(ltrim($className), 0, 1))) {
4747
return false;
4848
}
4949
$sourceName = rtrim(substr($className, 0, -strlen('Factory')), '\\');

lib/internal/Magento/Framework/Unserialize/Unserialize.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ public function __construct(Serialize $serializer = null)
3030
}
3131

3232
/**
33+
* Unserialize
34+
*
3335
* @param string $string
3436
* @return bool|mixed
3537
*/
3638
public function unserialize($string)
3739
{
38-
if (preg_match('/[oc]:[+\-]?\d+:"/i', $string)) {
40+
if ($string !== null && preg_match('/[oc]:[+\-]?\d+:"/i', $string)) {
3941
trigger_error('String contains serialized object');
4042
return false;
4143
}

lib/internal/Magento/Framework/Url.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,10 @@ public function getRebuiltUrl($url)
10111011
*/
10121012
public function escape($value)
10131013
{
1014+
if ($value === null) {
1015+
return '';
1016+
}
1017+
10141018
$value = str_replace('"', '%22', $value);
10151019
$value = str_replace("'", '%27', $value);
10161020
$value = str_replace('>', '%3E', $value);
@@ -1107,7 +1111,7 @@ public function getRedirectUrl($url)
11071111
$this->_prepareSessionUrl($url);
11081112
$query = $this->_getQuery(false);
11091113
if ($query) {
1110-
$url .= (strpos($url, '?') === false ? '?' : '&') . $query;
1114+
$url .= (strpos((string)$url, '?') === false ? '?' : '&') . $query;
11111115
}
11121116

11131117
return $url;

0 commit comments

Comments
 (0)