stable

Clone or download

Read-only

Refactoring: do not pass unneeded parameters to visitors

This is a part of story #8858 query tracker with expressions No functional changes. We must remove the contract definition in the Visitor. If we don't, then we will have to write: class A { public function accept(Visitor $v, VisitorParameters $p) { $v->visitA($this, $p); } } interface Visitor { public function visitA(A $a, VisitorParameters $p); } class VisitorXxx implements Visitor { public function visitA(A $a, VisitorParameters $p) { } } However in the implementation of visitA in VisitorXxx, we need a XxxParameters, not a VisitorParameters. we need to access to specific parameter. In one case it will be getUser() in another case it will be getFieldCollection(), … it depends on the context (context defined by the specific visitor. We cannot write this: class VisitorXxx implements Visitor { public function visitA(A $a, XxxParameters $p) { } } because 1) it breaks LSP and 2) PHP does not accept it since the declaration differs from the parent interface. The only way to manage this case is the following hack: interface Visitor { public function visitA(A $a); } class VisitorXxx implements Visitor { public function visitA(A $a, XxxParameters $p = null) { } } Here PHP will be happy, but the developer will not since null parameters are evil. This would mean that we will have to check the null case at runtime. (J)Hacky as hell. Therefore the only way to do so is to not anymore declare the functions in our interface. It is much preferable than the current situation where some parameters are used and some others are not. Change-Id: I6927152a35ac6230a0ae2eff60ba53dd41e13b05

Modified Files

Name
M plugins/tracker/include/Tracker/Report/Query/Advanced/Grammar/AndExpression.php +4 −7 Go to diff View file
M plugins/tracker/include/Tracker/Report/Query/Advanced/Grammar/AndOperand.php +4 −7 Go to diff View file
M plugins/tracker/include/Tracker/Report/Query/Advanced/Grammar/Comparison.php +3 −6 Go to diff View file
A plugins/tracker/include/Tracker/Report/Query/Advanced/Grammar/DepthValidatorParameters.php +24 −0 Go to diff View file
R plugins/tracker/include/Tracker/Report/Query/Advanced/Grammar/DepthValidator.php Go to diff View file
A plugins/tracker/include/Tracker/Report/Query/Advanced/Grammar/InvalidFieldsCollectorParameters.php +58 −0 Go to diff View file
R plugins/tracker/include/Tracker/Report/Query/Advanced/Grammar/Collector.php Go to diff View file
M plugins/tracker/include/Tracker/Report/Query/Advanced/Grammar/OrExpression.php +4 −7 Go to diff View file
M plugins/tracker/include/Tracker/Report/Query/Advanced/Grammar/OrOperand.php +4 −7 Go to diff View file
A plugins/tracker/include/Tracker/Report/Query/Advanced/Grammar/QueryBuilderParameters.php +43 −0 Go to diff View file
R plugins/tracker/include/Tracker/Report/Query/Advanced/Grammar/QueryBuilder.php Go to diff View file
A plugins/tracker/include/Tracker/Report/Query/Advanced/Grammar/Visitable.php +25 −0 Go to diff View file
M plugins/tracker/include/Tracker/Report/Query/Advanced/Grammar/Visitor.php +1 −13 Go to diff View file
A plugins/tracker/include/Tracker/Report/Query/Advanced/Grammar/VisitorParameters.php +24 −0 Go to diff View file
M plugins/tracker/include/Tracker/Report/Tracker_Report.class.php +17 −17 Go to diff View file
M plugins/tracker/include/autoload.php +10 −5 Go to diff View file
M plugins/tracker/tests/Tracker/Report/Query/Advanced/Grammar/DepthValidatorTest.php +3 −3 Go to diff View file
R plugins/tracker/tests/Tracker/Report/Query/Advanced/Grammar/CollectorTest.php Go to diff View file
M plugins/tracker/tests/Tracker/Report/Query/Advanced/Grammar/QueryBuilderTest.php +28 −27 Go to diff View file