Skip to content

Commit 67f8a36

Browse files
committed
AC-3162 fixed logic affected by "RFC: Deprecate passing null" issue
1 parent 073f38b commit 67f8a36

File tree

14 files changed

+47
-42
lines changed

14 files changed

+47
-42
lines changed

lib/internal/Magento/Framework/Filesystem/DirectoryList.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<?php
22
/**
3-
* Application file system directories dictionary.
4-
*
5-
* Provides information about what directories are available in the application.
6-
* Serves as a customization point to specify different directories or add your own.
7-
*
83
* Copyright © Magento, Inc. All rights reserved.
94
* See COPYING.txt for license details.
105
*/
@@ -13,6 +8,11 @@
138
namespace Magento\Framework\Filesystem;
149

1510
/**
11+
* Application file system directories dictionary.
12+
*
13+
* Provides information about what directories are available in the application.
14+
* Serves as a customization point to specify different directories or add your own.
15+
*
1616
* A list of directories
1717
*
1818
* Each list item consists of:
@@ -30,14 +30,14 @@ class DirectoryList
3030
/**#@+
3131
* Keys of directory configuration
3232
*/
33-
const PATH = 'path';
34-
const URL_PATH = 'uri';
33+
public const PATH = 'path';
34+
public const URL_PATH = 'uri';
3535
/**#@- */
3636

3737
/**
3838
* System base temporary directory
3939
*/
40-
const SYS_TMP = 'sys_tmp';
40+
public const SYS_TMP = 'sys_tmp';
4141

4242
/**
4343
* Root path
@@ -134,7 +134,7 @@ public function __construct($root, array $config = [])
134134
*/
135135
private function normalizePath($path)
136136
{
137-
return str_replace('\\', '/', $path);
137+
return $path !== null ? str_replace('\\', '/', $path) : '';
138138
}
139139

140140
/**
@@ -176,7 +176,7 @@ protected function prependRoot($path)
176176
*/
177177
protected function isAbsolute($path)
178178
{
179-
$path = strtr($path, '\\', '/');
179+
$path = $path !== null ? strtr($path, '\\', '/') : '';
180180

181181
if (strpos($path, '/') === 0) {
182182
//is UnixRoot

lib/internal/Magento/Framework/Filesystem/Driver/File.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ public function search($pattern, $path)
320320
if (!$this->stateful) {
321321
clearstatcache();
322322
}
323-
$globPattern = rtrim($path, '/') . '/' . ltrim($pattern, '/');
323+
$globPattern = rtrim((string)$path, '/') . '/' . ltrim((string)$pattern, '/');
324324
$result = Glob::glob($globPattern, Glob::GLOB_BRACE);
325325
return is_array($result) ? $result : [];
326326
}
@@ -819,6 +819,7 @@ public function fileClose($resource)
819819
*/
820820
public function fileWrite($resource, $data)
821821
{
822+
$data = $data !== null ? $data : '';
822823
$lenData = strlen($data);
823824
for ($result = 0; $result < $lenData; $result += $fwrite) {
824825
$fwrite = @fwrite($resource, substr($data, $result));
@@ -969,7 +970,7 @@ public function getAbsolutePath($basePath, $path, $scheme = null)
969970
// basepath. so if the basepath starts at position 0 in the path, we
970971
// must not concatinate them again because path is already absolute.
971972
$path = $path !== null ? $path : '';
972-
if ('' !== $basePath && strpos($path, $basePath) === 0) {
973+
if ('' !== $basePath && strpos($path, (string)$basePath) === 0) {
973974
return $this->getScheme($scheme) . $path;
974975
}
975976

@@ -986,7 +987,7 @@ public function getAbsolutePath($basePath, $path, $scheme = null)
986987
public function getRelativePath($basePath, $path = null)
987988
{
988989
$path = $path !== null ? $this->fixSeparator($path) : '';
989-
if (strpos($path, $basePath) === 0 || $basePath == $path . '/') {
990+
if ($basePath === null || strpos($path, $basePath) === 0 || $basePath == $path . '/') {
990991
$result = substr($path, strlen($basePath));
991992
} else {
992993
$result = $path;

lib/internal/Magento/Framework/Filesystem/Driver/Http.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22
/**
3-
* Origin filesystem driver
4-
*
53
* Copyright © Magento, Inc. All rights reserved.
64
* See COPYING.txt for license details.
75
*/
@@ -11,7 +9,7 @@
119
use Magento\Framework\Exception\FileSystemException;
1210

1311
/**
14-
* Allows interacting with http endpoint like with FileSystem
12+
* Origin filesystem driver. Allows interacting with http endpoint like with FileSystem
1513
*/
1614
class Http extends File
1715
{
@@ -31,7 +29,7 @@ class Http extends File
3129
public function isExists($path)
3230
{
3331
$headers = array_change_key_case(get_headers($this->getScheme() . $path, 1), CASE_LOWER);
34-
$status = $headers[0];
32+
$status = $headers[0] ?? '';
3533

3634
/* Handling 301 or 302 redirection */
3735
if (isset($headers[1]) && preg_match('/30[12]/', $status)) {
@@ -85,7 +83,7 @@ public function fileGetContents($path, $flags = null, $context = null)
8583
{
8684
$fullPath = $this->getScheme() . $path;
8785
clearstatcache(false, $fullPath);
88-
$result = @file_get_contents($fullPath, $flags, $context);
86+
$result = @file_get_contents($fullPath, $flags ?? false, $context);
8987
if (false === $result) {
9088
throw new FileSystemException(
9189
new \Magento\Framework\Phrase(
@@ -221,7 +219,7 @@ public function getAbsolutePath($basePath, $path, $scheme = null)
221219
// check if the path given is already an absolute path containing the
222220
// basepath. so if the basepath starts at position 0 in the path, we
223221
// must not concatinate them again because path is already absolute.
224-
if (0 === strpos($path, $basePath)) {
222+
if (0 === strpos((string)$path, (string)$basePath)) {
225223
return $this->getScheme() . $path;
226224
}
227225

lib/internal/Magento/Framework/Filesystem/Driver/StatefulFile.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22
/**
3-
* Origin filesystem driver
4-
*
53
* Copyright © Magento, Inc. All rights reserved.
64
* See COPYING.txt for license details.
75
*/
@@ -13,7 +11,7 @@
1311
use Magento\Framework\Filesystem\DriverInterface;
1412

1513
/**
16-
* Filesystem driver that uses the local filesystem.
14+
* Origin filesystem driver. Filesystem driver that uses the local filesystem.
1715
*
1816
* Assumed that stat cache is cleanup by data modification methods
1917
*
@@ -517,7 +515,7 @@ public function getRelativePath($basePath, $path = null)
517515
*/
518516
protected function fixSeparator($path)
519517
{
520-
return str_replace('\\', '/', $path);
518+
return $path !== null ? str_replace('\\', '/', $path) : '';
521519
}
522520

523521
/**

lib/internal/Magento/Framework/Filesystem/File/Write.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ public function __construct($path, DriverInterface $driver, $mode)
3333
protected function assertValid()
3434
{
3535
$fileExists = $this->driver->isExists($this->path);
36-
if (!$fileExists && preg_match('/r/', $this->mode)) {
36+
$mode = $this->mode ?? '';
37+
if (!$fileExists && preg_match('/r/', $mode)) {
3738
throw new FileSystemException(
3839
new \Magento\Framework\Phrase('The "%1" file doesn\'t exist.', [$this->path])
3940
);
40-
} elseif ($fileExists && preg_match('/x/', $this->mode)) {
41+
} elseif ($fileExists && preg_match('/x/', $mode)) {
4142
throw new FileSystemException(new \Magento\Framework\Phrase('The file "%1" already exists', [$this->path]));
4243
}
4344
}

lib/internal/Magento/Framework/Filesystem/FileResolver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class FileResolver
1919
public function getFile($class)
2020
{
2121
$relativePath = $this->getFilePath($class);
22+
// phpcs:ignore Magento2.Exceptions.TryProcessSystemResources
2223
return stream_resolve_include_path($relativePath);
2324
}
2425

@@ -30,7 +31,7 @@ public function getFile($class)
3031
*/
3132
public function getFilePath($class)
3233
{
33-
return ltrim(str_replace(['_', '\\'], '/', $class), '/') . '.php';
34+
return ($class !== null ? ltrim(str_replace(['_', '\\'], '/', $class), '/') : '') . '.php';
3435
}
3536

3637
/**

lib/internal/Magento/Framework/Filesystem/Filter/ExcludeFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function accept()
4646
}
4747

4848
foreach ($this->_filters as $filter) {
49-
$filter = str_replace('\\', '/', $filter);
49+
$filter = $filter !== null ? str_replace('\\', '/', $filter) : '';
5050
if (false !== strpos($current, $filter)) {
5151
return false;
5252
}

lib/internal/Magento/Framework/Filesystem/Io/File.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ class File extends AbstractIo
3636
*
3737
* @const
3838
*/
39-
const GREP_FILES = 'files_only';
39+
public const GREP_FILES = 'files_only';
4040

4141
/**
4242
* Used to grep ls() output
4343
*
4444
* @const
4545
*/
46-
const GREP_DIRS = 'dirs_only';
46+
public const GREP_DIRS = 'dirs_only';
4747

4848
/**
4949
* If this variable is set to TRUE, our library will be able to automatically create
@@ -444,6 +444,7 @@ public function read($filename, $dest = null)
444444
$result = false;
445445

446446
$this->_cwd();
447+
$filename = (string)$filename;
447448
if ($dest === null) {
448449
$result = @file_get_contents($filename);
449450
} elseif (is_resource($dest)) {
@@ -541,6 +542,9 @@ public function isWriteable($path)
541542
*/
542543
public function getDestinationFolder($filePath)
543544
{
545+
if ($filePath === null) {
546+
return null;
547+
}
544548
preg_match('/^(.*[!\/])/', $filePath, $matches);
545549
if (isset($matches[0])) {
546550
return $matches[0];

lib/internal/Magento/Framework/Filesystem/Io/Sftp.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
class Sftp extends AbstractIo
1717
{
18-
const REMOTE_TIMEOUT = 10;
19-
const SSH2_PORT = 22;
18+
public const REMOTE_TIMEOUT = 10;
19+
public const SSH2_PORT = 22;
2020

2121
/**
2222
* @var \phpseclib3\Net\SFTP
@@ -39,7 +39,7 @@ public function open(array $args = [])
3939
if (!isset($args['timeout'])) {
4040
$args['timeout'] = self::REMOTE_TIMEOUT;
4141
}
42-
if (strpos($args['host'], ':') !== false) {
42+
if (strpos($args['host'] ?? '', ':') !== false) {
4343
list($host, $port) = explode(':', $args['host'], 2);
4444
} else {
4545
$host = $args['host'];
@@ -82,7 +82,7 @@ public function mkdir($dir, $mode = 0777, $recursive = true)
8282
{
8383
if ($recursive) {
8484
$no_errors = true;
85-
$dirList = explode('/', $dir);
85+
$dirList = explode('/', (string)$dir);
8686
reset($dirList);
8787
$currentWorkingDir = $this->_connection->pwd();
8888
while ($no_errors && ($dir_item = next($dirList))) {

lib/internal/Magento/Framework/Filter/DirectiveProcessor/LegacyDirective.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function process(array $construction, Template $filter, array $templateVa
4242
return (string)$method->invokeArgs($filter, [$construction]);
4343
} catch (\ReflectionException $e) {
4444
// The legacy parser may be the only parser loaded so make sure the simple directives still process
45-
preg_match($this->simpleDirective->getRegularExpression(), $construction[0], $simpleConstruction);
45+
preg_match($this->simpleDirective->getRegularExpression(), $construction[0] ?? '', $simpleConstruction);
4646

4747
return $this->simpleDirective->process($simpleConstruction, $filter, $templateVariables);
4848
}

0 commit comments

Comments
 (0)