diff --git a/src/Rector/v8/v1/RefactorVariousGeneralUtilityMethodsRector.php b/src/Rector/v8/v1/RefactorVariousGeneralUtilityMethodsRector.php new file mode 100644 index 000000000..cc93e7b3f --- /dev/null +++ b/src/Rector/v8/v1/RefactorVariousGeneralUtilityMethodsRector.php @@ -0,0 +1,146 @@ +isMethodStaticCallOrClassMethodObjectType($node, GeneralUtility::class)) { + return null; + } + + if (! $this->isNames($node->name, [ + self::COMPAT_VERSION, + self::CONVERT_MICROTIME, + self::RAW_URL_ENCODE_JS, + self::RAW_URL_ENCODE_FP, + self::LCFIRST, + self::GET_MAXIMUM_PATH_LENGTH, + ])) { + return null; + } + + switch ($this->getName($node->name)) { + case self::COMPAT_VERSION: + return new GreaterOrEqual( + $this->createStaticCall(VersionNumberUtility::class, 'convertVersionNumberToInteger', [ + new ConstFetch(new Name('TYPO3_branch')), + ]), + $this->createStaticCall(VersionNumberUtility::class, 'convertVersionNumberToInteger', $node->args) + ); + case self::CONVERT_MICROTIME: + $funcCall = $this->createFuncCall('explode', [new String_(' '), $node->args[0]->value]); + $this->addNodeBeforeNode(new Expression(new Assign(new Variable(self::PARTS), $funcCall)), $node); + + return $this->createFuncCall('round', [ + new Mul(new Plus( + new ArrayDimFetch(new Variable(self::PARTS), new LNumber(0)), + new ArrayDimFetch(new Variable(self::PARTS), new LNumber(1)) + ), new LNumber(1000)), + ]); + case self::RAW_URL_ENCODE_JS: + return $this->createFuncCall('str_replace', [ + '%20', + ' ', + $this->createFuncCall('rawurlencode', $node->args), + ]); + case self::RAW_URL_ENCODE_FP: + return $this->createFuncCall('str_replace', [ + '%2F', + '/', + $this->createFuncCall('rawurlencode', $node->args), + ]); + case self::LCFIRST: + return $this->createFuncCall(self::LCFIRST, $node->args); + case self::GET_MAXIMUM_PATH_LENGTH: + return new ConstFetch(new Name('PHP_MAXPATHLEN')); + } + + return null; + } + + /** + * @codeCoverageIgnore + */ + public function getDefinition(): RectorDefinition + { + return new RectorDefinition('', [new CodeSample(<<<'PHP' +use TYPO3\CMS\Core\Utility\GeneralUtility; +$url = 'https://www.domain.com/'; +$url = GeneralUtility::rawUrlEncodeFP($url); +PHP + , <<<'PHP' +$url = 'https://www.domain.com/'; +$url = str_replace('%2F', '/', rawurlencode($url)); +PHP + )]); + } +} diff --git a/stubs/Core/Utility/GeneralUtility.php b/stubs/Core/Utility/GeneralUtility.php index b3241dd6e..a7c391beb 100644 --- a/stubs/Core/Utility/GeneralUtility.php +++ b/stubs/Core/Utility/GeneralUtility.php @@ -164,8 +164,9 @@ public static function array2xml_cs(array $array, $docTag = 'phparray', array $o { // Set default charset unless explicitly specified $charset = $charset ?: 'utf-8'; + // Return XML: - return '' . LF . self::array2xml($array, '', 0, $docTag, 0, $options); + return ''.LF.self::array2xml($array, '', 0, $docTag, 0, $options); } public static function array2xml(array $array, $NSprefix = '', $level = 0, $docTag = 'phparray', $spaceInd = 0, array $options = [], array $stackData = []): string @@ -177,4 +178,40 @@ public static function csvValues(array $row, $delim = ',', $quote = '"'): void { } + + public static function compat_version(): void + { + } + + public static function convertMicrotime(): void + { + } + + public static function deHSCentities(): void + { + } + + public static function slashJS(): void + { + } + + public static function rawUrlEncodeJS(): void + { + } + + public static function rawUrlEncodeFP(): void + { + } + + public static function lcfirst(): void + { + } + + public static function getMaximumPathLength(): void + { + } + + public static function wrapJS($string, $_ = null): void + { + } } diff --git a/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/Fixture/compat_version.php.inc b/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/Fixture/compat_version.php.inc new file mode 100644 index 000000000..c9e840e9a --- /dev/null +++ b/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/Fixture/compat_version.php.inc @@ -0,0 +1,16 @@ + +----- += VersionNumberUtility::convertVersionNumberToInteger('foobar'); + +?> diff --git a/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/Fixture/convert_microtime.php.inc b/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/Fixture/convert_microtime.php.inc new file mode 100644 index 000000000..d6b94550c --- /dev/null +++ b/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/Fixture/convert_microtime.php.inc @@ -0,0 +1,16 @@ + +----- + diff --git a/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/Fixture/get_maximum_path_length.php.inc b/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/Fixture/get_maximum_path_length.php.inc new file mode 100644 index 000000000..0335c05c5 --- /dev/null +++ b/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/Fixture/get_maximum_path_length.php.inc @@ -0,0 +1,15 @@ + +----- + diff --git a/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/Fixture/lcfirst.php.inc b/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/Fixture/lcfirst.php.inc new file mode 100644 index 000000000..690df6a3f --- /dev/null +++ b/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/Fixture/lcfirst.php.inc @@ -0,0 +1,15 @@ + +----- + diff --git a/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/Fixture/raw_url_encode_fp.php.inc b/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/Fixture/raw_url_encode_fp.php.inc new file mode 100644 index 000000000..d4ff60e82 --- /dev/null +++ b/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/Fixture/raw_url_encode_fp.php.inc @@ -0,0 +1,17 @@ + +----- + diff --git a/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/Fixture/raw_url_encode_js.php.inc b/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/Fixture/raw_url_encode_js.php.inc new file mode 100644 index 000000000..fc08b34ba --- /dev/null +++ b/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/Fixture/raw_url_encode_js.php.inc @@ -0,0 +1,17 @@ + +----- + diff --git a/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/RefactorVariousGeneralUtilityMethodsRectorTest.php b/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/RefactorVariousGeneralUtilityMethodsRectorTest.php new file mode 100644 index 000000000..3c1949e84 --- /dev/null +++ b/tests/Rector/v8/v1/RefactorVariousGeneralUtilityMethods/RefactorVariousGeneralUtilityMethodsRectorTest.php @@ -0,0 +1,31 @@ +doTestFileInfo($fileInfo); + } + + public function provideDataForTest(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + protected function getRectorClass(): string + { + return RefactorVariousGeneralUtilityMethodsRector::class; + } +}