From b60bc416401862d6d9ca2cf5c98b4fcd71f917fa Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Thu, 20 Jul 2023 10:36:06 +0200 Subject: [PATCH] [TASK] Improve return type annotations for GU::trimExplode This particularly helps PHPStan in extensions that call those methods detect unnecessary checks for empty strings if `GU::trimExplode` is called with `$removeEmptyValues = true`. Used command: > ./Build/Scripts/runTests.sh -s phpstanGenerateBaseline Resolves: #101395 Related: #99147 Releases: main, 12.4, 11.5 Change-Id: I6945cc0698b0777a05cb9327b342aa9aa7dee098 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80137 Tested-by: core-ci Tested-by: Christian Kuhn Reviewed-by: Christian Kuhn --- Build/phpstan/phpstan-baseline.neon | 4 ++-- typo3/sysext/core/Classes/Utility/GeneralUtility.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon index c149d0da81b0..4132a705189c 100644 --- a/Build/phpstan/phpstan-baseline.neon +++ b/Build/phpstan/phpstan-baseline.neon @@ -246,12 +246,12 @@ parameters: path: ../../typo3/sysext/beuser/Classes/Domain/Repository/BackendUserRepository.php - - message: "#^Offset 'tables_modify' on array\\{tables_select\\: array\\, tables_modify\\: array\\\\} on left side of \\?\\? always exists and is not nullable\\.$#" + message: "#^Offset 'tables_modify' on array\\{tables_select\\: array\\, tables_modify\\: array\\\\} on left side of \\?\\? always exists and is not nullable\\.$#" count: 1 path: ../../typo3/sysext/beuser/Classes/Service/UserInformationService.php - - message: "#^Offset 'tables_select' on array\\{tables_select\\: array\\, tables_modify\\: array\\\\} on left side of \\?\\? always exists and is not nullable\\.$#" + message: "#^Offset 'tables_select' on array\\{tables_select\\: array\\, tables_modify\\: array\\\\} on left side of \\?\\? always exists and is not nullable\\.$#" count: 1 path: ../../typo3/sysext/beuser/Classes/Service/UserInformationService.php diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php index 33e3fe998c78..9d2d27f73a30 100644 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -925,6 +925,7 @@ public static function revExplode($delimiter, $string, $limit = 0) * the last element containing the rest of string. If the limit parameter is negative, all components * except the last -limit are returned. * @return list Exploded values + * @phpstan-return ($removeEmptyValues is true ? list : list) Exploded values */ public static function trimExplode($delim, $string, $removeEmptyValues = false, $limit = 0): array {