69370[BUGFIX] Fix phpstan errors from ReturnTypeRule
Commit message
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
- typo3/sysext/scheduler/Classes/Controller/SchedulerModuleController.php3+2 −2
- typo3/sysext/scheduler/Classes/CronCommand/CronCommand.php3+2 −2
- typo3/sysext/scheduler/Classes/Task/IpAnonymizationAdditionalFieldProvider.php4+2 −3
- typo3/sysext/scheduler/Classes/Task/TableGarbageCollectionAdditionalFieldProvider.php4+3 −4
- typo3/sysext/scheduler/Classes/Scheduler.php+2 −1
- typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateModuleController.php3+2 −5
- typo3/sysext/workspaces/Classes/Domain/Model/DatabaseRecord.php6+3 −5
- typo3/sysext/workspaces/Classes/Domain/Record/StageRecord.php+1 −1
- typo3/sysext/workspaces/Classes/Service/StagesService.php+1 −1
Review log 1416
-
Daniel Goerz uploaded patch set 1 06/03/21, 18:19
-
Daniel Goerz wrote 06/03/21, 18:19
Topic set to phpstan -
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
-
Jochen Roth voted on patch set 1 V +1 CR +1 06/06/21, 13:09
-
Oli Bartsch commented on patch set 1 06/07/21, 08:11
GridDataService.php:697Why do we need this type-cast here? The var is initialized as int and only gets incremented. -
Daniel Goerz commented on patch set 1 06/07/21, 08:13
GridDataService.php:697Replyto be completely honest, I don't know. phpstan kept complaining that this could be a of type float. -
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:1232The 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:227This 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:161Possibly 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:197Ibid.TypoScriptTemplateModuleController.php:601This can be collapsed now to a null-coalesce, methinks.DatabaseRecord.php:39Can we just use a property type here instead of a doc type?DatabaseRecord.php:156This can also use null-coallesce assign. $this->row ??= ...GridDataService.php:697ReplyTheory: 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.) -
Markus Klösges commented on patch set 1 06/07/21, 19:35
IpAnonymizationAdditionalFieldProvider.php:161ReplyI 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 boolDatabaseRecord.php:39ReplyWe can't without making that change breaking, or am I mistaken?GridDataService.php:697ReplyThis 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 -
Daniel Goerz commented on patch set 1 CR -1 06/07/21, 20:34
Will update the patch tomorrowSchedulerModuleController.php:1232ReplyI'll revisit tomorrowCronCommand.php:227ReplyI'll revisit tomorrowIpAnonymizationAdditionalFieldProvider.php:161Replystan 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:197ReplyIbid. Also, what does Ibid stand for? :)TypoScriptTemplateModuleController.php:601ReplyGood catch. Will update the patch.DatabaseRecord.php:156ReplyGood catch. Will update the patch.GridDataService.php:697Replycool, then we should ignore the error until it is fixed upstream. -
crell commented on patch set 1 06/07/21, 22:32
TableGarbageCollectionAdditionalFieldProvider.php:197Reply"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." :) -
Daniel Goerz uploaded patch set 2 06/11/21, 14:38
-
Daniel Goerz commented on patch set 2 06/11/21, 14:41
SchedulerModuleController.php:1232Reply UnresolvedI 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:227ReplyDoneIpAnonymizationAdditionalFieldProvider.php:161ReplyDoneTableGarbageCollectionAdditionalFieldProvider.php:197ReplyDoneTypoScriptTemplateModuleController.php:601ReplyDoneDatabaseRecord.php:39ReplyDoneDatabaseRecord.php:156ReplyDoneGridDataService.php:697ReplyDone -
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
-
Alexander Schnitzler voted on patch set 2 V +1 CR +1 06/17/21, 12:01
-
Oli Bartsch voted on patch set 2 V +2 CR +2 06/17/21, 13:00
-
Oli Bartsch merged patch set 3 06/17/21, 13:00