Commit cac6bc6b authored by crell's avatar crell Committed by Stefan Bürk
Browse files

[!!!][TASK] Add native types to StringUtility

Also, clean up related tests' doc blocks.

Resolves: #97382
Related: #97210
Related: #97372
Releases: main
Change-Id: I5f9a99f35bf2e1afbbdeeec1cc1de98157e581ea
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74316

Tested-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Reviewed-by: Oliver Klee's avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
parent 8e912dd8
<?php <?php
declare(strict_types=1);
/* /*
* This file is part of the TYPO3 CMS project. * This file is part of the TYPO3 CMS project.
* *
...@@ -22,12 +24,9 @@ class StringUtility ...@@ -22,12 +24,9 @@ class StringUtility
{ {
/** /**
* This function generates a unique id by using the more entropy parameter. * This function generates a unique id by using the more entropy parameter.
* Furthermore the dots are removed so the id can be used inside HTML attributes e.g. id. * Furthermore, the dots are removed so the id can be used inside HTML attributes e.g. id.
*
* @param string $prefix
* @return string
*/ */
public static function getUniqueId($prefix = '') public static function getUniqueId(string $prefix = ''): string
{ {
$uniqueId = uniqid($prefix, true); $uniqueId = uniqid($prefix, true);
return str_replace('.', '', $uniqueId); return str_replace('.', '', $uniqueId);
...@@ -38,9 +37,6 @@ class StringUtility ...@@ -38,9 +37,6 @@ class StringUtility
* *
* This method takes care to escape any CSS selector meta character. * This method takes care to escape any CSS selector meta character.
* The result may be used to query the DOM like $('#' + escapedSelector) * The result may be used to query the DOM like $('#' + escapedSelector)
*
* @param string $selector
* @return string
*/ */
public static function escapeCssSelector(string $selector): string public static function escapeCssSelector(string $selector): string
{ {
...@@ -48,10 +44,9 @@ class StringUtility ...@@ -48,10 +44,9 @@ class StringUtility
} }
/** /**
* Removes the Byte Order Mark (BOM) from the input string. This method supports UTF-8 encoded strings only! * Removes the Byte Order Mark (BOM) from the input string.
* *
* @param string $input * This method supports UTF-8 encoded strings only!
* @return string
*/ */
public static function removeByteOrderMark(string $input): string public static function removeByteOrderMark(string $input): string
{ {
...@@ -69,7 +64,7 @@ class StringUtility ...@@ -69,7 +64,7 @@ class StringUtility
* @param string $needle The string to find in $haystack * @param string $needle The string to find in $haystack
* @return bool Returns TRUE if $needle matches or is found in (according to wildcards) $haystack. E.g. if $haystack is "Netscape 6.5" and $needle is "Net*" or "Net*ape" then it returns TRUE. * @return bool Returns TRUE if $needle matches or is found in (according to wildcards) $haystack. E.g. if $haystack is "Netscape 6.5" and $needle is "Net*" or "Net*ape" then it returns TRUE.
*/ */
public static function searchStringWildcard($haystack, $needle): bool public static function searchStringWildcard(string $haystack, string $needle): bool
{ {
$result = false; $result = false;
if ($haystack === $needle) { if ($haystack === $needle) {
...@@ -93,7 +88,7 @@ class StringUtility ...@@ -93,7 +88,7 @@ class StringUtility
* Takes a comma-separated list and removes all duplicates. * Takes a comma-separated list and removes all duplicates.
* If a value in the list is trim(empty), the value is ignored. * If a value in the list is trim(empty), the value is ignored.
* *
* @param string $list Accept a comma-separated list of values. * @param string $list A comma-separated list of values.
* @return string Returns the list without any duplicates of values, space around values are trimmed. * @return string Returns the list without any duplicates of values, space around values are trimmed.
*/ */
public static function uniqueList(string $list): string public static function uniqueList(string $list): string
...@@ -104,13 +99,6 @@ class StringUtility ...@@ -104,13 +99,6 @@ class StringUtility
/** /**
* Works the same as str_pad() except that it correctly handles strings with multibyte characters * Works the same as str_pad() except that it correctly handles strings with multibyte characters
* and takes an additional optional argument $encoding. * and takes an additional optional argument $encoding.
*
* @param string $string
* @param int $length
* @param string $pad_string
* @param int $pad_type
* @param string $encoding
* @return string
*/ */
public static function multibyteStringPad(string $string, int $length, string $pad_string = ' ', int $pad_type = STR_PAD_RIGHT, string $encoding = 'UTF-8'): string public static function multibyteStringPad(string $string, int $length, string $pad_string = ' ', int $pad_type = STR_PAD_RIGHT, string $encoding = 'UTF-8'): string
{ {
......
...@@ -21,6 +21,7 @@ expectations and existing behavior. ...@@ -21,6 +21,7 @@ expectations and existing behavior.
- :php:`\TYPO3\CMS\Core\Utility\MathUtility` - :php:`\TYPO3\CMS\Core\Utility\MathUtility`
- :php:`\TYPO3\CMS\Core\Utility\PathUtility` - :php:`\TYPO3\CMS\Core\Utility\PathUtility`
- :php:`\TYPO3\CMS\Core\Utility\RootlineUtility` - :php:`\TYPO3\CMS\Core\Utility\RootlineUtility`
- :php:`\TYPO3\CMS\Core\Utility\StringUtility`
- :php:`\TYPO3\CMS\Core\Utility\VersionNumberUtility` - :php:`\TYPO3\CMS\Core\Utility\VersionNumberUtility`
The following PHP classes have added public class property types: The following PHP classes have added public class property types:
......
...@@ -44,8 +44,6 @@ class StringUtilityTest extends UnitTestCase ...@@ -44,8 +44,6 @@ class StringUtilityTest extends UnitTestCase
/** /**
* @test * @test
* @param string $selector
* @param string $expectedValue
* @dataProvider escapeCssSelectorDataProvider * @dataProvider escapeCssSelectorDataProvider
*/ */
public function escapeCssSelector(string $selector, string $expectedValue): void public function escapeCssSelector(string $selector, string $expectedValue): void
...@@ -53,9 +51,6 @@ class StringUtilityTest extends UnitTestCase ...@@ -53,9 +51,6 @@ class StringUtilityTest extends UnitTestCase
self::assertEquals($expectedValue, StringUtility::escapeCssSelector($selector)); self::assertEquals($expectedValue, StringUtility::escapeCssSelector($selector));
} }
/**
* @return array
*/
public function escapeCssSelectorDataProvider(): array public function escapeCssSelectorDataProvider(): array
{ {
return [ return [
...@@ -68,8 +63,6 @@ class StringUtilityTest extends UnitTestCase ...@@ -68,8 +63,6 @@ class StringUtilityTest extends UnitTestCase
} }
/** /**
* @param string $input
* @param string $expectedValue
* @test * @test
* @dataProvider removeByteOrderMarkDataProvider * @dataProvider removeByteOrderMarkDataProvider
*/ */
...@@ -79,9 +72,6 @@ class StringUtilityTest extends UnitTestCase ...@@ -79,9 +72,6 @@ class StringUtilityTest extends UnitTestCase
self::assertSame($expectedValue, StringUtility::removeByteOrderMark(hex2bin($input))); self::assertSame($expectedValue, StringUtility::removeByteOrderMark(hex2bin($input)));
} }
/**
* @return array
*/
public function removeByteOrderMarkDataProvider(): array public function removeByteOrderMarkDataProvider(): array
{ {
return [ return [
...@@ -151,8 +141,6 @@ class StringUtilityTest extends UnitTestCase ...@@ -151,8 +141,6 @@ class StringUtilityTest extends UnitTestCase
/** /**
* Data provider for uniqueListUnifiesCommaSeparatedList * Data provider for uniqueListUnifiesCommaSeparatedList
*
* @return \Generator
*/ */
public function uniqueListUnifiesCommaSeparatedListDataProvider(): \Generator public function uniqueListUnifiesCommaSeparatedListDataProvider(): \Generator
{ {
...@@ -169,10 +157,6 @@ class StringUtilityTest extends UnitTestCase ...@@ -169,10 +157,6 @@ class StringUtilityTest extends UnitTestCase
/** /**
* @test * @test
*
* @param string $initialList
* @param string $unifiedList
*
* @dataProvider uniqueListUnifiesCommaSeparatedListDataProvider * @dataProvider uniqueListUnifiesCommaSeparatedListDataProvider
*/ */
public function uniqueListUnifiesCommaSeparatedList(string $initialList, string $unifiedList): void public function uniqueListUnifiesCommaSeparatedList(string $initialList, string $unifiedList): void
...@@ -182,8 +166,6 @@ class StringUtilityTest extends UnitTestCase ...@@ -182,8 +166,6 @@ class StringUtilityTest extends UnitTestCase
/** /**
* Data provider for multibyteStringPadReturnsSameValueAsStrPadForAsciiStrings * Data provider for multibyteStringPadReturnsSameValueAsStrPadForAsciiStrings
*
* @return \Generator
*/ */
public function multibyteStringPadReturnsSameValueAsStrPadForAsciiStringsDataProvider(): \Generator public function multibyteStringPadReturnsSameValueAsStrPadForAsciiStringsDataProvider(): \Generator
{ {
...@@ -203,16 +185,10 @@ class StringUtilityTest extends UnitTestCase ...@@ -203,16 +185,10 @@ class StringUtilityTest extends UnitTestCase
} }
/** /**
* @test
*
* Tests that StringUtility::multibyteStringPad() returns the same value as \str_pad() * Tests that StringUtility::multibyteStringPad() returns the same value as \str_pad()
* for ASCII strings. * for ASCII strings.
* *
* @param string $string * @test
* @param int $length
* @param string $pad_string
* @param int $pad_type
*
* @dataProvider multibyteStringPadReturnsSameValueAsStrPadForAsciiStringsDataProvider * @dataProvider multibyteStringPadReturnsSameValueAsStrPadForAsciiStringsDataProvider
*/ */
public function multibyteStringPadReturnsSameValueAsStrPadForAsciiStrings(string $string, int $length, string $pad_string, int $pad_type): void public function multibyteStringPadReturnsSameValueAsStrPadForAsciiStrings(string $string, int $length, string $pad_string, int $pad_type): void
...@@ -242,13 +218,6 @@ class StringUtilityTest extends UnitTestCase ...@@ -242,13 +218,6 @@ class StringUtilityTest extends UnitTestCase
/** /**
* @test * @test
*
* @param string $expectedResult
* @param string $string
* @param int $length
* @param string $pad_string
* @param int $pad_type
*
* @dataProvider multibyteStringPadReturnsCorrectResultsMultibyteDataProvider * @dataProvider multibyteStringPadReturnsCorrectResultsMultibyteDataProvider
*/ */
public function multibyteStringPadReturnsCorrectResultsMultibyte(string $expectedResult, string $string, int $length, string $pad_string, int $pad_type): void public function multibyteStringPadReturnsCorrectResultsMultibyte(string $expectedResult, string $string, int $length, string $pad_string, int $pad_type): void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment