mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
[PR #9551] Split TreeWalker and SqlWalker #11700
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Original Pull Request: https://github.com/doctrine/orm/pull/9551
State: closed
Merged: Yes
When working on native types for the
TreeWalkerinterface and its implementations I ran into some trouble. The main problem was that the interface declares most of its methods with astringreturn 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
TreeWakerChainthat 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 ofSqlWalkerorSqlWalkeritself which is the default.You can verify my assumption by removing the
implementspart fromSqlWalker: Doing so won't break a single test.3849aed6fb/lib/Doctrine/ORM/Query/SqlWalker.php (L48)The
TreeWalkerinterface is really quite large. This is why implementations (except forSqlWalkerandTreeWalkerChain) usually extendTreeWalkerAdapterwhich provides empty implementations (withvoidreturn 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:
SqlWalkerdoes not extendTreeWalkeranymore.TreeWalker,TreeWalkerAdapterandTreeWalkerChainare reduced towalkSelectStatement(),walkUpdateStatement()andwalkDeleteStatement()and receive a consistentvoidreturn type.