74378[TASK] Resolve "right side of && is always true" in PHPStan
Commit message
Review
-
Code review CR +2 Done
- Nikita Hovratov +2
- Oliver Klee +1
-
Verified V +2 Done
- Nikita Hovratov +2
- Oliver Klee +1
- core-ci +1 CI
Issues 1
Files 9
- Build/phpstan/phpstan-baseline.neon+0 −40
- typo3/sysext/backend/Classes/Form/Element/SelectTreeElement.php21+1 −1
- typo3/sysext/core/Classes/Crypto/PasswordHashing/BcryptPasswordHash.php2+0 −1
- typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php+16 −18
- typo3/sysext/core/Classes/LinkHandling/LinkService.php11+2 −2
- typo3/sysext/core/Classes/Mail/MemorySpool.php2+1 −1
- typo3/sysext/core/Classes/Resource/ResourceCompressor.php+1 −1
- typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbQueryParser.php4+1 −1
- typo3/sysext/extbase/Classes/Persistence/Generic/LazyLoadingProxy.php14+1 −1
Review log 4351
Show 2226 earlier messages
-
crell uploaded patch set 1 04/22/22, 23:01
-
core-ci voted on patch set 1 V +1 04/22/22, 23:09 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26330
-
Stefan Bürk commented on patch set 1 CR -1 04/23/22, 10:29
-1 because of some changes in behaviourSelectTreeElement.php:96Are you aware that this drastically changes the behaviour and that your replacement fully drops the fallback to a default value ?LinkService.php:47We could think about using ``` array<string, LinkHandlingInterface> ``` here to be more precise - as we are working on this property.LinkService.php:110Change of behaviour. This will not match anylonger if ``` $urn = 'T3://' ``` Not sure if it is save to change the behaviour in this way here. Would suggest keep the stripos() variant for now.LazyLoadingProxy.php:46Should we really mix CPP with non promoted parameter handling ?Typo3DbQueryParser.php:727What's the benefit of this change ? It make the code not clearer, it do not fix anything. New code introduces more to think about and understand, which was not really needed in the old variant. -
Oliver Klee commented on patch set 1 04/24/22, 11:50
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) -
Oliver Klee voted on patch set 1 CR -1 04/24/22, 11:51
-
crell commented on patch set 1 04/25/22, 14:42
Reply
Not all of this is backportable, as the new code is often using PHP 8+ syntax. I wasn't planning on backporting these, as they're style fixes, not bug fixes, so no sense disrupting an LTS. Some of the type changes in this and the other patch are related to the PHPStan cleanup. It made sense to me to follow the campground rule (always leave it cleaner than you found it) and do the easy types that were adjacent to areas I was already messing with.SelectTreeElement.php:96ReplyHrm. I confused $itemsToShow and $minItemsToShow. The names were too similar. :-/ Will adjust.LinkService.php:110ReplyThat's what the strtolower() call is for. https://3v4l.org/TVse6 str_starts_with() has no case-insensitive variant precisely because using strtolower() like this is logically equivalent.LazyLoadingProxy.php:46ReplyI don't see an issue with it, personally. Especially when it's not all CPP only because makeIntance() doesn't work in the signature directly. (`new` calls do, and I've used that in the past as well.)Typo3DbQueryParser.php:727ReplyThe old code was logically redundant, which PHPStan was objecting to. In particular, the final elseif clause I think is what was triggering it. ($includeDeleted is logically always true at that point, so redundant.) Early returns for error cases and fence posting is a very common technique, and works quite well here. Once I did that, my IDE just auto-recommended the rest. I actually had a really hard time following the nested conditionals in the original code. If the ($ignoreEnabledFields && !$includeDeleted) case were single line, I'd say the cleanest and most readable would be to switch to a multi-element match(). (cf: https://peakd.com/hive-168588/@crell/php-tricks-multi-value-match). If we can refactor that block to its own function, that would work well here, but I wasn't sure if that was too aggressive. If you think that's reasonable to do I can try the match() version, which should give the "lookup table" effect the old code was attempting to do, but IMO failing at. -
Oliver Klee commented on patch set 1 04/25/22, 14:58
Reply
Let me rephrase: I'll gladly review the two changesets if they're separated like I suggested, and I'm not willing to review if both things are mixed together (but I won't stand in your way in that case). -
crell uploaded patch set 2 04/25/22, 15:11
-
crell commented on patch set 2 04/25/22, 15:11
Reply
AckSelectTreeElement.php:96ReplyDoneLinkService.php:47ReplyDone -
core-ci voted on patch set 2 V +1 04/25/22, 15:24 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26404
-
Nikita Hovratov commented on patch set 2 CR -1 04/25/22, 15:55
SelectTreeElement.php:88The int casting is missing here now.LazyLoadingProxy.php:56Are you sure always an object is returned here? The comment states "hopefully". Also the __call method does not check for object without a reason. This needs to be carefully verified, that this is not a problem anymore.Typo3DbQueryParser.php:727ReplyThe refactoring looks fine to me, although I would prefer a separate patch to keep reviews as easy as possible. But you don't need to change it now. -
Stefan Bürk commented on patch set 2 CR -1 04/25/22, 17:02
SelectTreeElement.php:55Extensions / project extensions may extend SelectTreeElement as base for custom select render type. Also this properpy can be set per tca configuration, they may have for e.g. "protected $itemsToShow = 30;" set - which will be hard breaking now. See: https://3v4l.org/Sprt9 So patch has to be marked as breaking, and include or amend to a corresponding breaking ReST.SelectTreeElement.php:61Extensions / project extensions may extend SelectTreeElement as base for custom select render type. This is breaking if they have overriden this property without type hint, e.g. "protected $minItemsToShow = 10;". See: https://3v4l.org/Sprt9 So patch has to be marked as breaking, and include or amend to a corresponding breaking ReST.SelectTreeElement.php:66Same as the two property above. Breaking.Typo3DbQueryParser.php:727ReplyDone -
crell commented on patch set 2 04/26/22, 18:23
SelectTreeElement.php:55ReplyDo you think these should go in the same type-changes RST as we're already building up, or a separate one for each class, or...? I'm flexible here.SelectTreeElement.php:88ReplyUgh. Looks like max() takes mixed args, but will then return the value in the same type that it received it rather than converting to a number. What fresh hell is this, PHP? I will adjust.LazyLoadingProxy.php:56ReplyI checked all places this method is called from and the places it calls; the current logic is horribly inconsistent; some places check the return value with is_object(), most don't. The two methods it calls to get its return value are both `return mixed`. So... honestly the docblock is just wrong here, or rather "hopefully" is carrying a lot of weight. :-) For simplicity I'll back out this change for now. We'll fry this fish later. -
crell uploaded patch set 3 04/26/22, 20:29
-
core-ci voted on patch set 3 V +1 04/26/22, 20:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26478
-
Benni Mack commented on patch set 3 04/27/22, 10:21
LinkService.php:49I think we should initialize with an empty array? otherwise $this->handlers isn't for sure an array as the constructor _might_ populate it, but doesn't for sure populate it. -
Oli Bartsch commented on patch set 3 04/27/22, 10:54
SelectTreeElement.php:88That's a change in behaviour, see https://3v4l.org/Un06MLinkService.php:134isset seems to be a change in behaviour, since the value could still be NULL. IMO this should be "$this->handlers[self::TYPE_EMAIL] ?? false" instead.LazyLoadingProxy.php:42If I remember correct, we agreed to only use property promotion when the full argument block can use it. Additionally I'm missing the property descriptions now, which were given in the corresponding PHPdoc's.LazyLoadingProxy.php:93This will fail in case $this->_loadRealInstance() does not return an object. The corresponding check IMO needs to be keep. -
Stefan Bürk commented on patch set 3 04/27/22, 14:04
LinkService.php:134Replyisset() returns false for null, so not really a change in behaviour. However ?? is broader known for "not set or null" than "isset()" -
Stefan Bürk commented on patch set 3 04/27/22, 14:05
LinkService.php:134Reply -
Oli Bartsch commented on patch set 3 04/27/22, 15:54
LinkService.php:134ReplyYes you are right. -
Stefan Bürk commented on patch set 3 04/27/22, 16:05
SelectTreeElement.php:55Reply> So patch has to be marked as breaking, and include or amend to a corresponding breaking ReST. ... include (a new file) or amend a existing one ... -
Stefan Bürk commented on patch set 3 04/27/22, 16:09
-
crell commented on patch set 3 04/27/22, 16:24
SelectTreeElement.php:55ReplyOh, I was smart and mentioned properties in the title there after all. :-) It looks like it can be added there without colliding with any other in-flight patches, so will do so directly.SelectTreeElement.php:61ReplyDoneSelectTreeElement.php:66ReplyDoneSelectTreeElement.php:88ReplySigh. Who in their right mind sets size to a negative number??? :-PLinkService.php:49ReplyDoneLinkService.php:134ReplyI was trying to avoid issues with the priority order of ?? being so low, but it ends up being the same number of parentheses either way, so meh.LazyLoadingProxy.php:42ReplyIs that documented anywhere? I know it's been discussed around channel somewhat, but I don't recall a formal decision being made. I see no reason to triple the work/LOC because a single property needs one extra line of default handling. Also, the descriptions are same (give or take wording) as what's in the constructor docblock; I believe PHPStorm is smart enough to connect the two as being the same. If any other tools aren't, that's a bug in those tools that should be corrected.LazyLoadingProxy.php:93ReplyLeftover from when it seemed _loadRealInstance() was safe to type as :object. Will adjust. -
crell uploaded patch set 4 04/27/22, 16:24
-
Stefan Bürk commented on patch set 4 04/27/22, 16:25
SelectTreeElement.php:55Replywrong. I added and changed that for the property in the other patch. -
core-ci voted on patch set 4 V +1 04/27/22, 16:37 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26529
-
Oliver Klee commented on patch set 4 04/27/22, 16:42
SelectTreeElement.php:88Generally no conditions in conditions, please (with the exception of loops over DB results, where this is very hard to avoid). Instead, please let's put assign the variable first and have the condition in the next statement. -
crell commented on patch set 4 04/27/22, 17:06
SelectTreeElement.php:88ReplyAck -
crell uploaded patch set 5 04/27/22, 17:06
-
core-ci voted on patch set 5 V +1 04/27/22, 17:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26531
-
Oliver Hader commented on patch set 5 CR -1 05/02/22, 15:28
SelectTreeElement.php:82Would `!empty($config['readOnly'])` have been enough? Now `$readOnly` is of type mixed oder false, previously it has been a booleanBcryptPasswordHash.php:78So, PASSWORD_BCRYPT can be empty now?MemorySpool.php:97This seems to be wrong, and would unshift the null-messageLazyLoadingProxy.php:46What about using something like this? ``` ... private ?DataMapper $dataMapper = null, ) { $this->dataMapper ??= GeneralUtility::makeInstance(DataMapper::class); } ```LazyLoadingProxy.php:93superfluous spaceLazyLoadingProxy.php:157What about implementing `Stringable` interface? -
crell commented on patch set 5 05/02/22, 17:01
SelectTreeElement.php:82ReplyI think you are correct. Will adjust.BcryptPasswordHash.php:78ReplyPASSWORD_BCRYPT is either not defined (thus the defined() call will already return false) or has the value `2y`, which is truthy. Thus the truthiness check is redundant.MemorySpool.php:97ReplyThe exception cannot be thrown by `$message = array_pop(...)`. If $message is not a real value after that statement, the `while()` will terminate on its own. The only place that exception could be thrown is `$transport->send()`, which will only be reached if `$message` is truthy. Thus `$message` is always truthy on this line, and the check is redundant.LazyLoadingProxy.php:46ReplyThat would *technically* make it type-legal for $this->dataMapper to have a null value, even if it wouldn't happen in practice. I just tested and it looks like neither phpstan nor PHPStorm complain about the potential null value, so either they're particularly smart or particularly dumb. 😊 Either way, I can roll with that so will change.LazyLoadingProxy.php:93ReplyAckLazyLoadingProxy.php:157ReplyAck -
crell uploaded patch set 6 05/02/22, 17:02
-
Oliver Klee wrote 05/02/22, 17:08
Removed reviewer Oliver Klee. -
core-ci voted on patch set 6 V +1 05/02/22, 17:13 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26740
-
Oliver Hader wrote 05/06/22, 21:39
Removed reviewer Oliver Hader. -
Nikita Hovratov commented on patch set 6 05/07/22, 12:37
Honestly, let's split this patch into the non-breaking phpstan stuff and the breaking changed method signature stuff. -
Stefan Bürk wrote 05/07/22, 12:38
Removed reviewer Stefan Bürk. -
Oliver Klee commented on patch set 6 05/07/22, 12:48
Reply
For that case, my offer of reviewing the changes still stands. -
Oliver Klee wrote 05/07/22, 12:48
Removed cc Oliver Klee. -
Nikita Hovratov uploaded patch set 7 05/07/22, 16:33
-
Nikita Hovratov updated the commit message in patch set 8 05/07/22, 16:33
-
Oliver Klee voted on patch set 8 CR +1 05/07/22, 16:39
-
Oliver Klee updated the commit message in patch set 9 05/07/22, 16:41
-
Oliver Klee voted on patch set 9 CR +1 05/07/22, 16:41
-
core-ci voted on patch set 8 V +1 05/07/22, 16:41 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26966
-
Nikita Hovratov voted on patch set 9 V +1 CR +1 05/07/22, 16:45
-
core-ci voted on patch set 9 V +1 05/07/22, 16:48 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26967
-
Oliver Klee voted on patch set 9 V +1 05/07/22, 16:49
-
Nikita Hovratov voted on patch set 9 V +2 CR +2 05/07/22, 16:53
-
Nikita Hovratov merged patch set 10 05/07/22, 16:53