| Total Complexity | 54 |
| Total Lines | 410 |
| Duplicated Lines | 2.44 % |
| Coverage | 14.29% |
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like TreeWalkerAdapter often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TreeWalkerAdapter, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | abstract class TreeWalkerAdapter implements TreeWalker |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * The original Query. |
||
| 33 | * |
||
| 34 | * @var \Doctrine\ORM\AbstractQuery |
||
| 35 | */ |
||
| 36 | private $_query; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * The ParserResult of the original query that was produced by the Parser. |
||
| 40 | * |
||
| 41 | * @var \Doctrine\ORM\Query\ParserResult |
||
| 42 | */ |
||
| 43 | private $_parserResult; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * The query components of the original query (the "symbol table") that was produced by the Parser. |
||
| 47 | * |
||
| 48 | * @var array |
||
| 49 | */ |
||
| 50 | private $_queryComponents; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * {@inheritdoc} |
||
| 54 | */ |
||
| 55 | 178 | public function __construct($query, $parserResult, array $queryComponents) |
|
| 56 | { |
||
| 57 | 178 | $this->_query = $query; |
|
| 58 | 178 | $this->_parserResult = $parserResult; |
|
| 59 | 178 | $this->_queryComponents = $queryComponents; |
|
| 60 | 178 | } |
|
| 61 | |||
| 62 | /** |
||
| 63 | * {@inheritdoc} |
||
| 64 | */ |
||
| 65 | 89 | public function getQueryComponents() |
|
| 66 | { |
||
| 67 | 89 | return $this->_queryComponents; |
|
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * {@inheritdoc} |
||
| 72 | */ |
||
| 73 | 2 | View Code Duplication | public function setQueryComponent($dqlAlias, array $queryComponent) |
| 74 | { |
||
| 75 | 2 | $requiredKeys = ['metadata', 'parent', 'relation', 'map', 'nestingLevel', 'token']; |
|
| 76 | |||
| 77 | 2 | if (array_diff($requiredKeys, array_keys($queryComponent))) { |
|
| 78 | throw QueryException::invalidQueryComponent($dqlAlias); |
||
| 79 | } |
||
| 80 | |||
| 81 | 2 | $this->_queryComponents[$dqlAlias] = $queryComponent; |
|
| 82 | 2 | } |
|
| 83 | |||
| 84 | /** |
||
| 85 | * @return array |
||
| 86 | */ |
||
| 87 | 86 | protected function _getQueryComponents() |
|
| 88 | { |
||
| 89 | 86 | return $this->_queryComponents; |
|
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Retrieves the Query Instance responsible for the current walkers execution. |
||
| 94 | * |
||
| 95 | * @return \Doctrine\ORM\AbstractQuery |
||
| 96 | */ |
||
| 97 | 84 | protected function _getQuery() |
|
| 98 | { |
||
| 99 | 84 | return $this->_query; |
|
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Retrieves the ParserResult. |
||
| 104 | * |
||
| 105 | * @return \Doctrine\ORM\Query\ParserResult |
||
| 106 | */ |
||
| 107 | protected function _getParserResult() |
||
| 108 | { |
||
| 109 | return $this->_parserResult; |
||
| 110 | } |
||
| 111 | |||
| 112 | /** |
||
| 113 | * {@inheritdoc} |
||
| 114 | */ |
||
| 115 | public function walkSelectStatement(AST\SelectStatement $AST) |
||
| 116 | { |
||
| 117 | } |
||
| 118 | |||
| 119 | /** |
||
| 120 | * {@inheritdoc} |
||
| 121 | */ |
||
| 122 | public function walkSelectClause($selectClause) |
||
| 123 | { |
||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * {@inheritdoc} |
||
| 128 | */ |
||
| 129 | public function walkFromClause($fromClause) |
||
| 130 | { |
||
| 131 | } |
||
| 132 | |||
| 133 | /** |
||
| 134 | * {@inheritdoc} |
||
| 135 | */ |
||
| 136 | public function walkFunction($function) |
||
| 137 | { |
||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * {@inheritdoc} |
||
| 142 | */ |
||
| 143 | public function walkOrderByClause($orderByClause) |
||
| 144 | { |
||
| 145 | } |
||
| 146 | |||
| 147 | /** |
||
| 148 | * {@inheritdoc} |
||
| 149 | */ |
||
| 150 | public function walkOrderByItem($orderByItem) |
||
| 151 | { |
||
| 152 | } |
||
| 153 | |||
| 154 | /** |
||
| 155 | * {@inheritdoc} |
||
| 156 | */ |
||
| 157 | public function walkHavingClause($havingClause) |
||
| 158 | { |
||
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
| 162 | * {@inheritdoc} |
||
| 163 | */ |
||
| 164 | public function walkJoin($join) |
||
| 165 | { |
||
| 166 | } |
||
| 167 | |||
| 168 | /** |
||
| 169 | * {@inheritdoc} |
||
| 170 | */ |
||
| 171 | public function walkSelectExpression($selectExpression) |
||
| 172 | { |
||
| 173 | } |
||
| 174 | |||
| 175 | /** |
||
| 176 | * {@inheritdoc} |
||
| 177 | */ |
||
| 178 | public function walkQuantifiedExpression($qExpr) |
||
| 179 | { |
||
| 180 | } |
||
| 181 | |||
| 182 | /** |
||
| 183 | * {@inheritdoc} |
||
| 184 | */ |
||
| 185 | public function walkSubselect($subselect) |
||
| 186 | { |
||
| 187 | } |
||
| 188 | |||
| 189 | /** |
||
| 190 | * {@inheritdoc} |
||
| 191 | */ |
||
| 192 | public function walkSubselectFromClause($subselectFromClause) |
||
| 193 | { |
||
| 194 | } |
||
| 195 | |||
| 196 | /** |
||
| 197 | * {@inheritdoc} |
||
| 198 | */ |
||
| 199 | public function walkSimpleSelectClause($simpleSelectClause) |
||
| 200 | { |
||
| 201 | } |
||
| 202 | |||
| 203 | /** |
||
| 204 | * {@inheritdoc} |
||
| 205 | */ |
||
| 206 | public function walkSimpleSelectExpression($simpleSelectExpression) |
||
| 207 | { |
||
| 208 | } |
||
| 209 | |||
| 210 | /** |
||
| 211 | * {@inheritdoc} |
||
| 212 | */ |
||
| 213 | public function walkAggregateExpression($aggExpression) |
||
| 214 | { |
||
| 215 | } |
||
| 216 | |||
| 217 | /** |
||
| 218 | * {@inheritdoc} |
||
| 219 | */ |
||
| 220 | public function walkGroupByClause($groupByClause) |
||
| 221 | { |
||
| 222 | } |
||
| 223 | |||
| 224 | /** |
||
| 225 | * {@inheritdoc} |
||
| 226 | */ |
||
| 227 | public function walkGroupByItem($groupByItem) |
||
| 228 | { |
||
| 229 | } |
||
| 230 | |||
| 231 | /** |
||
| 232 | * {@inheritdoc} |
||
| 233 | */ |
||
| 234 | public function walkUpdateStatement(AST\UpdateStatement $AST) |
||
| 235 | { |
||
| 236 | } |
||
| 237 | |||
| 238 | /** |
||
| 239 | * {@inheritdoc} |
||
| 240 | */ |
||
| 241 | public function walkDeleteStatement(AST\DeleteStatement $AST) |
||
| 242 | { |
||
| 243 | } |
||
| 244 | |||
| 245 | /** |
||
| 246 | * {@inheritdoc} |
||
| 247 | */ |
||
| 248 | public function walkDeleteClause(AST\DeleteClause $deleteClause) |
||
| 249 | { |
||
| 250 | } |
||
| 251 | |||
| 252 | /** |
||
| 253 | * {@inheritdoc} |
||
| 254 | */ |
||
| 255 | public function walkUpdateClause($updateClause) |
||
| 256 | { |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * {@inheritdoc} |
||
| 261 | */ |
||
| 262 | public function walkUpdateItem($updateItem) |
||
| 263 | { |
||
| 264 | } |
||
| 265 | |||
| 266 | /** |
||
| 267 | * {@inheritdoc} |
||
| 268 | */ |
||
| 269 | public function walkWhereClause($whereClause) |
||
| 270 | { |
||
| 271 | } |
||
| 272 | |||
| 273 | /** |
||
| 274 | * {@inheritdoc} |
||
| 275 | */ |
||
| 276 | public function walkConditionalExpression($condExpr) |
||
| 277 | { |
||
| 278 | } |
||
| 279 | |||
| 280 | /** |
||
| 281 | * {@inheritdoc} |
||
| 282 | */ |
||
| 283 | public function walkConditionalTerm($condTerm) |
||
| 284 | { |
||
| 285 | } |
||
| 286 | |||
| 287 | /** |
||
| 288 | * {@inheritdoc} |
||
| 289 | */ |
||
| 290 | public function walkConditionalFactor($factor) |
||
| 291 | { |
||
| 292 | } |
||
| 293 | |||
| 294 | /** |
||
| 295 | * {@inheritdoc} |
||
| 296 | */ |
||
| 297 | public function walkConditionalPrimary($primary) |
||
| 299 | } |
||
| 300 | |||
| 301 | /** |
||
| 302 | * {@inheritdoc} |
||
| 303 | */ |
||
| 304 | public function walkExistsExpression($existsExpr) |
||
| 305 | { |
||
| 306 | } |
||
| 307 | |||
| 308 | /** |
||
| 309 | * {@inheritdoc} |
||
| 310 | */ |
||
| 311 | public function walkCollectionMemberExpression($collMemberExpr) |
||
| 312 | { |
||
| 313 | } |
||
| 314 | |||
| 315 | /** |
||
| 316 | * {@inheritdoc} |
||
| 317 | */ |
||
| 318 | public function walkEmptyCollectionComparisonExpression($emptyCollCompExpr) |
||
| 319 | { |
||
| 320 | } |
||
| 321 | |||
| 322 | /** |
||
| 323 | * {@inheritdoc} |
||
| 324 | */ |
||
| 325 | public function walkNullComparisonExpression($nullCompExpr) |
||
| 326 | { |
||
| 327 | } |
||
| 328 | |||
| 329 | /** |
||
| 330 | * {@inheritdoc} |
||
| 331 | */ |
||
| 332 | public function walkInExpression($inExpr) |
||
| 333 | { |
||
| 334 | } |
||
| 335 | |||
| 336 | /** |
||
| 337 | * {@inheritdoc} |
||
| 338 | */ |
||
| 339 | public function walkInstanceOfExpression($instanceOfExpr) |
||
| 340 | { |
||
| 341 | } |
||
| 342 | |||
| 343 | /** |
||
| 344 | * {@inheritdoc} |
||
| 345 | */ |
||
| 346 | public function walkLiteral($literal) |
||
| 347 | { |
||
| 348 | } |
||
| 349 | |||
| 350 | /** |
||
| 351 | * {@inheritdoc} |
||
| 352 | */ |
||
| 353 | public function walkBetweenExpression($betweenExpr) |
||
| 354 | { |
||
| 355 | } |
||
| 356 | |||
| 357 | /** |
||
| 358 | * {@inheritdoc} |
||
| 359 | */ |
||
| 360 | public function walkLikeExpression($likeExpr) |
||
| 361 | { |
||
| 362 | } |
||
| 363 | |||
| 364 | /** |
||
| 365 | * {@inheritdoc} |
||
| 366 | */ |
||
| 367 | public function walkStateFieldPathExpression($stateFieldPathExpression) |
||
| 368 | { |
||
| 369 | } |
||
| 370 | |||
| 371 | /** |
||
| 372 | * {@inheritdoc} |
||
| 373 | */ |
||
| 374 | public function walkComparisonExpression($compExpr) |
||
| 375 | { |
||
| 376 | } |
||
| 377 | |||
| 378 | /** |
||
| 379 | * {@inheritdoc} |
||
| 380 | */ |
||
| 381 | public function walkInputParameter($inputParam) |
||
| 383 | } |
||
| 384 | |||
| 385 | /** |
||
| 386 | * {@inheritdoc} |
||
| 387 | */ |
||
| 388 | public function walkArithmeticExpression($arithmeticExpr) |
||
| 389 | { |
||
| 390 | } |
||
| 391 | |||
| 392 | /** |
||
| 393 | * {@inheritdoc} |
||
| 394 | */ |
||
| 395 | public function walkArithmeticTerm($term) |
||
| 396 | { |
||
| 397 | } |
||
| 398 | |||
| 399 | /** |
||
| 400 | * {@inheritdoc} |
||
| 401 | */ |
||
| 402 | public function walkStringPrimary($stringPrimary) |
||
| 403 | { |
||
| 404 | } |
||
| 405 | |||
| 406 | /** |
||
| 407 | * {@inheritdoc} |
||
| 408 | */ |
||
| 409 | public function walkArithmeticFactor($factor) |
||
| 410 | { |
||
| 411 | } |
||
| 412 | |||
| 413 | /** |
||
| 414 | * {@inheritdoc} |
||
| 415 | */ |
||
| 416 | public function walkSimpleArithmeticExpression($simpleArithmeticExpr) |
||
| 417 | { |
||
| 418 | } |
||
| 419 | |||
| 420 | /** |
||
| 421 | * {@inheritdoc} |
||
| 422 | */ |
||
| 423 | public function walkPathExpression($pathExpr) |
||
| 425 | } |
||
| 426 | |||
| 427 | /** |
||
| 428 | * {@inheritdoc} |
||
| 429 | */ |
||
| 430 | public function walkResultVariable($resultVariable) |
||
| 431 | { |
||
| 432 | } |
||
| 433 | |||
| 434 | /** |
||
| 435 | * {@inheritdoc} |
||
| 436 | */ |
||
| 437 | public function getExecutor($AST) |
||
| 438 | { |
||
| 439 | } |
||
| 440 | } |
||
| 441 |