Skip to content

Commit c3965c3

Browse files
committed
Merge remote-tracking branch 'origin/AC-3161-fix-potential-issues-php-p14' into delivery-bunch-w22
2 parents 73ae1eb + 38e2ae5 commit c3965c3

File tree

13 files changed

+36
-55
lines changed

13 files changed

+36
-55
lines changed

lib/internal/Magento/Framework/Session/SessionManager.php

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22
/**
3-
* Magento session manager
4-
*
53
* Copyright © Magento, Inc. All rights reserved.
64
* See COPYING.txt for license details.
75
*/
@@ -29,57 +27,41 @@ class SessionManager implements SessionManagerInterface
2927
protected $defaultDestroyOptions = ['send_expire_cookie' => true, 'clear_storage' => true];
3028

3129
/**
32-
* URL host cache
33-
*
3430
* @var array
3531
*/
3632
protected static $urlHostCache = [];
3733

3834
/**
39-
* Validator
40-
*
4135
* @var ValidatorInterface
4236
*/
4337
protected $validator;
4438

4539
/**
46-
* Request
47-
*
4840
* @var \Magento\Framework\App\Request\Http
4941
*/
5042
protected $request;
5143

5244
/**
53-
* SID resolver
54-
*
5545
* @var SidResolverInterface
5646
*/
5747
protected $sidResolver;
5848

5949
/**
60-
* Session config
61-
*
6250
* @var Config\ConfigInterface
6351
*/
6452
protected $sessionConfig;
6553

6654
/**
67-
* Save handler
68-
*
6955
* @var SaveHandlerInterface
7056
*/
7157
protected $saveHandler;
7258

7359
/**
74-
* Storage
75-
*
7660
* @var StorageInterface
7761
*/
7862
protected $storage;
7963

8064
/**
81-
* Cookie Manager
82-
*
8365
* @var \Magento\Framework\Stdlib\CookieManagerInterface
8466
*/
8567
protected $cookieManager;
@@ -161,7 +143,7 @@ public function writeClose()
161143
*/
162144
public function __call($method, $args)
163145
{
164-
if (!in_array(substr($method, 0, 3), ['get', 'set', 'uns', 'has'])) {
146+
if (!$method || !in_array(substr($method, 0, 3), ['get', 'set', 'uns', 'has'])) {
165147
throw new \InvalidArgumentException(
166148
sprintf('Invalid method %s::%s(%s)', get_class($this), $method, print_r($args, 1))
167149
);
@@ -425,6 +407,7 @@ public function setSessionId($sessionId)
425407
*
426408
* @param string $urlHost can be host or url
427409
* @return string {session_id_key}={session_id_encrypted}
410+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
428411
* @SuppressWarnings(PHPMD.NPathComplexity)
429412
*/
430413
public function getSessionIdForHost($urlHost)
@@ -434,14 +417,14 @@ public function getSessionIdForHost($urlHost)
434417
return '';
435418
}
436419

437-
$urlHostArr = explode('/', $urlHost, 4);
420+
$urlHostArr = explode('/', $urlHost ?: '', 4);
438421
if (!empty($urlHostArr[2])) {
439422
$urlHost = $urlHostArr[2];
440423
}
441424
$urlPath = empty($urlHostArr[3]) ? '' : $urlHostArr[3];
442425

443426
if (!isset(self::$urlHostCache[$urlHost])) {
444-
$urlHostArr = explode(':', $urlHost);
427+
$urlHostArr = explode(':', $urlHost ?: '');
445428
$urlHost = $urlHostArr[0];
446429
$sessionId = $httpHost !== $urlHost && !$this->isValidForHost($urlHost) ? $this->getSessionId() : '';
447430
self::$urlHostCache[$urlHost] = $sessionId;
@@ -458,7 +441,7 @@ public function getSessionIdForHost($urlHost)
458441
*/
459442
public function isValidForHost($host)
460443
{
461-
$hostArr = explode(':', $host);
444+
$hostArr = explode(':', $host ?: '');
462445
$hosts = $this->_getHosts();
463446
return !empty($hosts[$hostArr[0]]);
464447
}

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class BackupRollback
2525
/**
2626
* Default backup directory
2727
*/
28-
const DEFAULT_BACKUP_DIRECTORY = 'backups';
28+
public const DEFAULT_BACKUP_DIRECTORY = 'backups';
2929

3030
/**
3131
* Path to backup folder
@@ -35,8 +35,6 @@ class BackupRollback
3535
private $backupsDir;
3636

3737
/**
38-
* Object Manager
39-
*
4038
* @var ObjectManagerInterface
4139
*/
4240
private $objectManager;
@@ -56,8 +54,6 @@ class BackupRollback
5654
private $directoryList;
5755

5856
/**
59-
* File
60-
*
6157
* @var File
6258
*/
6359
private $file;
@@ -146,7 +142,7 @@ public function codeBackup($time, $type = Factory::TYPE_FILESYSTEM)
146142
*/
147143
public function codeRollback($rollbackFile, $type = Factory::TYPE_FILESYSTEM, $keepSourceFile = false)
148144
{
149-
if (preg_match('/[0-9]_(filesystem)_(code|media)\.(tgz)$/', $rollbackFile) !== 1) {
145+
if (!$rollbackFile || preg_match('/[0-9]_(filesystem)_(code|media)\.(tgz)$/', $rollbackFile) !== 1) {
150146
throw new LocalizedException(new Phrase('The rollback file is invalid. Verify the file and try again.'));
151147
}
152148
if (!$this->file->isExists($this->backupsDir . '/' . $rollbackFile)) {
@@ -224,7 +220,7 @@ public function dbBackup($time)
224220
*/
225221
public function dbRollback($rollbackFile, $keepSourceFile = false)
226222
{
227-
if (preg_match('/[0-9]_(db)(.*?).(sql)$/', $rollbackFile) !== 1) {
223+
if (!$rollbackFile || preg_match('/[0-9]_(db)(.*?).(sql)$/', $rollbackFile) !== 1) {
228224
throw new LocalizedException(new Phrase('The rollback file is invalid. Verify the file and try again.'));
229225
}
230226
if (!$this->file->isExists($this->backupsDir . '/' . $rollbackFile)) {
@@ -237,7 +233,7 @@ public function dbRollback($rollbackFile, $keepSourceFile = false)
237233
$dbRollback->setBackupExtension('sql');
238234
$time = explode('_', $rollbackFile);
239235
if (count($time) === 3) {
240-
$thirdPart = explode('.', $time[2]);
236+
$thirdPart = explode('.', $time[2] ?? '');
241237
$dbRollback->setName($thirdPart[0]);
242238
}
243239
$dbRollback->setTime($time[0]);
@@ -284,12 +280,12 @@ private function getMediaBackupIgnorePaths()
284280
$ignorePaths = [];
285281
foreach (new \DirectoryIterator($this->directoryList->getRoot()) as $item) {
286282
if (!$item->isDot() && ($this->directoryList->getPath(DirectoryList::PUB) !== $item->getPathname())) {
287-
$ignorePaths[] = str_replace('\\', '/', $item->getPathname());
283+
$ignorePaths[] = $item->getPathname() !== null ? str_replace('\\', '/', $item->getPathname()) : '';
288284
}
289285
}
290286
foreach (new \DirectoryIterator($this->directoryList->getPath(DirectoryList::PUB)) as $item) {
291287
if (!$item->isDot() && ($this->directoryList->getPath(DirectoryList::MEDIA) !== $item->getPathname())) {
292-
$ignorePaths[] = str_replace('\\', '/', $item->getPathname());
288+
$ignorePaths[] = $item->getPathname() !== null ? str_replace('\\', '/', $item->getPathname()) : '';
293289
}
294290
}
295291
return $ignorePaths;
@@ -348,7 +344,7 @@ private function getCorrectFileNameWithoutPrefix(\Magento\Framework\Backup\Db $d
348344
{
349345
$namePrefix = $dbRollback->getTime() . '_' . $dbRollback->getType();
350346
//delete prefix.
351-
$fileNameWithoutPrefix = str_replace($namePrefix, '', $rollbackFile);
347+
$fileNameWithoutPrefix = $rollbackFile !== null ? str_replace($namePrefix, '', $rollbackFile) : '';
352348
//change '_' to ' '.
353349
$fileNameWithoutPrefix = str_replace('_', ' ', $fileNameWithoutPrefix);
354350
//delete file extension.

lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/MySQL/DDL/Triggers/MigrateDataFrom.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MigrateDataFrom implements DDLTriggerInterface
2222
/**
2323
* Pattern with which we can match whether we can apply and use this trigger or not.
2424
*/
25-
const MATCH_PATTERN = '/migrateDataFrom\(([^\)]+)\)/';
25+
public const MATCH_PATTERN = '/migrateDataFrom\(([^\)]+)\)/';
2626

2727
/**
2828
* @var ResourceConnection
@@ -54,7 +54,7 @@ public function getCallback(ElementHistory $columnHistory) : callable
5454
{
5555
/** @var Column $column */
5656
$column = $columnHistory->getNew();
57-
preg_match(self::MATCH_PATTERN, $column->getOnCreate(), $matches);
57+
preg_match(self::MATCH_PATTERN, $column->getOnCreate() ?? '', $matches);
5858
return function () use ($column, $matches) {
5959
$tableName = $column->getTable()->getName();
6060
$adapter = $this->resourceConnection->getConnection(

lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/MySQL/Definition/Columns/Blob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function toDefinition(ElementInterface $column)
6868
public function fromDefinition(array $data)
6969
{
7070
$matches = [];
71-
if (preg_match('/^text\s*\((\d+)\)/', $data['definition'], $matches) && isset($matches[1])) {
71+
if (preg_match('/^text\s*\((\d+)\)/', $data['definition'] ?? '', $matches) && isset($matches[1])) {
7272
$data['length'] = $matches[1];
7373
}
7474

lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/MySQL/Definition/Columns/Integer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function fromDefinition(array $data)
107107
$matches = [];
108108
if (preg_match(
109109
'/^(?<type>(?:big|small|tiny|medium)?int)(?:\((?<padding>\d+)\))?/',
110-
$data['definition'],
110+
$data['definition'] ?? '',
111111
$matches
112112
)) {
113113
// we have an agreement that tinyint(1) is Boolean

lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/MySQL/Definition/Columns/OnUpdate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function toDefinition(ElementInterface $column)
3838
public function fromDefinition(array $data)
3939
{
4040
$matches = [];
41-
if (preg_match('/(?:on update)\s([\_\-\s\w\d]+)/', $data['extra'], $matches)) {
41+
if (preg_match('/(?:on update)\s([\_\-\s\w\d]+)/', $data['extra'] ?? '', $matches)) {
4242
$data['on_update'] = true;
4343
}
4444

lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/MySQL/Definition/Columns/Real.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public function __construct(
5757
}
5858

5959
/**
60-
* @param \Magento\Framework\Setup\Declaration\Schema\Dto\Columns\Real $column
6160
* @inheritdoc
6261
*/
6362
public function toDefinition(ElementInterface $column)
@@ -86,7 +85,7 @@ public function toDefinition(ElementInterface $column)
8685
public function fromDefinition(array $data)
8786
{
8887
$matches = [];
89-
if (preg_match('/^(float|decimal|double)\s*\((\d+)\s*,\s*(\d+)\)/i', $data['definition'], $matches)) {
88+
if (preg_match('/^(float|decimal|double)\s*\((\d+)\s*,\s*(\d+)\)/i', $data['definition'] ?? '', $matches)) {
9089
/**
9190
* match[1] - type
9291
* match[2] - precision
@@ -96,7 +95,7 @@ public function fromDefinition(array $data)
9695
$data['scale'] = $matches[3];
9796
$data = $this->nullable->fromDefinition($data);
9897
$data = $this->unsigned->fromDefinition($data);
99-
} elseif (preg_match('/^decimal\s*\(\s*(\d+)\s*\)/i', $data['definition'], $matches)) {
98+
} elseif (preg_match('/^decimal\s*\(\s*(\d+)\s*\)/i', $data['definition'] ?? '', $matches)) {
10099
$data['precision'] = $matches[1];
101100
$data['scale'] = 0;
102101
}

lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/MySQL/Definition/Columns/StringBinary.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function toDefinition(ElementInterface $column)
8383
*/
8484
public function fromDefinition(array $data)
8585
{
86-
preg_match($this->getStringBinaryPattern(), $data['definition'], $matches);
86+
preg_match($this->getStringBinaryPattern(), $data['definition'] ?? '', $matches);
8787

8888
if (array_key_exists('padding', $matches) && !empty($matches['padding'])) {
8989
$data['length'] = $matches['padding'];
@@ -93,7 +93,7 @@ public function fromDefinition(array $data)
9393
return $data;
9494
}
9595

96-
$isHex = preg_match('`^0x([a-f0-9]+)$`i', $data['default'], $hexMatches);
96+
$isHex = preg_match('`^0x([a-f0-9]+)$`i', $data['default'] ?? '', $hexMatches);
9797

9898
if ($this->isBinaryHex($matches['type'], (bool)$isHex)) {
9999
$data['default'] = hex2bin($hexMatches[1]);

lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/MySQL/Definition/Index.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Index implements DbDefinitionProcessorInterface
2121
/**
2222
* Index statement.
2323
*/
24-
const INDEX_KEY_NAME = 'INDEX';
24+
public const INDEX_KEY_NAME = 'INDEX';
2525

2626
/**
2727
* @var ResourceConnection
@@ -39,7 +39,6 @@ public function __construct(ResourceConnection $resourceConnection)
3939
}
4040

4141
/**
42-
* @param \Magento\Framework\Setup\Declaration\Schema\Dto\Index $index
4342
* @inheritdoc
4443
*/
4544
public function toDefinition(ElementInterface $index)
@@ -73,7 +72,7 @@ function ($columnName) use ($adapter) {
7372
public function fromDefinition(array $data)
7473
{
7574
return [
76-
'indexType' => strtolower($data['Index_type']),
75+
'indexType' => strtolower($data['Index_type'] ?? ''),
7776
'name' => $data['Key_name'],
7877
'column' => [
7978
$data['Column_name'] => $data['Column_name']

lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/SchemaBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function build(Schema $schema)
8989
[
9090
'name' => $tableName,
9191
'resource' => $resource,
92-
'engine' => strtolower($tableOptions['engine']),
92+
'engine' => strtolower($tableOptions['engine'] ?? ''),
9393
'comment' => $tableOptions['comment'] === '' ? null : $tableOptions['comment'],
9494
'charset' => $tableOptions['charset'],
9595
'collation' => $tableOptions['collation']

0 commit comments

Comments
 (0)