Review main Merged

75732[TASK] Prevent undefined array key warnings in ext:beuser

Oliver Hader CR +2 V +2 Normal +63 −38 updated 09/19/22, 15:22

Commit message

This change addresses several "undefined array key" issues that have
been identified by PsalmPHP (see issue #98321).

Review

  • Code review CR +2 Done
    • Oliver Hader +2
    • Oliver Klee +1
    • Stefan Bürk +1
    • Christian Kuhn +1
  • Verified V +2 Done
    • Oliver Hader +2
    • Stefan Bürk +1
    • Christian Kuhn +1
    • core-ci +1 CI

Issues 2

Files 9

Review log 1417

  1. Oliver Hader uploaded patch set 1 09/15/22, 09:35

  2. core-ci voted on patch set 1 V +1 09/15/22, 09:48 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31103

  3. Oliver Klee commented on patch set 1 09/15/22, 09:58

    BackendUserController.php:252

    For better readability, I suggest moving this to a local variable $userName (or $username).

    BackendUserGroupRepository.php:53

    Also, this looks a bit out of scope for this change and should go into a separate change.

    BackendUserGroupRepository.php:53

    Just to be safe, we should use a named parameter with Connection::PARAM_INT_ARRAY.

    UserInformationService.php:128

    We need to skip these two lines if $recordUid is null.

    UserInformationService.php:226

    We should skip this line if $itemField is an empty string.

    ArrayElementViewHelper.php:44

    To make it more clear to clear to the read at the first glance what is what, pleas let's put at least the array key "array" into quotes (or for consistency, all array keys in this array shape).

    PermissionsViewHelper.php:99

    @param value-of<self::MASKS> $mask

    SpriteIconForRecordViewHelper.php:56

    Same as above: Please let's have quotes at least around the array key "object".
  4. Oliver Hader commented on patch set 1 09/16/22, 06:52

    BackendUserGroupRepository.php:53 Reply

    No, that's the Extbase Query Builder

    BackendUserGroupRepository.php:53 Reply

    Fine

    UserInformationService.php:128 Reply

    It reflects the current behavior, `null` is casted implicitly to `string` as array key. Using `if (isset($record['uid']))` would change that behavior - but I agree, it would make more sense.

    UserInformationService.php:226 Reply

    Again, that would change the current behavior

    PermissionsViewHelper.php:99 Reply

    How would that be helpful, and why is `int` not enough here?
  5. Oliver Hader commented on patch set 1 09/16/22, 07:11

  6. Oliver Hader uploaded patch set 2 09/16/22, 07:32

  7. core-ci voted on patch set 2 V +1 09/16/22, 07:40 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31148

  8. Oliver Hader commented on patch set 2 09/16/22, 07:45

    BackendUserController.php:252 Reply

    Done

    BackendUserGroupRepository.php:53 Reply

    Done

    BackendUserGroupRepository.php:53 Reply

    UserInformationService.php:128 Reply

    Done

    UserInformationService.php:226 Reply

    Done

    ArrayElementViewHelper.php:44 Reply

    Done

    PermissionsViewHelper.php:99 Reply

    Skipped this

    SpriteIconForRecordViewHelper.php:56 Reply

    Done
  9. Christian Kuhn updated the commit message in patch set 3 09/16/22, 08:32

  10. core-ci voted on patch set 3 V +1 09/16/22, 08:39 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31152

  11. Oliver Klee commented on patch set 3 09/16/22, 09:52

    BackendUserController.php:248

    I think have the positive case first and the fallback would make this a bit easier to understand (as this is the way most other ternary-operator usages in the core work).

    BackendUserGroupRepository.php:53 Reply

    Ack, and thanks!

    PermissionsViewHelper.php:99 Reply

    This helps static analysis as this narrows the allowed values of $mask from "any possible int, including negative values, zero and 12341234" to "only values from the corresponding array", which allows PHPStan to …: 1. know in the method that the values of $mask are within those values 2. complain if callers put in "any random int", which helps catch bad calls (code-wise)
  12. Christian Kuhn voted on patch set 3 V +1 CR +1 09/16/22, 10:27

  13. Christian Kuhn commented on patch set 3 09/16/22, 10:29

    BackendUserController.php:248 Reply

    that's a minor detail. i'd be fine to keep it like it is for now.
  14. Stefan Bürk voted on patch set 3 V +1 CR +1 09/16/22, 11:37

  15. Oliver Klee voted on patch set 3 CR +1 09/16/22, 13:14

  16. Oliver Hader voted on patch set 3 V +2 CR +2 09/19/22, 15:21

  17. Oliver Hader merged patch set 4 09/19/22, 15:22