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
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
......@@ -22,12 +24,9 @@ class StringUtility
{
/**
* 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.
*
* @param string $prefix
* @return string
* Furthermore, the dots are removed so the id can be used inside HTML attributes e.g. id.
*/
public static function getUniqueId($prefix = '')
public static function getUniqueId(string $prefix = ''): string
{
$uniqueId = uniqid($prefix, true);
return str_replace('.', '', $uniqueId);
......@@ -38,9 +37,6 @@ class StringUtility
*
* This method takes care to escape any CSS selector meta character.
* The result may be used to query the DOM like $('#' + escapedSelector)
*
* @param string $selector
* @return string
*/
public static function escapeCssSelector(string $selector): string
{
......@@ -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
* @return string
* This method supports UTF-8 encoded strings only!
*/
public static function removeByteOrderMark(string $input): string
{
......@@ -69,7 +64,7 @@ class StringUtility
* @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.
*/
public static function searchStringWildcard($haystack, $needle): bool
public static function searchStringWildcard(string $haystack, string $needle): bool
{
$result = false;
if ($haystack === $needle) {
......@@ -93,7 +88,7 @@ class StringUtility
* Takes a comma-separated list and removes all duplicates.
* 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.
*/
public static function uniqueList(string $list): string
......@@ -104,13 +99,6 @@ class StringUtility
/**
* Works the same as str_pad() except that it correctly handles strings with multibyte characters
* 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
{
......
......@@ -21,6 +21,7 @@ expectations and existing behavior.
- :php:`\TYPO3\CMS\Core\Utility\MathUtility`
- :php:`\TYPO3\CMS\Core\Utility\PathUtility`
- :php:`\TYPO3\CMS\Core\Utility\RootlineUtility`
- :php:`\TYPO3\CMS\Core\Utility\StringUtility`
- :php:`\TYPO3\CMS\Core\Utility\VersionNumberUtility`
The following PHP classes have added public class property types:
......
......@@ -44,8 +44,6 @@ class StringUtilityTest extends UnitTestCase
/**
* @test
* @param string $selector
* @param string $expectedValue
* @dataProvider escapeCssSelectorDataProvider
*/
public function escapeCssSelector(string $selector, string $expectedValue): void
......@@ -53,9 +51,6 @@ class StringUtilityTest extends UnitTestCase
self::assertEquals($expectedValue, StringUtility::escapeCssSelector($selector));
}
/**
* @return array
*/
public function escapeCssSelectorDataProvider(): array
{
return [
......@@ -68,8 +63,6 @@ class StringUtilityTest extends UnitTestCase
}
/**
* @param string $input
* @param string $expectedValue
* @test
* @dataProvider removeByteOrderMarkDataProvider
*/
......@@ -79,9 +72,6 @@ class StringUtilityTest extends UnitTestCase
self::assertSame($expectedValue, StringUtility::removeByteOrderMark(hex2bin($input)));
}
/**
* @return array
*/
public function removeByteOrderMarkDataProvider(): array
{
return [
......@@ -151,8 +141,6 @@ class StringUtilityTest extends UnitTestCase
/**
* Data provider for uniqueListUnifiesCommaSeparatedList
*
* @return \Generator
*/
public function uniqueListUnifiesCommaSeparatedListDataProvider(): \Generator
{
......@@ -169,10 +157,6 @@ class StringUtilityTest extends UnitTestCase
/**
* @test
*
* @param string $initialList
* @param string $unifiedList
*
* @dataProvider uniqueListUnifiesCommaSeparatedListDataProvider
*/
public function uniqueListUnifiesCommaSeparatedList(string $initialList, string $unifiedList): void
......@@ -182,8 +166,6 @@ class StringUtilityTest extends UnitTestCase
/**
* Data provider for multibyteStringPadReturnsSameValueAsStrPadForAsciiStrings
*
* @return \Generator
*/
public function multibyteStringPadReturnsSameValueAsStrPadForAsciiStringsDataProvider(): \Generator
{
......@@ -203,16 +185,10 @@ class StringUtilityTest extends UnitTestCase
}
/**
* @test
*
* Tests that StringUtility::multibyteStringPad() returns the same value as \str_pad()
* for ASCII strings.
*
* @param string $string
* @param int $length
* @param string $pad_string
* @param int $pad_type
*
* @test
* @dataProvider multibyteStringPadReturnsSameValueAsStrPadForAsciiStringsDataProvider
*/
public function multibyteStringPadReturnsSameValueAsStrPadForAsciiStrings(string $string, int $length, string $pad_string, int $pad_type): void
......@@ -242,13 +218,6 @@ class StringUtilityTest extends UnitTestCase
/**
* @test
*
* @param string $expectedResult
* @param string $string
* @param int $length
* @param string $pad_string
* @param int $pad_type
*
* @dataProvider multibyteStringPadReturnsCorrectResultsMultibyteDataProvider
*/
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