74583[BUGFIX] Resolve access to undefined property PHPStan warnings
Commit message
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 7
- Build/phpstan/phpstan-baseline.neon8+0 −40
- typo3/sysext/backend/Classes/ViewHelpers/ArrayBrowserViewHelper.php+0 −1
- typo3/sysext/core/Classes/Database/Schema/Parser/Parser.php+1 −1
- typo3/sysext/core/Classes/Utility/GeneralUtility.php18+11 −2
- typo3/sysext/core/Tests/Unit/Configuration/Parser/PageTsConfigParserTest.php8+1 −0
- typo3/sysext/indexed_search/Classes/Utility/DoubleMetaPhoneUtility.php+4 −0
- typo3/sysext/install/Classes/ExtensionScanner/Php/Matcher/ConstructorArgumentMatcher.php+10 −10
Review log 4560
Show 2635 earlier messages
-
crell uploaded patch set 1 05/09/22, 18:58
-
core-ci voted on patch set 1 V -1 05/09/22, 19:47 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27048
-
core-ci commented on patch set 1 05/09/22, 20:51 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27048
-
Oliver Klee commented on patch set 1 CR -1 05/09/22, 22:06
GeneralUtility.php:3216Generally, please do not mix breaking changes (adding type declaration, which we cannot backport) with PHPStan fixes (which we can backport).GeneralUtility.php:3228Let's use the magic of the makeInstance annotation here instead: /** @var class-string<AbstractAuthenticationService> $className */ $className = $info['className']; $obj = self::makeInstance($info['className']);PageTsConfigParserTest.php:47Please do not add PHPStan ignores to production code. -
Stefan Bürk commented on patch set 1 CR -1 05/10/22, 11:29
phpstan-baseline.neon:4298ReplyCorrect. Will add a baseline check to ci to fail if someone will edit the baseline by hand. This integration check is missing. > Build/Scripts/runTests.sh -s phpstanGenerateBaseline should be used and also meantioned as used command in the commit message (no hard rule, but it's a lived practice )GeneralUtility.php:3216Simply adding types/return types based on docblock's does not make any sense. It *must* be checked if the docblock eventually is not correct. Docblock do not crash or throw erros in running code, types/return types may/will be. Missed to add `false` as return type possibillity: ``` :array|object|false ``` or change the code that it is ensured that never ever a false can be returned.GeneralUtility.php:3216ReplyAck.GeneralUtility.php:3228ReplyMaybe this is "good" for phpstan, but it destroyes the autocompletion for e.g. PHPStorm. (If the @var is a replacement for the current one). $obj-> ... will not display proper autocompletion for AbstractAuthenticatioService Not sure if this can be mitigated along by extending/adjusting the phpstorm metadata file. We should not break phpstorm here, so we need a solution which works for both. And do not get the benefit for provided change example, so would it leave it as is OR find a solution which has the benefit (not known for me right know) and do not breaking phpstorm autocompletion.PageTsConfigParserTest.php:47ReplyThis is test code and not production code. But ack, using phpstan ignore line is not a solution here. @Larry It's not the goal to "simply" get get the baseline "empty". It's not a race. It's a utility to increase the quality properly. Thus things should be fixed properly and removed from baseline OR staying there until they are fixed or fixable (deprecation=>new feature, refactoring, etc....) For core we only use phpstan ignore lines for explicitly broken code which has to be tested (texting broken code fpr extbase things etc) if not excluded with a proper comment in the phpstan configuration at all. Simply fix here would be to use a proper annotation instead of the ignore line: ``` /** @var TypoScriptParser $this */ ``` Using the extending version with a "local" variable would be possible, but I think unneded: ``` /** @var TypoScriptParser $that */ $that = $this; $that->setup = $expectedParsedTsConfig; ``` -
crell commented on patch set 1 05/10/22, 14:38
phpstan-baseline.neon:4298ReplyHow should information be documented for why a given baseline exception is in place then?GeneralUtility.php:3216ReplyI scanned the code visually and did not see any way for false to be returned, even though that's the initial default value for $error. Unit tests also had no issue with this return type, although PHPStorm wants to auto-generate a |false. I suspect it's a false-positive (no pun intended) from PHPStorm, and a false return is not actually possible, but if you can point out where a false is also possible return I will update the patch.GeneralUtility.php:3228ReplyIn this case, adding the @var declaration was also picked up by phpstan, which eliminated the need for the "property not defined" exclusion rule on line 3231. I can experiment and see if we can include both the basic and more-advanced annotations to keep both tools happy. If not, the current @var may not be fully robust but it has the desired effect in both tools.PageTsConfigParserTest.php:47ReplyI've been told in the past to use ignore-next-line for some other exclusions (in particular where PHPStan is needlessly over-aggressive, and exclusions are the only way to disable it). Is there a policy actually documented somewhere? I'll try the suggested annotations and see if they resolve these cases. -
crell commented on patch set 1 05/10/22, 14:45
AbstractCompositeValidator.php:56This change is causing test fails, which doesn't surprise me as the fix is probably wrong. I don't fully understand the context here. ValidatorInterface obviously has no properties, but it does have a method of the exact same name. This is apparently causing an error as sometimes $this->validatedInstanceContainer() is null, which the method doesn't accept. Does someone who knows the context better have a better suggestion for what to do here? -
Stefan Bürk commented on patch set 1 05/10/22, 15:02
phpstan-baseline.neon:4298Replycomment it at the code place where this happens with a simple comment stating that this leads to an baseline entry but cannot be solved currently.GeneralUtility.php:3216Reply`findService()` may return false. thus return here $error = false. Even if it most unlikely that a instance is configured in a way that it boils down to the false default, it may be possible. So either add the return of it or change the code that it never be false. Which is currently not guaranteed. If no t3_services are registered for a specific service type, it may return false in the corrent code state, for example.GeneralUtility.php:3228Replyin the end .. using the abstract authentication service anotinan here is sa specific case at all ... as it may be other services. So not sure about that at all.PageTsConfigParserTest.php:47ReplyIt's not a good way to use phpstan ignore line to remove a entry of the baseline. Not sure who told you that. It should not be used to silence something or remove it, only because it cannot be refactored or properly fixed right now. Than it stays in the baseline. That's what the baseline is for. phpstan ignore annotion may only be used if there is a rare case in tests which explictly tests for violations or broken code. And if using a full ignore/not scan through the configuration, as it os only a part in a file and the rest should be scanned, than it *may* be used. Using phpstan ignore lines in code will spread this through the core instead of having one place where all "issues" which are marked as "we know this is wrong, but it's okay for now" - instead of scanning/grepping the core for doizens of phpstan ignore lines. I'm not ware of a really official statement. But this was the working operandi which Christian Kuhn, Oliver Klee and myself came about when we reworked the phpstan configuration and how it should be used for core development. Starting with rule disabling and transplantation or these ignore lines will make this tool useless, manual rule management and we could remove it at all. Besides this, it also an easier workflow management for patch backportings. -
crell commented on patch set 1 05/10/22, 15:57
phpstan-baseline.neon:4298ReplyAckGeneralUtility.php:3228ReplyI checked and this does work: /** @var class-string<AbstractAuthenticationService> $className */ $className = $info['className']; /** @var AbstractAuthenticationService $obj */ $obj = self::makeInstance($info['className']); Though I won't say I actually like it. Just the basic @var keeps both tools happy. That said, I've been told that in core it's always going to be AbstractAuthenticationService, but you're right, extensions could theoretically do whatever. If we skip any annotation here and bring back the baseline entry along with an inline comment explaining the legacy lack of interface, that would keep PHPStan happy and be technically more accurate, but PHPStorm would continue to complain. I'm not sure what the best tradeoff here is.PageTsConfigParserTest.php:47ReplyDone -
crell commented on patch set 1 05/10/22, 22:42
GeneralUtility.php:3216ReplyIn many cases, the fix for PHPStan is to properly include types, which render code that PHPStan is complaining about unnecessary and deletable. -
crell uploaded patch set 2 05/10/22, 22:43
-
core-ci voted on patch set 2 V -1 05/10/22, 23:14 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27105
-
core-ci commented on patch set 2 05/11/22, 00:00 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27105
-
Stefan Bürk commented on patch set 2 05/11/22, 00:40
AbstractCompositeValidator.php:56ReplyNo context/knowlege here. But from 5 minute finding the patch introducing this, reading the todo and the patch at all, I would say this was some kind of compatibility layer if flow was used. Never used flow or followed that project, if this is still possible/active for Typo3 or if it has shifted to neos only. Maybe Alexander Schnitzler may have more information about this, as he backported that stuff. See: https://review.typo3.org/c/Packages/TYPO3.CMS/+/21428 Either removing this condition/todo-block at all or extending the condition may be usefull: ``` if ($validator instanceof ObjectValidatorInterface && isset($this->validatedInstancesContainer) ) { // @todo: provide bugfix as soon as it is fixed in TYPO3.Flow // ... (https://forge.typo3.org/issues/48093) $validator->setValidatedInstancesContainer($this->validatedInstancesContainer); } ``` ^ comment splitted for this commet, should stay one line The issue is, it could be set the property as null or a validated instance container if it exists. Changing this to the method, which is strict typed as non-nullable this fails then. To avoid another phpstan message, docblock type of the property should contain "|null" as type hint: ``` /** * @var \SplObjectStorage|null * @todo: It's unclear if this is always correctly initialized. */ protected $validatedInstancesContainer; ``` So three possibilites to process further on here: * avoid setting/calling the seter if $this->validatedInstancesContainer is not set * remove it (if this is possible because of flow and no longer needed as workaround) * leave it as it is without changing it (with the corrsponding ignore pattern in phpstan baseline file) But take this as a comment to kickstart and bringing you on track and not to give you a finished solution. Work that out yourself with furter investigations, as this was a quick shot. * maybe doing something else then the isset() check/improve it further etc .... -
Stefan Bürk uploaded patch set 3 05/11/22, 00:42
-
core-ci voted on patch set 3 V +1 05/11/22, 00:49 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27107
-
Stefan Bürk uploaded patch set 4 05/11/22, 01:10
-
Stefan Bürk commented on patch set 4 05/11/22, 01:11
phpstan-baseline.neon:4298ReplyIn the end, the comment was wrong any way. There is a solution to handle this and remove (solve!!) these kinds from the baseline. See ConstructorArgumentMatcher .... -
Stefan Bürk commented on patch set 4 05/11/22, 01:16
And again. Please try to separate these kind of changes in dedicated patches. It grows to "properly" solve similar error messages, but needs different approaches and solutions. Making it harder to properly reviewe, and in case of a regression eventually reverted completly instead of smaller areas. Additionally, as already meantioned .. some solutions should be backported to v11 already which may help project/extensiond developers. So first patch should be a backportable change, with a follup for native types which are not backportable. -
core-ci voted on patch set 4 V +1 05/11/22, 01:19 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27109
-
Stefan Bürk commented on patch set 4 05/11/22, 21:12
Reply
Okay. Let's do this patch in one go. Talked with Larry, he will try to split this more in the future.phpstan-baseline.neon:4298ReplyDoneGeneralUtility.php:3216ReplyDoneGeneralUtility.php:3228ReplyI pushed a variant having both annotations. That way phpstan and phpstorm is happy.AbstractCompositeValidator.php:56ReplyDone -
Stefan Bürk commented on patch set 4 V +1 CR +1 05/11/22, 23:42
Reply
Done -
Oli Bartsch commented on patch set 4 CR -1 05/12/22, 21:02
GeneralUtility.php:3216Since this is a public method, this seems to be a breaking change.AbstractCompositeValidator.php:55Is this todo resolved? Issue is still open. Anyways this seems to be a change in behaviour, so could this please be covered by a test? -
Stefan Bürk voted on patch set 4 V 0 CR 0 05/12/22, 21:38
-
Stefan Bürk commented on patch set 4 05/12/22, 22:51
AbstractCompositeValidator.php:55ReplyCould we take the fact, that without this change the tests are going badly on the ground when simply using the setter method? Will run a test endlessly without ending (except running into 30min ci job limit). No, that's satisfying. But how to write a test for it without further understanding ? Tried to get into this ... ------------------- I don't get this at all. there is no code in the validators accessing the "dynamiclly" set property.. typo3/flow packages has been abandoned on packagist, neos.flow "should" be used. Looking into the actual code of that, which has the same classes which has been backporterted, it has the exact same code (without the todo): https://github.com/neos/flow/blob/1af9a29aa1742c088da180bd7942971fb59113a7/Classes/Validation/Validator/AbstractCompositeValidator.php#L106 But also, even there it make no sense - there is no validator implementing this ObjectValidatorInterface AND having the property `setValidatedInstancesContainer` definied OR read/write access to it. See grep through the neos.flow code: ``` $ ack 'setValidatedInstancesContainer' Classes/Persistence/Doctrine/ObjectValidationAndDeDuplicationListener.php 124: $validator->setValidatedInstancesContainer($validatedInstancesContainer); Classes/Validation/Validator/ObjectValidatorInterface.php 28: public function setValidatedInstancesContainer(\SplObjectStorage $validatedInstancesContainer); Classes/Validation/Validator/GenericObjectValidator.php 49: public function setValidatedInstancesContainer(\SplObjectStorage $validatedInstancesContainer) 143: $validator->setValidatedInstancesContainer($this->validatedInstancesContainer); Classes/Validation/Validator/AbstractCompositeValidator.php 91: public function setValidatedInstancesContainer(\SplObjectStorage $validatedInstancesContainer) 106: $validator->setValidatedInstancesContainer = $this->validatedInstancesContainer; Classes/Validation/Validator/CollectionValidator.php 75: $collectionElementValidator->setValidatedInstancesContainer($this->validatedInstancesContainer); Documentation/TheDefinitiveGuide/PartIII/Validation.rst 386:can be (re-)set using ``setValidatedInstancesContainer`` defined in the ``ObjectValidatorInterface``. ``` I can only guess - maybe this is some kind of really old uncommented fallback code or something in the direction that the property should be this because of the public setter method 'setValidatedInstancesContainer()` - which does not match in the implementation, neighter in typo3/neos.flow nor in the backported stuff into the core. Could not find any issue on neos (monorepo) -> https://github.com/neos/flow-development-collection https://github.com/neos/flow-development-collection/search?q=setValidatedInstancesContainer Monorepo itself uses the public/interface method to set these thinks, however they have a psaml baseline entry this dynamically property set code: https://github.com/neos/flow-development-collection/blob/b2b623ba8f6d810019743ec6aaee6e3862eeecd5/psalm-baseline.xml#L2549 Not much into the psalm stuff, but I would guess this is the equialent to the phpstan baseline - silencing this. Maybe we could open an Issue there first asking for the backround of this code. Also reading the "writing a validator" in the neos packages do not mention this propery at all, only the public method. However, using the method instead will let the functional test not finishing. On some tests it's running endless (in core ci failing after 30 minutes because of pipeline/job limit). Thus my intention to only set it if the validator container is set to avoid passing "null" to a method without nullable method argument. Writing tests for this "change" is hard - as not understanding the background at all. We *could* assume that the test runs trough with the isset() hack as "test" coverage. But withoud correct understanding the background about this dynamically property setting is hard to tell anything. Not sure who has more insight in this whole flow topic here and real knowledge. How should we proceed here further ? @crell may it be fine for you to create a corresponding issue on the neos repository asking about it ? Otherwise I will try to do that tommorrow after work/at the weekend. Side-node: removing this if block still makes tests happy. -
crell uploaded patch set 5 05/13/22, 18:40
-
crell commented on patch set 4 05/13/22, 18:41
Rerolled. I also removed the Flow-based fix because that's a rabbit hole that should not block the rest of the patch. We can deal with it another time.phpstan-baseline.neon:4298ReplyAckAbstractCompositeValidator.php:55ReplyDone -
crell uploaded patch set 6 05/13/22, 18:43
-
core-ci voted on patch set 5 V +1 05/13/22, 18:47 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27190
-
core-ci voted on patch set 6 V +1 05/13/22, 18:52 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27191
-
Stefan Bürk commented on patch set 6 05/13/22, 18:55
Reply
Wanted to suggest to cut this out. I have that part on my todo-list for deeper investigation. So thanks for splitting this out. -
crell commented on patch set 6 05/13/22, 18:57
GeneralUtility.php:3216ReplyDone -
Stefan Bürk updated the commit message in patch set 7 05/14/22, 22:14
-
core-ci voted on patch set 7 V +1 05/14/22, 22:21 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27218
-
Oliver Klee commented on patch set 7 05/15/22, 09:43
CreateColumnDefinitionItem.php:48This property is only written (once) and never read. I propose we instead remove the line that writes it.GeneralUtility.php:3231If we're pretty sure that $obj here always is an instance of AbstractAuthenticationService, we can make this even more official by using assert($obj instanceof AbstractAuthenticationService); instead of the type annotations. This provides PHPStan with the type as well, and also adds a hard check on installations with assert enabled. (On production systems, this should be disabled, which then also avoids the (minimal) runtime overhead.)PageTsConfigParserTest.php:45This looks wrong to me. $this is the test case, not an instance of TypoScriptParser. As $this->setup is never read, we might be get away with dropping the anonymous function altogether.
-
crell commented on patch set 7 05/16/22, 15:44
CreateColumnDefinitionItem.php:48ReplyIt's public, so presumably it's intended for external reads, no? Wouldn't that be a breaking change?GeneralUtility.php:3231ReplyI am not pretty sure that it is always AbstractAuthenticationService. :-) Talking with Stefan, this is probably the best we can do for now, and we should instead work to eliminate this legacy extension mechanism entirely.PageTsConfigParserTest.php:45ReplyProphesy rebinds the closure to the mocked object, so $this does refer to the parser object, not the test. Removing the anon function causes the assertion at the end of the method to fail. (This is part of why I avoid using mocking libraries whenever possible, because the tests are hard to follow.) -
Oliver Klee commented on patch set 7 05/17/22, 10:25
CreateColumnDefinitionItem.php:48ReplyI wouldn't consider setting a property that does not exist part of our BC promise. However, I'd like to have the opinion of one of the Core mergers here. Benni? Stefan? Lolli?GeneralUtility.php:3231ReplyAckPageTsConfigParserTest.php:45ReplyAck -
Stefan Bürk commented on patch set 7 05/18/22, 19:40
CreateColumnDefinitionItem.php:48ReplyThe place where property '->null' is written *must* write to ->allowNull instead. In the original patch intruducing this schema parser the property was `->null`, and has been refactored/changed to '->allowNull'. Has been missed to "adjust on on writing place and went unnoticed through the review of this bigger patch. See: https://review.typo3.org/c/Packages/TYPO3.CMS/+/49593/12..16/typo3/sysext/core/Classes/Database/Schema/Parser/AST/CreateColumnDefinitionItem.php#b42 Despite writing the "default" value, this should be corrected. And the writing "not" removed, as it would not make clear what the AST builder is doing. T_NULL for "column type" says it's nullable. can be "manual" expressed, but if missing it is the default. In the wild, this is mostly omited in ext_tables.sql files. In contrast to "NOT NULL" which sets 'allowNull' to false, whis is more common. T_NULL as value (default) value is handled in another place in the AST builder. So far the explanation/background. * remove the $null property * change writing place to write into $allowNull ``` case Lexer::T_NULL: $columnDefinitionItem->allowNull = true; $this->match(Lexer::T_NULL); break; ``` in `\TYPO3\CMS\Core\Database\Schema\Parser\Parser->createColumnDefinitionItem()` This is a "bugfix" - which how ever has no outcome because of the "default". Thus backportable without any further headache ( an the whole Schema Parse should be treatened as internal anyway). -
Oliver Klee wrote 05/18/22, 19:41
Removed reviewer Oliver Klee. -
crell commented on patch set 7 05/20/22, 17:01
CreateColumnDefinitionItem.php:48ReplyAck -
crell uploaded patch set 8 05/20/22, 17:05
-
core-ci voted on patch set 8 V +1 05/20/22, 17:13 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27357
-
crell uploaded patch set 9 07/08/22, 14:45
-
core-ci voted on patch set 9 V +1 07/08/22, 14:53 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/28762
-
Stefan Bürk updated the commit message in patch set 10 07/08/22, 19:33
-
Stefan Bürk updated the commit message in patch set 11 07/08/22, 19:34
-
Stefan Bürk voted on patch set 11 V +1 CR +1 07/08/22, 19:40
-
core-ci voted on patch set 10 V +1 07/08/22, 19:41 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/28771
-
core-ci voted on patch set 11 V +1 07/08/22, 19:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/28772
-
Nikita Hovratov commented on patch set 11 07/08/22, 20:08
There are some good fixes for v11 also. Let's divide this patch in breaking and non-breaking changes. -
Nikita Hovratov uploaded patch set 12 07/08/22, 20:31
-
Nikita Hovratov updated the commit message in patch set 13 07/08/22, 20:33
-
core-ci voted on patch set 12 V +1 07/08/22, 20:39 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/28777
-
core-ci voted on patch set 13 V +1 07/08/22, 20:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/28779
-
Nikita Hovratov voted on patch set 13 V +1 CR +1 07/08/22, 20:44
-
Stefan Bürk commented on patch set 13 07/08/22, 21:47
Reply
Did you already created the splited patch with the "removed" changes due backportability ? -
Nikita Hovratov commented on patch set 13 07/08/22, 21:50
Reply
Not yet, it's just the typehints and return type for that GU method. -
Stefan Bürk voted on patch set 13 V +2 CR +2 07/08/22, 21:53
-
Stefan Bürk merged patch set 14 07/08/22, 21:53
-
Stefan Bürk commented on patch set 14 07/08/22, 21:54
Reply
Please take care of it ;)
phpstan-baseline.neon:4298