From 21324f20a96f78deb5850f7b7bb592a53c39a09f Mon Sep 17 00:00:00 2001 From: Oliver Klee <typo3-coding@oliverklee.de> 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/+/80138 Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: core-ci <typo3@b13.com> --- Build/Scripts/annotationChecker.php | 2 ++ Build/phpstan/phpstan-baseline.neon | 4 ++-- typo3/sysext/core/Classes/Utility/GeneralUtility.php | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Build/Scripts/annotationChecker.php b/Build/Scripts/annotationChecker.php index c4d5ec073f5d..af44c61628eb 100755 --- a/Build/Scripts/annotationChecker.php +++ b/Build/Scripts/annotationChecker.php @@ -75,6 +75,8 @@ class NodeVisitor extends NodeVisitorAbstract 'extensionScannerIgnoreFile', 'extensionScannerIgnoreLine', // static code analysis 'template', 'implements', 'extends', + // phpstan specific annotations + 'phpstan-var', 'phpstan-param', 'phpstan-return', ]; // allow annotation only on class level if (get_class($node) === Node\Stmt\Class_::class) { diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon index 91942ae5d61b..96efba98f5ab 100644 --- a/Build/phpstan/phpstan-baseline.neon +++ b/Build/phpstan/phpstan-baseline.neon @@ -501,12 +501,12 @@ parameters: path: ../../typo3/sysext/beuser/Classes/Controller/PermissionController.php - - message: "#^Offset 'tables_modify' on array\\{tables_select\\: array\\<string, mixed\\>, tables_modify\\: array\\<string, mixed\\>\\} on left side of \\?\\? always exists and is not nullable\\.$#" + message: "#^Offset 'tables_modify' on array\\{tables_select\\: array\\<non\\-empty\\-string, mixed\\>, tables_modify\\: array\\<non\\-empty\\-string, mixed\\>\\} 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\\<string, mixed\\>, tables_modify\\: array\\<string, mixed\\>\\} on left side of \\?\\? always exists and is not nullable\\.$#" + message: "#^Offset 'tables_select' on array\\{tables_select\\: array\\<non\\-empty\\-string, mixed\\>, tables_modify\\: array\\<non\\-empty\\-string, mixed\\>\\} 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 bc11be9c7faa..7fce932a0e68 100644 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -1001,6 +1001,7 @@ class GeneralUtility * the last element containing the rest of string. If the limit parameter is negative, all components * except the last -limit are returned. * @return list<string> Exploded values + * @phpstan-return ($removeEmptyValues is true ? list<non-empty-string> : list<string>) Exploded values */ public static function trimExplode($delim, $string, $removeEmptyValues = false, $limit = 0): array { -- GitLab