-
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
Split TreeWalker and SqlWalker #9551
Conversation
0d3ec8d
to
c0f7929
Compare
Without looking too much into the implementation, instead of having multiple interfaces, would it be possible to have one parameterized? See https://phpstan.org/r/7ec5df39-c547-4116-abd8-f706ae0dd548 for example. |
That's possible and that way we could have |
c0f7929
to
f9659bb
Compare
cf4fb41
to
1d97ce2
Compare
1d97ce2
to
fd5ee18
Compare
548a069
to
b6d25c1
Compare
0169258
to
55c08f5
Compare
55c08f5
to
9e9dcd3
Compare
I think your proposal goes in the right direction! It's not like we have a big bag of walkers at some point and iterate on them, they seem to be well separated from the start. I used this as an occasion to try out the MermaidJS integration (disregard the BeforeclassDiagram
TreeWalker <|-- TreeWalkerAdapter
TreeWalker <|-- TreeWalkerChain
TreeWalkerChain *-- TreeWalker
TreeWalker <|-- SqlWalker
TreeWalker : string walkSelectStatement()
TreeWalker : string walkUpdateStatement()
TreeWalker : string walkDeleteStatement()
TreeWalker : mixed manyMoreMethods()
AfterclassDiagram
TreeWalker <|-- TreeWalkerAdapter
TreeWalker <|-- TreeWalkerChain
TreeWalkerChain *-- TreeWalker
TreeWalker : void walkSelectStatement()
TreeWalker : void walkUpdateStatement()
TreeWalker : void walkDeleteStatement()
SomeOtherInterface <|-- SqlWalker
Regarding the purpose of |
4d738f3
to
9cfea0f
Compare
9834963
to
56e90aa
Compare
Rebased. Now that the deprecation is in place, I think I can backport some more changes to 2.13. Leaving this PR as draft for now. |
56e90aa
to
fbff600
Compare
d579c88
to
8f65a69
Compare
8f65a69
to
b8066a9
Compare
9a75953
to
93df374
Compare
public function walkConditionalExpression($condExpr) | ||
{ | ||
public function walkConditionalExpression( | ||
AST\ConditionalExpression|AST\ConditionalPrimary|AST\ConditionalTerm|AST\ConditionalFactor $condExpr |
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'm not really happy with those unions here. We should try to get rid of them in a follow-up.
93df374
to
6e75d51
Compare
When working on native types for the
TreeWalker
interface and its implementations I ran into some trouble. The main problem was that the interface declares most of its methods with astring
return type while some implementations change the return type tovoid
. This of course is not allowed and PHPStan and Psalm already complain a lot about that.Analyzing the implementations and their usages, I came to the conclusion that we basically have two types of implementations:
Tree walkers are never called directly. Instead, they are loaded into a
TreeWakerChain
that iterates over them. Those walkers are optional; it might very well be that the chain is empty when parsing a query. On the other hand, we'll always have an output walker in that process. It has to be either a subclass ofSqlWalker
orSqlWalker
itself which is the default.You can verify my assumption by removing the
implements
part fromSqlWalker
: Doing so won't break a single test.orm/lib/Doctrine/ORM/Query/SqlWalker.php
Line 48 in 3849aed
The
TreeWalker
interface is really quite large. This is why implementations (except forSqlWalker
andTreeWalkerChain
) usually extendTreeWalkerAdapter
which provides empty implementations (withvoid
return type!) for all methods. The custom tree walker would just override the method it really wants to implement. The interesting part about that is that onlywalkSelectStatement()
,walkUpdateStatement()
andwalkDeleteStatement()
are ever called publicly. Overriding any other method would be futile. Those methods are called on the output walker however.This is why I'd like to propose the following changes:
SqlWalker
does not extendTreeWalker
anymore.TreeWalker
,TreeWalkerAdapter
andTreeWalkerChain
are reduced towalkSelectStatement()
,walkUpdateStatement()
andwalkDeleteStatement()
and receive a consistentvoid
return type.