[TASK] Switch specific strpos() usages with equivalent string methods
Due to a former lack of missing proper functions to check for strings starting, ending or containing sub-strings, workarounds with strpos() constructs have been used in TYPO3 as well as in just about every PHP application. PHP finally implemented proper native functions for these kind of tasks, which make code more readable and avoid to easily oversee bugs. Additionally, php-cs-fixer provides a rule-set to replace most of these changes, see: https://cs.symfony.com/doc/ruleSets/PHP80MigrationRisky.html This rule is now enabled and used to ensure cleaner code in the future. The rule is applied to ensure green cgl checks. Replacements covered by php-cs-fixer rule: * replace `strpos($haystack, $needle) === 0` with `str_starts_with($haystack, $needle)` * replace `strpos($haystack, $needle) !== 0` with `!str_starts_with($haystack, $needle)` * replace `strpos($haystack, $needle) !== false` with `str_contains($haystack, $needle)` * replace `strpos($haystack, $needle) === false` with `!str_contains($haystack, $needle)` Some additional (manual) replacements on nearby places to changed code places: * replace `substr($haystack, strlen($needle) * -1) === $needle` with `str_ends_with($expression, ']')` * replace `substr($haystack, strlen($needle) * -1) !== $needle` with `!str_ends_with($expression, ']')` Used commands: > Build/Scripts/runTests.sh -s cgl Resolves: #97438 Releases: main Change-Id: Ia1206d4dd08b43597bfe794389f6db8bdeb3de0f Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74365 Tested-by:core-ci <typo3@b13.com> Tested-by:
Nikita Hovratov <nikita.h@live.de> Tested-by:
Stefan Bürk <stefan@buerk.tech> Tested-by:
Georg Ringer <georg.ringer@gmail.com> Reviewed-by:
Nikita Hovratov <nikita.h@live.de> Reviewed-by:
crell <larry@garfieldtech.com> Reviewed-by:
Stefan Bürk <stefan@buerk.tech> Reviewed-by:
Georg Ringer <georg.ringer@gmail.com>
Showing
- Build/php-cs-fixer.php 1 addition, 0 deletionsBuild/php-cs-fixer.php
- typo3/sysext/backend/Classes/Controller/FormInlineAjaxController.php 3 additions, 1 deletion...t/backend/Classes/Controller/FormInlineAjaxController.php
- typo3/sysext/backend/Classes/Controller/SiteInlineAjaxController.php 1 addition, 1 deletion...t/backend/Classes/Controller/SiteInlineAjaxController.php
- typo3/sysext/backend/Classes/Controller/Wizard/AddController.php 2 additions, 2 deletions...ysext/backend/Classes/Controller/Wizard/AddController.php
- typo3/sysext/backend/Classes/Controller/Wizard/ListController.php 2 additions, 2 deletions...sext/backend/Classes/Controller/Wizard/ListController.php
- typo3/sysext/backend/Classes/Form/Container/FullRecordContainer.php 2 additions, 2 deletions...xt/backend/Classes/Form/Container/FullRecordContainer.php
- typo3/sysext/backend/Classes/Form/Container/InlineRecordContainer.php 1 addition, 1 deletion.../backend/Classes/Form/Container/InlineRecordContainer.php
- typo3/sysext/backend/Classes/Form/FormDataCompiler.php 1 addition, 1 deletiontypo3/sysext/backend/Classes/Form/FormDataCompiler.php
- typo3/sysext/backend/Classes/Form/FormDataProvider/DatabaseUniqueUidNewRow.php 1 addition, 1 deletion...Classes/Form/FormDataProvider/DatabaseUniqueUidNewRow.php
- typo3/sysext/backend/Classes/Form/FormDataProvider/EvaluateDisplayConditions.php 3 additions, 3 deletions...asses/Form/FormDataProvider/EvaluateDisplayConditions.php
- typo3/sysext/backend/Classes/Form/FormDataProvider/SiteTcaInline.php 2 additions, 2 deletions...t/backend/Classes/Form/FormDataProvider/SiteTcaInline.php
- typo3/sysext/backend/Classes/Form/FormDataProvider/TcaColumnsProcessPlaceholders.php 1 addition, 1 deletion...s/Form/FormDataProvider/TcaColumnsProcessPlaceholders.php
- typo3/sysext/backend/Classes/Form/FormDataProvider/TcaInline.php 1 addition, 1 deletion...ysext/backend/Classes/Form/FormDataProvider/TcaInline.php
- typo3/sysext/backend/Classes/Form/FormDataProvider/TcaSiteLanguage.php 3 additions, 3 deletions...backend/Classes/Form/FormDataProvider/TcaSiteLanguage.php
- typo3/sysext/backend/Classes/History/RecordHistory.php 1 addition, 1 deletiontypo3/sysext/backend/Classes/History/RecordHistory.php
- typo3/sysext/backend/Classes/Search/LiveSearch/QueryParser.php 1 addition, 1 deletion.../sysext/backend/Classes/Search/LiveSearch/QueryParser.php
- typo3/sysext/backend/Classes/Tree/View/PagePositionMap.php 1 addition, 1 deletiontypo3/sysext/backend/Classes/Tree/View/PagePositionMap.php
- typo3/sysext/backend/Classes/Utility/BackendUtility.php 1 addition, 1 deletiontypo3/sysext/backend/Classes/Utility/BackendUtility.php
- typo3/sysext/backend/Classes/View/BackendLayoutView.php 1 addition, 1 deletiontypo3/sysext/backend/Classes/View/BackendLayoutView.php
- typo3/sysext/belog/Classes/Domain/Repository/LogEntryRepository.php 2 additions, 2 deletions...xt/belog/Classes/Domain/Repository/LogEntryRepository.php
Please register or sign in to comment