[TASK] Use str_replace instead of strtr to improve readability and clarity purposes 65/57465/3
authorWouter Wolters <typo3@wouterwolters.nl>
Wed, 4 Jul 2018 18:08:27 +0000 (20:08 +0200)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Fri, 6 Jul 2018 20:28:51 +0000 (22:28 +0200)
Resolves: #85476
Releases: master
Change-Id: I879bb7546e7e7ca0d46e8d682eb739f76df61b01
Reviewed-on: https://review.typo3.org/57465
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Rudy Gnodde <rgn@windinternet.nl>
Tested-by: Rudy Gnodde <rgn@windinternet.nl>
Reviewed-by: Robert van Kammen <rvkammen@hotmail.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/core/Classes/Core/ClassLoadingInformationGenerator.php
typo3/sysext/core/Classes/Http/ServerRequestFactory.php
typo3/sysext/core/Resources/PHP/ClassMapGenerator.php
typo3/sysext/install/Classes/Controller/UpgradeController.php
typo3/sysext/install/Classes/UpgradeAnalysis/DocumentationFile.php

index fe45dd6..7902cbd 100644 (file)
@@ -149,7 +149,7 @@ class ClassLoadingInformationGenerator
         $blacklistExpression = null;
         if ($ignorePotentialTestClasses) {
             $blacklistPathPrefix = realpath($classesPath);
-            $blacklistPathPrefix = strtr($blacklistPathPrefix, '\\', '/');
+            $blacklistPathPrefix = str_replace('\\', '/', $blacklistPathPrefix);
             $blacklistExpression = "{($blacklistPathPrefix/tests/|$blacklistPathPrefix/Tests/|$blacklistPathPrefix/Resources/|$blacklistPathPrefix/res/|$blacklistPathPrefix/class.ext_update.php)}";
         }
         foreach (ClassMapGenerator::createMap($classesPath, $blacklistExpression, null, $namespace) as $class => $path) {
index 6bf4823..f8049bf 100644 (file)
@@ -84,8 +84,8 @@ class ServerRequestFactory
             }
             if (!empty($value)) {
                 if (strpos($key, 'HTTP_') === 0) {
-                    $name = strtr(substr($key, 5), '_', ' ');
-                    $name = strtr(ucwords(strtolower($name)), ' ', '-');
+                    $name = str_replace('_', ' ', substr($key, 5));
+                    $name = str_replace(' ', '-', ucwords(strtolower($name)));
                     $name = strtolower($name);
                     $headers[$name] = $value;
                 } elseif (strpos($key, 'CONTENT_') === 0) {
index b98430c..98a5126 100644 (file)
@@ -82,7 +82,7 @@ class ClassMapGenerator
                 continue;
             }
 
-            if ($blacklist && preg_match($blacklist, strtr($filePath, '\\', '/'))) {
+            if ($blacklist && preg_match($blacklist, str_replace('\\', '/', $filePath))) {
                 continue;
             }
 
@@ -96,7 +96,10 @@ class ClassMapGenerator
 
                 if (!isset($map[$class])) {
                     $map[$class] = $filePath;
-                } elseif ($io && $map[$class] !== $filePath && !preg_match('{/(test|fixture|example|stub)s?/}i', strtr($map[$class] . ' ' . $filePath, '\\', '/'))) {
+                } elseif ($io && $map[$class] !== $filePath && !preg_match(
+                    '{/(test|fixture|example|stub)s?/}i',
+                        str_replace('\\', '/', $map[$class] . ' ' . $filePath)
+                )) {
                     $io->writeError(
                         '<warning>Warning: Ambiguous class resolution, "' . $class . '"' .
                         ' was found in both "' . $map[$class] . '" and "' . $filePath . '", the first will be used.</warning>'
index f765674..aa2b71b 100644 (file)
@@ -557,7 +557,11 @@ class UpgradeController extends AbstractController
             }
 
             // Build array of file (hashes) not affected by current scan, if they are tagged as "FullyScanned"
-            $parsedRestFile = array_pop($documentationFile->getListEntry(strtr(realpath($restFile->getPathname()), '\\', '/')));
+            $parsedRestFile = array_pop($documentationFile->getListEntry(str_replace(
+                '\\',
+                '/',
+                realpath($restFile->getPathname())
+            )));
             if (!in_array($parsedRestFile['file_hash'], $foundRestFileHashes, true)
                 && in_array('FullyScanned', $parsedRestFile['tags'], true)
             ) {
@@ -667,7 +671,11 @@ class UpgradeController extends AbstractController
                     $restFileLocation = $restFile->getPathname();
                     break;
                 }
-                $parsedRestFile = array_pop($documentationFile->getListEntry(strtr(realpath($restFileLocation), '\\', '/')));
+                $parsedRestFile = array_pop($documentationFile->getListEntry(str_replace(
+                    '\\',
+                    '/',
+                    realpath($restFileLocation)
+                )));
                 $version = GeneralUtility::trimExplode(DIRECTORY_SEPARATOR, $restFileLocation);
                 array_pop($version);
                 // something like "8.2" .. "8.7" .. "master"
@@ -1147,7 +1155,7 @@ class UpgradeController extends AbstractController
     {
         $documentationFileService = new DocumentationFile();
         $documentationFiles = $documentationFileService->findDocumentationFiles(
-            strtr(realpath(ExtensionManagementUtility::extPath('core') . 'Documentation/Changelog'), '\\', '/')
+            str_replace('\\', '/', realpath(ExtensionManagementUtility::extPath('core') . 'Documentation/Changelog'))
         );
         $documentationFiles = array_reverse($documentationFiles);
 
index b96bedc..044633e 100644 (file)
@@ -55,7 +55,7 @@ class DocumentationFile
             $this->registry = new Registry();
         }
         $this->changelogPath = $changelogDir !== '' ? $changelogDir : realpath(ExtensionManagementUtility::extPath('core') . 'Documentation/Changelog');
-        $this->changelogPath = strtr($this->changelogPath, '\\', '/');
+        $this->changelogPath = str_replace('\\', '/', $this->changelogPath);
     }
 
     /**
@@ -75,7 +75,7 @@ class DocumentationFile
         $versionDirectories = scandir($path);
 
         $fileInfo = pathinfo($path);
-        $absolutePath = strtr($fileInfo['dirname'], '\\', '/') . '/' . $fileInfo['basename'];
+        $absolutePath = str_replace('\\', '/', $fileInfo['dirname']) . '/' . $fileInfo['basename'];
         foreach ($versionDirectories as $version) {
             $directory = $absolutePath . '/' . $version;
             $documentationFiles += $this->getDocumentationFilesForVersion($directory, $version);
@@ -226,7 +226,7 @@ class DocumentationFile
         $documentationFiles = [];
         if ($this->isRelevantDirectory($docDirectory, $version)) {
             $documentationFiles[$version] = [];
-            $absolutePath = strtr(PathUtility::dirname($docDirectory), '\\', '/') . '/' . $version;
+            $absolutePath = str_replace('\\', '/', PathUtility::dirname($docDirectory)) . '/' . $version;
             $rstFiles = scandir($docDirectory);
             foreach ($rstFiles as $file) {
                 $fileInfo = pathinfo($file);