Commit 63031fb2 authored by Oliver Bartsch's avatar Oliver Bartsch Committed by Andreas Fernandez
Browse files

[TASK] Deprecate GeneralUtility::rmFromList

GeneralUtility::rmFromList is unused since v10. If at
all, this method would better belong to StringUtility.

Therefore, it's now deprecated in GeneralUtility, but
could be reimplemented in a more performant way in
StringUtility, when needed again.

Resolves: #94311
Releases: master
Change-Id: I2ea5ec57143d70fa2a0de2d2c34230764d3ce204
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69459


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
parent 3ac058de
......@@ -538,9 +538,15 @@ class GeneralUtility
* @param string $element Element to remove
* @param string $list Comma-separated list of items (string)
* @return string New comma-separated list of items
* @deprecated since v11, will be removed in v12.
*/
public static function rmFromList($element, $list)
{
trigger_error(
'GeneralUtility::rmFromList() is deprecated and will be removed in v12.',
E_USER_DEPRECATED
);
$items = explode(',', $list);
foreach ($items as $k => $v) {
if ($v == $element) {
......
.. include:: ../../Includes.txt
===========================================================
Deprecation: #94311 - Deprecated GeneralUtility::rmFromList
===========================================================
See :issue:`94311`
Description
===========
The method :php:`GeneralUtility::rmFromList()` is unused within TYPO3
Core since v10. Because of this and the fact that this method would
anyways better belong to :php:`StringUtility` it has now been deprecated
in :php:`GeneralUtility` and will be removed in TYPO3 v12.
Impact
======
Calling the method will log a deprecation warning and the method will
be dropped with TYPO3 v12.
Affected Installations
======================
All TYPO3 installations calling this method in custom code. The extension
scanner will find all usages as strong match.
Migration
=========
Replace all usages of the method in your extension code.
.. index:: PHP-API, FullyScanned, ext:core
......@@ -539,46 +539,6 @@ class GeneralUtilityTest extends UnitTestCase
];
}
///////////////////////////////
// Tests concerning rmFromList
///////////////////////////////
/**
* @test
* @param string $initialList
* @param string $listWithElementRemoved
* @dataProvider rmFromListRemovesElementsFromCommaSeparatedListDataProvider
*/
public function rmFromListRemovesElementsFromCommaSeparatedList($initialList, $listWithElementRemoved)
{
self::assertSame($listWithElementRemoved, GeneralUtility::rmFromList('removeme', $initialList));
}
/**
* Data provider for rmFromListRemovesElementsFromCommaSeparatedList
*
* @return array
*/
public function rmFromListRemovesElementsFromCommaSeparatedListDataProvider()
{
return [
'Element as second element of three' => ['one,removeme,two', 'one,two'],
'Element at beginning of list' => ['removeme,one,two', 'one,two'],
'Element at end of list' => ['one,two,removeme', 'one,two'],
'One item list' => ['removeme', ''],
'Element not contained in list' => ['one,two,three', 'one,two,three'],
'Empty element survives' => ['one,,three,,removeme', 'one,,three,'],
'Empty element survives at start' => [',removeme,three,removeme', ',three'],
'Empty element survives at end' => ['removeme,three,removeme,', 'three,'],
'Empty list' => ['', ''],
'List contains removeme multiple times' => ['removeme,notme,removeme,removeme', 'notme'],
'List contains removeme multiple times nothing else' => ['removeme,removeme,removeme', ''],
'List contains removeme multiple times nothing else 2x' => ['removeme,removeme', ''],
'List contains removeme multiple times nothing else 3x' => ['removeme,removeme,removeme', ''],
'List contains removeme multiple times nothing else 4x' => ['removeme,removeme,removeme,removeme', ''],
'List contains removeme multiple times nothing else 5x' => ['removeme,removeme,removeme,removeme,removeme', ''],
];
}
///////////////////////////////
// Tests concerning expandList
///////////////////////////////
......
......@@ -46,4 +46,44 @@ class GeneralUtilityTest extends UnitTestCase
$result = GeneralUtility::compileSelectedGetVarsFromArray($filter, $getArray, true);
self::assertSame($expected, $result);
}
/**
* @test
* @dataProvider rmFromListRemovesElementsFromCommaSeparatedListDataProvider
*
* @param string $initialList
* @param string $listWithElementRemoved
*/
public function rmFromListRemovesElementsFromCommaSeparatedList(
string $initialList,
string $listWithElementRemoved
): void {
self::assertSame($listWithElementRemoved, GeneralUtility::rmFromList('removeme', $initialList));
}
/**
* Data provider for rmFromListRemovesElementsFromCommaSeparatedList
*
* @return array
*/
public function rmFromListRemovesElementsFromCommaSeparatedListDataProvider(): array
{
return [
'Element as second element of three' => ['one,removeme,two', 'one,two'],
'Element at beginning of list' => ['removeme,one,two', 'one,two'],
'Element at end of list' => ['one,two,removeme', 'one,two'],
'One item list' => ['removeme', ''],
'Element not contained in list' => ['one,two,three', 'one,two,three'],
'Empty element survives' => ['one,,three,,removeme', 'one,,three,'],
'Empty element survives at start' => [',removeme,three,removeme', ',three'],
'Empty element survives at end' => ['removeme,three,removeme,', 'three,'],
'Empty list' => ['', ''],
'List contains removeme multiple times' => ['removeme,notme,removeme,removeme', 'notme'],
'List contains removeme multiple times nothing else' => ['removeme,removeme,removeme', ''],
'List contains removeme multiple times nothing else 2x' => ['removeme,removeme', ''],
'List contains removeme multiple times nothing else 3x' => ['removeme,removeme,removeme', ''],
'List contains removeme multiple times nothing else 4x' => ['removeme,removeme,removeme,removeme', ''],
'List contains removeme multiple times nothing else 5x' => ['removeme,removeme,removeme,removeme,removeme', ''],
];
}
}
......@@ -1086,4 +1086,11 @@ return [
'Deprecation-94309-DeprecatedGeneralUtilitystdAuthCode.rst'
],
],
'TYPO3\CMS\Core\Utility\GeneralUtility::rmFromList' => [
'numberOfMandatoryArguments' => 2,
'maximumNumberOfArguments' => 2,
'restFiles' => [
'Deprecation-94311-DeprecatedGeneralUtilityrmFromList.rst'
],
],
];
Supports Markdown
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