-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Precise phpdoc of getRootEntities #9778
Conversation
Hi @greg0ire, I recently got a static analysis error because I was expecting |
I don't know for sure but it looks to me like you are right. If not, we will revert this PR and add a comment to explain :) I think this comment needs to be changed as well: orm/lib/Doctrine/ORM/QueryBuilder.php Lines 493 to 494 in 8f77012
Also, PRs that fix wrong things should target 2.12.x, but target that make things more precise should target 2.13.x |
Fixed :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just remembered 2 features that might explain why class-string
was not used before. Please check what happens when you use them.
@@ -490,7 +494,7 @@ public function getAllAliases() | |||
} | |||
|
|||
/** | |||
* Gets the root entities of the query. This is the entity aliases involved | |||
* Gets the root entities of the query. This is the entity classes involved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 maybe this was referring to the deprecated but still existing class alias feature? #8818
I don't know if those are resolved at that point.
lib/Doctrine/ORM/QueryBuilder.php
Outdated
$alias = substr($fromClause, $spacePos + 1); | ||
|
||
$from = substr($fromClause, 0, $spacePos); | ||
assert(class_exists($from)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise, there is a feature that allows to use an interface here: https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/cookbook/resolve-target-entity-listener.html I think this assertion might be wrong because of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know how to solve both the static analysis error and the cs style error.
First, I added. /** @var class-string $from */
and got a cs error.
I tried again with @psalm-var
, seems like it's ok like this.
It might be better to not doing any assertions so far to avoid any errors with the deprecated class-alias feature.
Indeed, but since it's deprecated this will help to stop using them thanks to phpstan reporting static analysis errors then. |
I might agree if we were talking about parameter type declarations, but here, this is about return type declarations. We just cannot guarantee that we are going to return a class-string. I think the way forward should be to check if yes or no, what I described does happen in practice (maybe interfaces and short aliases are resolved earlier?), and if yes, to document why we use |
Currently the following code is reported as an error by phpstan
because I don't feel right the fact that doctrine/orm is compatible with persistence 3 (https://github.com/doctrine/orm/blob/2.12.x/composer.json#L35) but let the user to handle this phpstan error.
You never can guarantee that this is a class-string. In the following code
If I can To me it's the same here. getRootEntities is supposed to return a class string IF you respect others params method phpdoc. |
Even if we respect the
Well we can't know if the user is indeed using Persistence 3, can we? I'm afraid you're going to have to use |
If you respect the It's the same than this return orm/lib/Doctrine/ORM/Configuration.php Line 611 in 2e4a872
It won't return a class-string, if you don't pass one to the setter orm/lib/Doctrine/ORM/Configuration.php Line 600 in 2e4a872
(which is currently asking for string, but even if you change for class-string, it won't force the user to pass a class-string). |
Which one? The one you are introducing in this PR? This conversation is going in circles, maybe because you think I am talking about the code after this PR, when I really am talking about the code before this PR. Before this PR, there is (rightly IMO) no |
Yes, I'm talking about the
I don't try to go in circles, but I really don't understand your point. You're saying that currently there is no If I use the same argument than you, I could say that
are currently working code. What the
Sure |
I'm not saying you are trying to go in circle, just noticing that's what is happening, and I remain hopeful that we are going to come to an understanding 😉
I think this is where we disagree: calling it with something else than a
That's where we disagree and where that discussion should focus. And by we, I'm not sure I mean just "you and I", but from what I've seen, Doctrine as a whole. We preserve documentation for deprecated things, be it in phpdoc or in actual documentation. I think we might accept this PR if it's really causing a lot of pain for you, but I don't think we would let it act as a precedent for other PRs changing phpdoc to document only non-deprecated behaviors. I'm adding more people as reviewers so that we can get other points of view on this. |
No description provided.