Review main Merged

74375[TASK] Address phpstan "Expression on left side of ??" errors

crell CR +2 V +2 Normal +39 −160 updated 05/13/22, 17:05

Commit message

There are several PHPStan Baseline exceptions for misuse of
the ?? operator. Many of them are no longer necessary thanks
to either other code evolution or PHP evolution. This patch
cleans those up.

Review

  • Code review CR +2 Done
    • Stefan Bürk +2
    • Nikita Hovratov +1
  • Verified V +2 Done
    • Stefan Bürk +2
    • Nikita Hovratov +1
    • core-ci +1 CI

Issues 1

Files 27

Show 7 more files

Review log 2735

Show 710 earlier messages
  1. crell uploaded patch set 1 04/22/22, 20:27

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

  3. Simon Schaufelberger commented on patch set 1 04/22/22, 23:02

    I guess this should be marked as breaking (!!!) as several method annotations are adjusted
  4. Oliver Klee commented on patch set 1 04/24/22, 11:51

    Honestly, I'm not a big fan of mixing two things in one changeset (in this case: resolving a specific type of PHPStan warning and adding more native types). This makes review harder (as there is no clear focus/purpose for the changeset anymore), and this increases the impact of backing out the commit case it has broken something. In addition, this prevents us from backporting the cleanup to 11.5. So I propose to split this changeset into two changesets: a) fix the PHPStan warnings (non-breaking, backportable to 11.5) b) add the native type declarations (breaking, not backportable)
  5. Oliver Klee voted on patch set 1 CR -1 04/24/22, 11:51

  6. crell uploaded patch set 2 05/02/22, 17:08

  7. Oliver Klee wrote 05/02/22, 17:15

    Removed reviewer Oliver Klee.
  8. core-ci voted on patch set 2 V +1 05/02/22, 17:24 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26741

  9. crell uploaded patch set 3 05/02/22, 17:24

  10. core-ci voted on patch set 3 V +1 05/02/22, 17:39 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26742

  1. Nikita Hovratov uploaded patch set 4 05/07/22, 18:02

  2. Nikita Hovratov uploaded patch set 5 05/07/22, 18:04

  3. core-ci voted on patch set 4 V -1 05/07/22, 18:05 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26973

  4. core-ci voted on patch set 5 V -1 05/07/22, 18:07 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26974

  5. Nikita Hovratov uploaded patch set 6 05/07/22, 18:11

  6. core-ci voted on patch set 6 V +1 05/07/22, 18:18 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26975

  7. Simon Schaufelberger voted on patch set 6 CR +1 05/07/22, 18:22

  8. Oliver Klee commented on patch set 6 05/07/22, 19:00

    BackendController.php:213

    I think this is a change of behavior. getWidth and getHeight return integers, which can be 0, in which case the default value of 22 catches.
  9. Nikita Hovratov commented on patch set 6 05/07/22, 19:10

    BackendController.php:213 Reply

    The coalesce operator only works on null. The real question is, can getWidth/getHeight in fact return null.
  10. Nikita Hovratov commented on patch set 6 05/07/22, 19:13

    BackendController.php:213 Reply

    Seems it always returns int. I think we could change it to `?: 22`. What do you think?
  11. Nikita Hovratov uploaded patch set 7 05/07/22, 19:15

  12. Nikita Hovratov commented on patch set 7 05/07/22, 19:15

    BackendController.php:213 Reply

    Done
  13. core-ci voted on patch set 7 V +1 05/07/22, 19:23 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26979

  14. Nikita Hovratov commented on patch set 7 05/08/22, 06:33

    BackendController.php:213 Reply

    Ok, it's not always an int, but can be a string too, if it comes from parsing an IM command. But I don't think null is possible here though, so a ternary check should be the right choice.
  15. crell voted on patch set 7 CR +1 05/09/22, 14:20

  16. Stefan Bürk commented on patch set 7 CR -1 05/11/22, 21:29

    on it ...
  17. Simon Schaufelberger wrote 05/11/22, 21:44

    Removed reviewer Simon Schaufelberger.
  18. Stefan Bürk commented on patch set 7 05/11/22, 23:15

    Clipboard.php:344

    Not sure about this. Even if this makes phpstan happy. ``` BackendUtility::getRecordTitle() ``` There is no native return type, and doc-block return type is string. In the end, it may be not ensured that the return value is really a string. So avoiding ?? '' here may be wrong - Larry, may you have a look to the stated method, should we eventually add there a (string) cast for the return along this or as a prepatch or in combination with a native return-type for the getRecordTitle()? At least for the userFunction call - which is already better.

    BackendController.php:213 Reply

    I would suggest to use here an int cast on the getWidth()/getHeight() and doing the `?: 22` on the casted value. Problem is, through the whole chain, that if imagemagick identify is used, the result may be a string containing the height/width along with an offset in string form. And through the whole chain, this is not handled/casted/mitigated. Fixing the whole chain is out of scope for this patch. Another solution "may" be to add a (int) cast to the method in the ImageInfo class. I would go with the (int) cast in the methods of ImageInfo without adding the return type for now and to keep backportability.

    EditDocumentController.php:2298

    See other comment .. getRecordTitle() needs care too, otherwise I think this cannot be removed (yet).
  19. Stefan Bürk uploaded patch set 8 05/11/22, 23:17

  20. Stefan Bürk commented on patch set 8 05/11/22, 23:18

    Clipboard.php:344 Reply

    Done

    BackendController.php:213 Reply

    Done

    EditDocumentController.php:2298 Reply

    Done
  21. core-ci voted on patch set 8 V +1 05/11/22, 23:25 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27128

  22. Stefan Bürk voted on patch set 8 V +1 CR +1 05/11/22, 23:25

  23. Nikita Hovratov voted on patch set 8 V +1 CR +1 05/13/22, 09:06

  24. Stefan Bürk voted on patch set 8 V +2 CR +2 05/13/22, 17:04

  25. Stefan Bürk merged patch set 9 05/13/22, 17:05