Review main Merged

69370[BUGFIX] Fix phpstan errors from ReturnTypeRule

Daniel Goerz CR +2 V +2 Easy +18 −24 updated 06/17/21, 13:00

Commit message

EXT:scheduler
EXT:tstemplate
EXT:workspaces

Review

  • Code review CR +2 Done
    • Oli Bartsch +2
    • Alexander Schnitzler +1
  • Verified V +2 Done
    • Oli Bartsch +2
    • Alexander Schnitzler +1
    • core-ci +1 CI

Issues 1

Files 9

Review log 1416

  1. Daniel Goerz uploaded patch set 1 06/03/21, 18:19

  2. Daniel Goerz wrote 06/03/21, 18:19

    Topic set to phpstan
  3. core-ci voted on patch set 1 V +1 06/03/21, 18:30 Core CI is happy: https://gitlab.typo3.org/TYPO3/CI/cms/-/pipelines/12144

  4. Jochen Roth voted on patch set 1 V +1 CR +1 06/06/21, 13:09

  5. Oli Bartsch commented on patch set 1 06/07/21, 08:11

    GridDataService.php:697

    Why do we need this type-cast here? The var is initialized as int and only gets incremented.
  6. Daniel Goerz commented on patch set 1 06/07/21, 08:13

    GridDataService.php:697 Reply

    to be completely honest, I don't know. phpstan kept complaining that this could be a of type float.
  7. crell commented on patch set 1 06/07/21, 17:52

    I think several of these could be done in a more elegant way. Adding more explicit return types in the code would probably help phpstan to realize the code is OK. 😊

    SchedulerModuleController.php:1232

    The goal here is to normalize the timestamp to UTC, I presume? If so, skip this and just set the timezone on the DateTime object, then generate the timezone off of that. Always assume your date math is wrong if done manually. :)

    CronCommand.php:227

    This whole thing can be simplified to `floor($timestamp/60)*60`. That's even better, and typesafe as long as $timestamp is an int, as specified. (Can we go ahead and add that type check?)

    IpAnonymizationAdditionalFieldProvider.php:161

    Possibly better approach: return $this->validateTableAdditionalField($submittedData, $schedulerModule) && $this->validateNumberOfDaysAdditionalField($submittedData, $schedulerModule) I'm not sure what phpstan is complaining about here, but that would get the same result without an intermediate variable and guarantee a boolean return. And then the method can/should be typed to return bool, as well.

    TableGarbageCollectionAdditionalFieldProvider.php:197

    Ibid.

    TypoScriptTemplateModuleController.php:601

    This can be collapsed now to a null-coalesce, methinks.

    DatabaseRecord.php:39

    Can we just use a property type here instead of a doc type?

    DatabaseRecord.php:156

    This can also use null-coallesce assign. $this->row ??= ...

    GridDataService.php:697 Reply

    Theory: Break up the `$recordCount = $parentRecordsCount = 0` line at the start into multiple assignments? It may be confused by that and thinking that $parentRecordCount might be a float and then it's not sure what to do. (It's an uncommon pattern, so it's possible that phpstan doesn't know how to read it properly.)
  8. Markus Klösges commented on patch set 1 06/07/21, 19:35

    IpAnonymizationAdditionalFieldProvider.php:161 Reply

    I think the type might be widened to int by the bitwise operator here. I agree, that the explicit && notation would make things clearer here than casting to bool

    DatabaseRecord.php:39 Reply

    We can't without making that change breaking, or am I mistaken?

    GridDataService.php:697 Reply

    This is indeed a phpstan bug. Was able to build a minimal reproducing example and submitted upstream: https://github.com/phpstan/phpstan/issues/5147 the combination of by-ref call and post-increment fools phpstan somehow. I would suggest to reference the github issue in a comment explaining the type-cast? But even if we don't, phpstan will complain about the unneccessary cast whenever it gets the correct understanding of the code
  9. Daniel Goerz commented on patch set 1 CR -1 06/07/21, 20:34

    Will update the patch tomorrow

    SchedulerModuleController.php:1232 Reply

    I'll revisit tomorrow

    CronCommand.php:227 Reply

    I'll revisit tomorrow

    IpAnonymizationAdditionalFieldProvider.php:161 Reply

    stan complains about this method returning an integer while promising a boolen (as does the interface). I thought about using && instead of the bool cast and went with the "change less code" approach. But tbh I also like it better, lets change it.

    TableGarbageCollectionAdditionalFieldProvider.php:197 Reply

    Ibid. Also, what does Ibid stand for? :)

    TypoScriptTemplateModuleController.php:601 Reply

    Good catch. Will update the patch.

    DatabaseRecord.php:156 Reply

    Good catch. Will update the patch.

    GridDataService.php:697 Reply

    cool, then we should ignore the error until it is fixed upstream.
  10. crell commented on patch set 1 06/07/21, 22:32

    TableGarbageCollectionAdditionalFieldProvider.php:197 Reply

    "Ibid. is an abbreviation for the Latin word ibīdem, meaning "in the same place", commonly used in an endnote, footnote, bibliography citation, or scholarly reference to refer to the source cited in the preceding note or list item." - Wikipedia. In this case, "that thing I said on a previous comment I'm saying here, too." :)
  11. Daniel Goerz uploaded patch set 2 06/11/21, 14:38

  12. Daniel Goerz commented on patch set 2 06/11/21, 14:41

    SchedulerModuleController.php:1232 Reply Unresolved

    I left this as is to not have too much refactoring going into this patch. This could be revisited in a separate patch that adds unit tests as well as this is untested.

    CronCommand.php:227 Reply

    Done

    IpAnonymizationAdditionalFieldProvider.php:161 Reply

    Done

    TableGarbageCollectionAdditionalFieldProvider.php:197 Reply

    Done

    TypoScriptTemplateModuleController.php:601 Reply

    Done

    DatabaseRecord.php:39 Reply

    Done

    DatabaseRecord.php:156 Reply

    Done

    GridDataService.php:697 Reply

    Done
  13. core-ci voted on patch set 2 V +1 06/11/21, 14:48 Core CI is happy: https://gitlab.typo3.org/TYPO3/CI/cms/-/pipelines/12306

  14. Alexander Schnitzler voted on patch set 2 V +1 CR +1 06/17/21, 12:01

  15. Oli Bartsch voted on patch set 2 V +2 CR +2 06/17/21, 13:00

  16. Oli Bartsch merged patch set 3 06/17/21, 13:00