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 Done
    • Georg Ringer +2
    • crell +1
    • Stefan Bürk +1
    • Nikita Hovratov +1
  • Verified V +2 Done
    • Georg Ringer +2
    • Stefan Bürk +1
    • Nikita Hovratov +1
    • core-ci +1 CI

Issues 1

Files 108

Show 88 more files

Review log 1924

  1. crell uploaded patch set 1 04/20/22, 21:18

  2. core-ci voted on patch set 1 V +1 04/20/22, 21:27 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26253

  3. Stefan Bürk commented on patch set 1 CR -1 04/21/22, 10:15

    on it
  4. Stefan Bürk commented on patch set 1 04/21/22, 13:18

    FormInlineAjaxController.php:57

    Weired line break. Should be adjusted. Either online or the line starting with && to a new line ....

    PagePositionMap.php:205

    We can ommit superflous paranthesis now arount the blocks, as they are self contained now.

    FormTestService.php:64

    This is also a bugfix/change in behaviour. Old variant returned "false" if $formHtml startet with "[$fieldName]", str_contains() will return true. See: https://3v4l.org/IFcC3#v8.1.5 Maybe we should "consider" to extract this for fixing in v11 too, as a dedicated direct patch.

    ExpressionBuilder.php:689

    Could be simplified / made more clear with: `str_ends_with($value, $quoteChar)`

    SqlReader.php:100

    Can be replaced with `str_ends_with()`

    SqlReader.php:103

    Can be replaced with `!str_ends_with()`

    SqlReader.php:106

    Can be replaced with `str_ends_with()`

    SqlReader.php:114

    Can be replaced with `str_ends_with()`

    RteHtmlParser.php:647

    Can be replaced with `!str_ends_with()`

    RteHtmlParser.php:647

    Superlous empty chars

    RteHtmlParser.php:648

    Superflous empty chars and substr() can be replaced with `!str_ends_with()`

    PageUriMatcher.php:85

    Superflous spaces.

    TemplateService.php:716

    Superflous spaces.

    TemplateService.php:763

    Additional lets add paranthesis to current php operator order as minor side change - May help in debugging to see if this may be a bug or not in the future.

    TemplateService.php:763

    Superflous spaces.

    ExtensionManagementUtility.php:158

    Superflous spaces.

    GeneralUtility.php:1417

    Superflous spaces.

    GeneralUtility.php:2685

    superflous spaces.

    PathUtility.php:465

    Superflous spaces.

    Repository.php:222

    Superflous spaces.

    Repository.php:228

    Superflous spaces.

    Repository.php:239

    Superflous spaces.

    DocumentationFile.php:245

    Superflous spaces.

    DatabaseIntegrityController.php:166

    Superflous spaces.
  5. Stefan Bürk uploaded patch set 2 04/21/22, 13:28

  6. Stefan Bürk commented on patch set 2 04/21/22, 13:31

    FormInlineAjaxController.php:57 Reply

    Done

    PagePositionMap.php:205 Reply

    Done

    SqlReader.php:100 Reply

    Done

    SqlReader.php:103 Reply

    Done

    SqlReader.php:106 Reply

    Done

    SqlReader.php:114 Reply

    Done

    RteHtmlParser.php:647 Reply

    Done

    RteHtmlParser.php:647 Reply

    Done

    RteHtmlParser.php:648 Reply

    Done

    PageUriMatcher.php:85 Reply

    Done

    TemplateService.php:716 Reply

    Done

    TemplateService.php:763 Reply

    Done

    TemplateService.php:763 Reply

    Done

    ExtensionManagementUtility.php:158 Reply

    Done

    GeneralUtility.php:1417 Reply

    Done

    GeneralUtility.php:2685 Reply

    Done

    PathUtility.php:465 Reply

    Done

    Repository.php:222 Reply

    Done

    Repository.php:228 Reply

    Done

    Repository.php:239 Reply

    Done

    DocumentationFile.php:245 Reply

    Done

    DatabaseIntegrityController.php:166 Reply

    Done
  7. core-ci voted on patch set 2 V +1 04/21/22, 13:45 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26272

  8. crell uploaded patch set 3 04/21/22, 14:05

  9. crell commented on patch set 2 04/21/22, 14:06

    FormTestService.php:64 Reply

    str_contains() was added in PHP 8, so it's not safe to use in v11 as it supports PHP 7.4. Sad panda. I think for now we just back this change out, since it's not a direct translation from one call to the other.

    ExpressionBuilder.php:689 Reply

    Done
  10. core-ci voted on patch set 3 V +1 04/21/22, 14:17 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26273

  11. Stefan Bürk commented on patch set 3 04/21/22, 14:20

    FormTestService.php:64 Reply

    We have corresponding symfony/polyfill for it in v11. And already str_contains() placed/backported to v11.
  12. Stefan Bürk voted on patch set 3 V +1 CR +1 04/21/22, 16:44

  13. Nikita Hovratov updated the commit message in patch set 4 04/21/22, 17:11

  14. Nikita Hovratov voted on patch set 4 V +1 CR +1 04/21/22, 17:13

  15. Stefan Bürk voted on patch set 4 V +1 CR +1 04/21/22, 17:14

  16. core-ci voted on patch set 4 V +1 04/21/22, 17:26 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26281

  17. Oliver Hader voted on patch set 4 CR +1 04/21/22, 18:15

  18. Stefan Bürk uploaded patch set 5 04/22/22, 18:34

  19. core-ci voted on patch set 5 V +1 04/22/22, 18:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26315

  20. Nikita Hovratov voted on patch set 5 V +1 CR +1 04/22/22, 18:50

  21. crell commented on patch set 5 CR +1 04/22/22, 19:08

    I don't see a change here other than a new parent, but +1 either way.
  22. Stefan Bürk commented on patch set 5 V +1 CR +1 04/22/22, 21:06

    Reply

    Rebased and solved merge-conflict.
  23. Georg Ringer voted on patch set 5 V +2 CR +2 04/22/22, 21:19

  24. Georg Ringer merged patch set 6 04/22/22, 21:19