Skip to content

Commit 9949cb0

Browse files
anzinandrewbess
authored andcommitted
AC-3161: fixed logic affected by "RFC: Deprecate passing null"
1 parent 9058428 commit 9949cb0

File tree

13 files changed

+83
-62
lines changed

13 files changed

+83
-62
lines changed

lib/internal/Magento/Framework/App/Router/ActionList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ public function get($module, $area, $namespace, $action)
130130
if ($area) {
131131
$area = '\\' . $area;
132132
}
133-
$namespace = strtolower($namespace);
133+
$namespace = $namespace !== null ? strtolower($namespace) : '';
134134
if (strpos($namespace, self::NOT_ALLOWED_IN_NAMESPACE_PATH) !== false) {
135135
return null;
136136
}
137-
if (in_array(strtolower($action), $this->reservedWords)) {
137+
if ($action && in_array(strtolower($action), $this->reservedWords)) {
138138
$action .= 'action';
139139
}
140140
$fullPath = str_replace(

lib/internal/Magento/Framework/App/StaticResource.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ public function catchException(Bootstrap $bootstrap, \Exception $exception)
222222
*/
223223
protected function parsePath($path)
224224
{
225-
$safePath = $this->driver->getRealPathSafety(ltrim($path, '/'));
225+
$path = $path !== null ? ltrim($path, '/') : '';
226+
$safePath = $this->driver->getRealPathSafety($path);
226227
$parts = explode('/', $safePath, 6);
227228
if (count($parts) < 5) {
228229
//Checking that path contains all required parts and is not above static folder.
@@ -276,6 +277,12 @@ private function getLogger()
276277
return $this->logger;
277278
}
278279

280+
/**
281+
* Method to check if theme allowed.
282+
*
283+
* @param string $theme
284+
* @return bool
285+
*/
279286
private function isThemeAllowed(string $theme): bool
280287
{
281288
return in_array($theme, array_keys($this->themePackageList->getThemes()));

lib/internal/Magento/Framework/App/Utility/Classes.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22
/**
3-
* A helper for handling Magento-specific class names in various use cases
4-
*
53
* Copyright © Magento, Inc. All rights reserved.
64
* See COPYING.txt for license details.
75
*/
@@ -35,6 +33,7 @@ public static function getAllMatches($contents, $regex, &$result = [])
3533

3634
array_shift($matches);
3735
foreach ($matches as $row) {
36+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
3837
$result = array_merge($result, $row);
3938
}
4039
$result = array_filter(
@@ -194,8 +193,8 @@ public static function collectModuleClasses($subTypePattern = '[A-Za-z]+')
194193
foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleName => $modulePath) {
195194
$pattern = '/^' . preg_quote($modulePath, '/') . '\/(' . $subTypePattern . '\/.+)\.php$/';
196195
foreach (Files::init()->getFiles([$modulePath], '*.php') as $file) {
197-
if (preg_match($pattern, $file)) {
198-
$partialFileName = substr($file, strlen($modulePath) + 1);
196+
if ($file && preg_match($pattern, $file)) {
197+
$partialFileName = substr($file, strlen($modulePath ?? '') + 1);
199198
$partialFileName = substr($partialFileName, 0, strlen($partialFileName) - strlen('.php'));
200199
$partialClassName = str_replace('/', '\\', $partialFileName);
201200
$className = str_replace('_', '\\', $moduleName) . '\\' . $partialClassName;
@@ -274,7 +273,7 @@ public static function resolveVirtualType($className)
274273
*/
275274
public static function isAutogenerated($className)
276275
{
277-
if (preg_match(
276+
if ($className && preg_match(
278277
'/.*\\\\[a-zA-Z0-9]{1,}(Factory|SearchResults|DataBuilder|Extension|ExtensionInterface)$/',
279278
$className
280279
)
@@ -364,7 +363,7 @@ public static function collectPhpCodeClasses($contents, &$classes = [])
364363
*/
365364
public static function getClassModuleName($class)
366365
{
367-
$parts = explode('\\', trim($class, '\\'));
366+
$parts = explode('\\', trim($class ?: '', '\\'));
368367
return $parts[0] . '_' . $parts[1];
369368
}
370369
}

lib/internal/Magento/Framework/App/Utility/Files.php

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public static function composeDataSets(array $files)
143143
{
144144
$result = [];
145145
foreach ($files as $file) {
146-
$key = str_replace(BP . '/', '', $file);
146+
$key = $file !== null ? str_replace(BP . '/', '', $file) : '';
147147
$result[$key] = [$file];
148148
}
149149
return $result;
@@ -640,9 +640,10 @@ private function collectModuleLayoutFiles(array $params, $location)
640640
);
641641
if ($params['with_metainfo']) {
642642
foreach ($moduleFiles as $moduleFile) {
643-
$modulePath = str_replace(DIRECTORY_SEPARATOR, '/', preg_quote($moduleDir, '#'));
643+
$modulePath = $moduleDir !== null ?
644+
str_replace(DIRECTORY_SEPARATOR, '/', preg_quote($moduleDir, '#')) : '';
644645
$regex = '#^' . $modulePath . '/view/(?P<area>[a-z]+)/layout/(?P<path>.+)$#i';
645-
if (preg_match($regex, $moduleFile, $matches)) {
646+
if ($moduleFile && preg_match($regex, $moduleFile, $matches)) {
646647
$files[] = [
647648
[$matches['area'], '', $moduleName, $matches['path'], $moduleFile]
648649
];
@@ -673,7 +674,8 @@ private function collectThemeLayoutFiles(array $params, $location)
673674
$requiredModuleName = $params['namespace'] . '_' . $params['module'];
674675
$themePath = $params['theme_path'];
675676
foreach ($this->themePackageList->getThemes() as $theme) {
676-
$currentThemePath = str_replace(DIRECTORY_SEPARATOR, '/', $theme->getPath());
677+
$currentThemePath = $theme->getPath() !== null ?
678+
str_replace(DIRECTORY_SEPARATOR, '/', $theme->getPath()) : '';
677679
$currentThemeCode = $theme->getVendor() . '/' . $theme->getName();
678680
if (($area == '*' || $theme->getArea() === $area)
679681
&& ($themePath == '*' || $themePath == '*/*' || $themePath == $currentThemeCode)
@@ -712,7 +714,7 @@ private function parseThemeFiles($themeFiles, $currentThemePath, $theme)
712714
. '/(?P<module>[a-z\d]+_[a-z\d]+)/layout/(override/((base/)|(theme/[a-z\d_]+/[a-z\d_]+/)))?'
713715
. '(?P<path>.+)$#i';
714716
foreach ($themeFiles as $themeFile) {
715-
if (preg_match($regex, $themeFile, $matches)) {
717+
if ($themeFile && preg_match($regex, $themeFile, $matches)) {
716718
$files[] = [
717719
$theme->getArea(),
718720
$theme->getVendor() . '/' . $theme->getName(),
@@ -927,7 +929,8 @@ private function accumulateThemeStaticFiles($area, $locale, $filePattern, &$resu
927929
$themeArea = $themePackage->getArea();
928930
if ($area == '*' || $area == $themeArea) {
929931
$files = [];
930-
$themePath = str_replace(DIRECTORY_SEPARATOR, '/', $themePackage->getPath());
932+
$themePath = $themePackage->getPath() !== null ?
933+
str_replace(DIRECTORY_SEPARATOR, '/', $themePackage->getPath()) : '';
931934
$paths = [
932935
$themePath . "/web",
933936
$themePath . "/*_*/web",
@@ -938,7 +941,7 @@ private function accumulateThemeStaticFiles($area, $locale, $filePattern, &$resu
938941
$regex = '#^' . $themePath .
939942
'/((?P<module>[a-z\d]+_[a-z_\d]+)/)?web/(i18n/(?P<locale>[a-z_]+)/)?(?P<path>.+)$#i';
940943
foreach ($files as $file) {
941-
if (preg_match($regex, $file, $matches)) {
944+
if ($file && preg_match($regex, $file, $matches)) {
942945
$result[] = [
943946
$themeArea,
944947
$themePackage->getVendor() . '/' . $themePackage->getName(),
@@ -1004,7 +1007,7 @@ protected function _accumulateFilesByPatterns(array $patterns, $filePattern, arr
10041007
{
10051008
$path = str_replace(DIRECTORY_SEPARATOR, '/', BP);
10061009
foreach (self::getFiles($patterns, $filePattern) as $file) {
1007-
$file = str_replace(DIRECTORY_SEPARATOR, '/', $file);
1010+
$file = $file !== null ? str_replace(DIRECTORY_SEPARATOR, '/', $file) : '';
10081011
if ($subroutine) {
10091012
$result[] = $this->$subroutine($file, $path);
10101013
} else {
@@ -1024,7 +1027,7 @@ protected function _accumulateFilesByPatterns(array $patterns, $filePattern, arr
10241027
protected function _parseModuleStatic($file)
10251028
{
10261029
foreach ($this->componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleName => $modulePath) {
1027-
if (preg_match(
1030+
if ($file && preg_match(
10281031
'/^' . preg_quote("{$modulePath}/", '/') . 'view\/([a-z]+)\/web\/(.+)$/i',
10291032
$file,
10301033
$matches
@@ -1051,7 +1054,7 @@ private function accumulateStaticFiles($area, $filePattern, array &$result)
10511054
$moduleWebPath = $moduleDir . "/view/{$area}/web";
10521055

10531056
foreach (self::getFiles([$moduleWebPath], $filePattern) as $absolutePath) {
1054-
$localPath = substr($absolutePath, strlen($moduleDir) + 1);
1057+
$localPath = $absolutePath !== null ? substr($absolutePath, strlen($moduleDir ?? '') + 1) : '';
10551058
if (preg_match('/^view\/([a-z]+)\/web\/(.+)$/i', $localPath, $matches) === 1) {
10561059
list(, $parsedArea, $parsedPath) = $matches;
10571060
$result[] = [$parsedArea, '', '', $moduleName, $parsedPath, $absolutePath];
@@ -1070,7 +1073,8 @@ protected function _parseModuleLocaleStatic($file)
10701073
{
10711074
foreach ($this->componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleName => $modulePath) {
10721075
$appCode = preg_quote("{$modulePath}/", '/');
1073-
if (preg_match('/^' . $appCode . 'view\/([a-z]+)\/web\/i18n\/([a-z_]+)\/(.+)$/i', $file, $matches) === 1) {
1076+
if ($file &&
1077+
preg_match('/^' . $appCode . 'view\/([a-z]+)\/web\/i18n\/([a-z_]+)\/(.+)$/i', $file, $matches) === 1) {
10741078
list(, $area, $locale, $filePath) = $matches;
10751079
return [$area, '', $locale, $moduleName, $filePath, $file];
10761080
}
@@ -1191,10 +1195,10 @@ private function accumulateThemeTemplateFiles($withMetaInfo, array &$result)
11911195
$files
11921196
);
11931197
if ($withMetaInfo) {
1194-
$regex = '#^' . str_replace(DIRECTORY_SEPARATOR, '/', $theme->getPath())
1195-
. '/(?P<module>[a-z\d]+_[a-z\d]+)/templates/(?P<path>.+)$#i';
1198+
$themePath = $theme->getPath() !== null ? str_replace(DIRECTORY_SEPARATOR, '/', $theme->getPath()) : '';
1199+
$regex = '#^' . $themePath . '/(?P<module>[a-z\d]+_[a-z\d]+)/templates/(?P<path>.+)$#i';
11961200
foreach ($files as $file) {
1197-
if (preg_match($regex, $file, $matches)) {
1201+
if ($file && preg_match($regex, $file, $matches)) {
11981202
$result[] = [
11991203
$theme->getArea(),
12001204
$theme->getVendor() . '/' . $theme->getName(),
@@ -1230,10 +1234,11 @@ private function accumulateModuleTemplateFiles($withMetaInfo, array &$result)
12301234
$files
12311235
);
12321236
if ($withMetaInfo) {
1233-
$modulePath = str_replace(DIRECTORY_SEPARATOR, '/', preg_quote($moduleDir, '#'));
1237+
$modulePath = $moduleDir !== null ?
1238+
str_replace(DIRECTORY_SEPARATOR, '/', preg_quote($moduleDir, '#')) : '';
12341239
$regex = '#^' . $modulePath . '/view/(?P<area>[a-z]+)/templates/(?P<path>.+)$#i';
12351240
foreach ($files as $file) {
1236-
if (preg_match($regex, $file, $matches)) {
1241+
if ($file && preg_match($regex, $file, $matches)) {
12371242
$result[] = [
12381243
$matches['area'],
12391244
'',
@@ -1320,7 +1325,7 @@ public static function getFiles(array $dirPatterns, $fileNamePattern, $recursive
13201325
{
13211326
$result = [];
13221327
foreach ($dirPatterns as $oneDirPattern) {
1323-
$oneDirPattern = str_replace('\\', '/', $oneDirPattern);
1328+
$oneDirPattern = $oneDirPattern !== null ? str_replace('\\', '/', $oneDirPattern) : '';
13241329
$entriesInDir = Glob::glob("{$oneDirPattern}/{$fileNamePattern}", Glob::GLOB_NOSORT | Glob::GLOB_BRACE);
13251330
$subDirs = Glob::glob("{$oneDirPattern}/*", Glob::GLOB_ONLYDIR | Glob::GLOB_NOSORT | Glob::GLOB_BRACE);
13261331
$filesInDir = array_diff($entriesInDir, $subDirs);
@@ -1389,6 +1394,8 @@ private function getPaths()
13891394
*/
13901395
public function classFileExists($class, &$path = '')
13911396
{
1397+
$class = $class ?: '';
1398+
13921399
if ($class[0] == '\\') {
13931400
$class = substr($class, 1);
13941401
}
@@ -1459,7 +1466,7 @@ private function classFileExistsCheckContent($fullPath, $namespace, $className)
14591466
* Note that realpath() automatically changes directory separator to the OS-native
14601467
* Since realpath won't work with symlinks we also check file_exists if realpath failed
14611468
*/
1462-
if (realpath($fullPath) == str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $fullPath)
1469+
if ($fullPath && realpath($fullPath) == str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $fullPath)
14631470
|| file_exists($fullPath)
14641471
) {
14651472
$fileContent = file_get_contents($fullPath);
@@ -1582,10 +1589,13 @@ public function readLists($globPattern)
15821589
$result = [];
15831590
$incorrectPatterns = [];
15841591
foreach ($patterns as $pattern) {
1592+
$pattern = $pattern ?? '';
1593+
15851594
if (0 === strpos($pattern, '#')) {
15861595
continue;
15871596
}
15881597
$patternParts = explode(' ', $pattern);
1598+
15891599
if (count($patternParts) == 3) {
15901600
list($componentType, $componentName, $pathPattern) = $patternParts;
15911601
$files = $this->getPathByComponentPattern($componentType, $componentName, $pathPattern);

lib/internal/Magento/Framework/App/View/Asset/MaterializationStrategy/Symlink.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function publishFile(
3838
*/
3939
public function isSupported(Asset\LocalInterface $asset)
4040
{
41-
$sourceParts = explode('/', $asset->getSourceFile());
41+
$sourceParts = explode('/', $asset->getSourceFile() ?? '');
4242
if (in_array(DirectoryList::TMP_MATERIALIZATION_DIR, $sourceParts)) {
4343
return false;
4444
}

lib/internal/Magento/Framework/Archive.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ class Archive
1919
/**
2020
* Archiver is used for compress.
2121
*/
22-
const DEFAULT_ARCHIVER = 'gz';
22+
public const DEFAULT_ARCHIVER = 'gz';
2323

2424
/**
2525
* Default packer for directory.
2626
*/
27-
const TAPE_ARCHIVER = 'tar';
27+
public const TAPE_ARCHIVER = 'tar';
2828

2929
/**
3030
* Current archiver is used for compress.
@@ -62,8 +62,8 @@ class Archive
6262
*/
6363
protected function _getArchiver($extension)
6464
{
65-
$extension = strtolower($extension);
66-
$format = isset($this->_formats[$extension]) ? $this->_formats[$extension] : self::DEFAULT_ARCHIVER;
65+
$extension = $extension !== null ? strtolower($extension) : '';
66+
$format = $this->_formats[$extension] ?? self::DEFAULT_ARCHIVER;
6767
$class = '\\Magento\Framework\Archive\\' . ucfirst($format);
6868
$this->_archiver = new $class();
6969
return $this->_archiver;
@@ -113,6 +113,7 @@ public function pack($source, $destination = 'packed.tgz', $skipRoot = false)
113113

114114
/**
115115
* Unpack file from archivers are parsed from extension.
116+
*
116117
* If $tillTar == true unpack file from archivers till
117118
* meet TAR archiver.
118119
*

lib/internal/Magento/Framework/Archive/AbstractArchive.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ class AbstractArchive
2323
*/
2424
protected function _writeFile($destination, $data)
2525
{
26-
$destination = trim($destination);
26+
$destination = $destination !== null ? trim($destination) : '';
2727
if (false === file_put_contents($destination, $data)) {
28+
// phpcs:ignore Magento2.Exceptions.DirectThrow
2829
throw new \Exception("Can't write to file: " . $destination);
2930
}
3031
return true;
@@ -60,7 +61,7 @@ protected function _readFile($source)
6061
*/
6162
public function getFilename($source, $withExtension = false)
6263
{
63-
$file = str_replace(dirname($source) . '/', '', $source);
64+
$file = $source !== null ? str_replace(dirname($source) . '/', '', $source) : '';
6465
if (!$withExtension) {
6566
$file = substr($file, 0, strrpos($file, '.'));
6667
}

lib/internal/Magento/Framework/Archive/Tar.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Tar extends \Magento\Framework\Archive\AbstractArchive implements \Magento
2020
*
2121
* @const int
2222
*/
23-
const TAR_BLOCK_SIZE = 512;
23+
public const TAR_BLOCK_SIZE = 512;
2424

2525
/**
2626
* Keep file or directory for packing.
@@ -180,7 +180,7 @@ protected function _setSkipRoot($skipRoot)
180180
*/
181181
protected function _setCurrentFile($file)
182182
{
183-
$file = str_replace('\\', '/', $file);
183+
$file = $file !== null ? str_replace('\\', '/', $file) : '';
184184
$this->_currentFile = $file . (!is_link($file) && is_dir($file) && substr($file, -1) != '/' ? '/' : '');
185185
return $this;
186186
}
@@ -215,7 +215,7 @@ protected function _getCurrentFile()
215215
*/
216216
protected function _setCurrentPath($path)
217217
{
218-
$path = str_replace('\\', '/', $path);
218+
$path = $path !== null ? str_replace('\\', '/', $path) : '';
219219
if ($this->_skipRoot && is_dir($path)) {
220220
$this->_currentPath = $path . (substr($path, -1) != '/' ? '/' : '');
221221
} else {
@@ -304,6 +304,7 @@ protected function _packAndWriteCurrentFile()
304304

305305
/**
306306
* Compose header for current file in TAR format.
307+
*
307308
* If length of file's name greater 100 characters,
308309
* method breaks header into two pieces. First contains
309310
* header and data with long name. Second contain only header.
@@ -315,8 +316,8 @@ protected function _packAndWriteCurrentFile()
315316
*/
316317
protected function _composeHeader($long = false)
317318
{
318-
$file = $this->_getCurrentFile();
319-
$path = $this->_getCurrentPath();
319+
$file = $this->_getCurrentFile() ?? '';
320+
$path = $this->_getCurrentPath() ?? '';
320321
$infoFile = stat($file);
321322
$nameFile = str_replace($path, '', $file);
322323
$nameFile = str_replace('\\', '/', $nameFile);
@@ -375,6 +376,7 @@ protected function _composeHeader($long = false)
375376

376377
/**
377378
* Read TAR string from file, and unpacked it.
379+
*
378380
* Create files and directories information about described
379381
* in the string.
380382
*

0 commit comments

Comments
 (0)