74684[TASK] Resolve PHPStan issues around pointless else clauses
Commit message
Review
-
Code review CR 0
-
Verified V 0
Issues 1
Files 13
- Build/phpstan/phpstan-baseline.neon+1 −56
- typo3/sysext/backend/Classes/Search/LiveSearch/QueryParser.php+1 −6
- typo3/sysext/core/Classes/LinkHandling/LinkService.php2+2 −2
- typo3/sysext/core/Classes/Localization/LanguageService.php+2 −2
- typo3/sysext/core/Classes/Tree/TableConfiguration/DatabaseTreeDataProvider.php+1 −3
- typo3/sysext/core/Classes/Type/File/ImageInfo.php+6 −8
- typo3/sysext/core/Classes/TypoScript/ExtendedTemplateService.php+1 −1
- typo3/sysext/core/Classes/TypoScript/TemplateService.php3+1 −1
- typo3/sysext/core/Classes/Utility/CsvUtility.php+0 −1
- typo3/sysext/extensionmanager/Classes/Utility/InstallUtility.php+0 −1
- typo3/sysext/fluid/Classes/ViewHelpers/Asset/CssViewHelper.php2+1 −1
- typo3/sysext/fluid/Classes/ViewHelpers/Asset/ScriptViewHelper.php2+1 −1
- typo3/sysext/frontend/Classes/Plugin/AbstractPlugin.php2+2 −2
Review log 1417
-
crell uploaded patch set 1 05/18/22, 18:05
-
core-ci voted on patch set 1 V -1 05/18/22, 18:12 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27311
-
crell uploaded patch set 2 05/18/22, 18:16
-
core-ci voted on patch set 2 V +1 05/18/22, 18:23 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27312
-
crell uploaded patch set 3 05/27/22, 15:16
-
core-ci voted on patch set 3 V +1 05/27/22, 15:25 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27499
-
Simon Schaufelberger commented on patch set 3 CR -1 05/29/22, 19:25
please add the generate baseline command here as well. -
Simon Schaufelberger commented on patch set 3 05/29/22, 19:27
LinkService.php:110this looks like a bugfix and should not be part of this patch imho. -
Simon Schaufelberger commented on patch set 3 05/29/22, 19:29
there is much more going on in this patch than just resolving a couple of pointless else clauses. this is not clear. -
Stefan Bürk commented on patch set 3 05/30/22, 05:41
Reply
simplified commit message title is not sufficient. Commit message should be describe the different things of the patch more precise enough / clear enough what this patch intends to do and why ...Reply
ack. ``` Used command(s): > Build/Scripts/runTests.sh -s phpstanGenerateBaseline ```LinkService.php:110ReplyThis change is not a bugfix, it's a simple replacement which is correct.TemplateService.php:170How does this match to "pointless esle clauses" ?CssViewHelper.php:119How does this comply to commit message ? Maybe it's me, but do not get "pointless else clause" matches to adding null coalescing operator (fallback handling) here ?ScriptViewHelper.php:115How does this comply to commit message ? Maybe it's me, but do not get "pointless else clause" matches to adding null coalescing operator (fallback handling) here to avoid not obious "true-branch" of if in L120 ? and more over eventually avoids a array key access error instead ...AbstractPlugin.php:432Not sure about this change, if it is safe to remove the check here. "piVars" is per default an array, but it is not a typed property. Thus not ensured. This check may be here for a good reason. More essential is, that this property is a public property at all - are we really safe to remove this check here ? -
Stefan Bürk voted on patch set 3 CR -1 05/30/22, 05:41
-
crell commented on patch set 3 05/31/22, 15:57
Reply Unresolved
Everything here is to resolve an "unreachable else" PHPStan issue, although not always in the most self-evident way. (See replies on other threads.) Does that need a blow-by-blow of each change in the description and why it works, or something else? (The one exception is the stripos/str_starts_with change, which I don't think is related to an unreachable-else but since we already switched the rest of them over I figured it was a safe straight-swap as long as I was editing the same method already.)Reply
I did not use that command, as it takes 20+ minutes to run and produces the exact same file that already exists. Do you want it included even if it wasn't used? I try to be honest in my commit messages. 😜TemplateService.php:170ReplyEnsuring the property has a default value eliminates the need for the is_array() check in ExtendedTemplateService::getRootLine(). (PHPStan said it was unnecessary because the property is doc-typed array, but technically it defaults to null if no default is set, so moving the default value from the method to the property resolves both.)CssViewHelper.php:119ReplyThis is sort of a workaround to typo3fluid. getAttribute() is doc-typed as returning `string`, but the description says it returns `?string`. That meant PHPStan felt the `$file !== null` check below was unnecessary, when it actually is. The TagBuilder class is not in core, though, but in the typo3fluid vendored package, so I couldn't just correct that here. (It should be corrected there eventually, but that's a separate task.) However, the `$attributes` array is already being requested above (line 112), and then href is removed from it anyway because it's the same piece of data. So just reading off of the array we already have and doing missing-value handling there ourselves resolves the PHPStan issue, is slightly more consistent with what the next line does (the unset() call), and is ever so slightly faster as it skips a method call. (You probably couldn't benchmark the difference, though.) (This one is non-obvious, I agree, but in context I believe it's the best fix.)ScriptViewHelper.php:115ReplySame as the href in CssViewHelper above.AbstractPlugin.php:432Reply UnresolvedIt's doc-typed as an array and has a default. If someone sets it to a non-array, whoever is doing so is already breaking things very badly. I can see the argument for "it's public, so we can't guarantee people won't do dumb things," but if someone sets it to a non-array then a whole lot of things are going to explode anyway. I can back this one out if we want to be extra extra careful, but setting $piVars to a non-array is already violating the API so I wouldn't consider that supported to begin with. (Adding types should be done anyway, though presumably not in this patch.) -
Simon Schaufelberger commented on patch set 3 05/31/22, 16:02
Reply
how did you then update the phpstan baseline file? -
crell commented on patch set 3 05/31/22, 16:16
Reply Unresolved
The process I use for these patches is: * Delete entry from baseline file. * Run the phpstan test suite so it will tell me exactly what line the issue is on. * Change the code as appropriate. * Run unit tests and phpstan to make sure I didn't break anything. * Commit, repeat. Rerunning the baseline generator would just burn 20 minutes to do nothing in most cases. -
Oliver Klee commented on patch set 3 CR -1 05/31/22, 16:45
TemplateService.php:170Reply UnresolvedI'd really prefer to have changes titled like "Add default values to properties in …" or "Add native type types to …", where the removal of the else and the baseline reduction then is a result. (Fixing PHPStan warnings should a side effect of the actual changes, be it bug fixes, cleanup, added native types or type annotation improvements.) Otherwise, if do changes that fix one kind of PHPStan warning in many places, the changes get really unfocused, and also hard to understand and review. -
crell abandoned the change 06/23/22, 17:41
-
Oliver Klee wrote 06/24/22, 16:55
Removed reviewer Oliver Klee with the following votes: * Code-Review-1 by Oliver Klee