Closed a-r-m-i-n closed 11 months ago
I solved this by propagating the parent classes' generics annotations in my abstract repository: https://github.com/oliverklee/ext-feuserextrafields/blob/v5.4.0/Classes/Domain/Repository/AbstractFrontendUserRepository.php
Very cool! Thank you @oliverklee This solved the issue for me as well.
However, when a repository class is marked as "abstract" phpstan should not expect a model for this repository existing.
@a-r-m-i-n Could you check if @inheritdoc
would also solve the problem?
(just a wild guess; haven't tried this yet)
Oh, no. It did not work. I've already renamed the repository to "AbstractEntityRepository" and now was able to provide an abstract model for this - and thought because of this, it would work. My fault!
After reverting, I've added
/**
* @template TEntityClass of \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface
* @extends Repository<TEntityClass>
*/
to the AbstractRepository. Did I miss something?
@a-r-m-i-n Do your non-abstract repos also have the corresponding generics annotation, e.g. like this?
@inheritdoc
to the AbstractRepository did not change anything.
@a-r-m-i-n Do your non-abstract repos also have the corresponding generics annotation, e.g. like this?
No. I try this
@a-r-m-i-n Do you have more information about the source of the error? Where does it happen?
Thanks for trying @inheritdoc
. :pray: It was worth a try. :slightly_smiling_face:
@a-r-m-i-n Do your non-abstract repos also have the corresponding generics annotation, e.g. like this?
Did not help
@a-r-m-i-n Do you have more information about the source of the error? Where does it happen?
Not sure what you mean. The error is assigned to a file named project/Classes/DataProcessing/BenefitProcessor.php
which is a DataProcessor.
The line which it is pointing to, calls a non-existing-method (triggering magic __call) of one repository, extending from my AbstractRepository.
Not sure what you mean. The error is assigned to a file named
project/Classes/DataProcessing/BenefitProcessor.php
which is a DataProcessor.The line which it is pointing to, calls a non-existing-method (triggering magic __call) of one repository, extending from my AbstractRepository.
Ok, how doe the code look like in the processor? Are you using AbstractRepository as type or annotation somewhere in there?
Ok, how doe the code look like in the processor? Are you using AbstractRepository as type or annotation somewhere in there?
No, the only files referencing to AbstractRepository are the repositories extending from it, within the same namespace. AbstractRepository is not being used elsewhere.
Maybe good to know: It only happens when I call a non-existing method. Existing methods - in the same repo - do not trigger the issue.
Maybe good to know: It only happens when I call a non-existing method. Existing methods - in the same repo - do not trigger the issue.
You mean methods that are not implemented right? So it does also happen for "magic" methods like findByFieldname
, right?
Ahhh. Actually there was a bug in the code. Because the model has no "blah" property, but I called findByBlah($blubb)
.
When I call a magic method findByTitle, which' property actually exist, I get no error anymore.
So the fact that I got an error was correct. Just the error message wasn't.
Ahhh. Actually there was a bug in the code. Because the model has no "blah" property, but I called
findByBlah($blubb)
. When I call a magic method findByTitle, which' property actually exist, I get no error anymore.So the fact that I got an error was correct. Just the error message wasn't.
Ok, i can reproduce it. I'll take care
@a-r-m-i-n Could you please check if you'll get a proper error message with the small adjustment i did?
Yes, I was able to confirm that your patch works. 👍
Before:
------ -----------------------------------------------------------------------------------------------------------
Line extension/Classes/DataProcessing/BenefitProcessor.php
------ -----------------------------------------------------------------------------------------------------------
28 Class Vendor\Extension\Domain\Model\Abstract was not found while trying to analyse it - discovering symbols is
probably not configured properly.
💡 Learn more at https://phpstan.org/user-guide/discovering-symbols
------ -----------------------------------------------------------------------------------------------------------
After:
------ ------------------------------------------------------------------------------------------------------
Line extension/Classes/DataProcessing/BenefitProcessor.php
------ ------------------------------------------------------------------------------------------------------
28 Call to an undefined method Vendor\Extension\Domain\Repository\BenefitRepository::findByBlah().
------ ------------------------------------------------------------------------------------------------------
Please merge and release 😊
In projects where we provide an AbstractRepository, I get the error:
Although the class itself is marked as "abstract":
Excluding the path of the AbstractRepository did not solve the issue, nor moving the AbstractRepository out of the Domain/Repository namespace. Also, providing a model named "Abstract" is not possible. because abstract is a reserved word in PHP.
The only solution for this is, to not include the
vendor/saschaegerer/phpstan-typo3/extension.neon
as long as this bug is fixed.