Review main Merged

74365[TASK] Switch specific strpos() usages with equivalent string methods

crell CR +2 V +2 Hard +192 −183 updated 04/22/22, 21:19

Commit message

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

Review

  • Code review CR +2

    Imported before Forger kept the single votes, the next import adds them.

  • Verified V +2

    Imported before Forger kept the single votes, the next import adds them.

Issues 1

Files 108

Show 88 more files