Failed Conditions
Push — master ( ddb3cd...4476ec )
by Marco
11:47
created

TreeWalkerChain   F

Complexity

Total Complexity 98

Size/Duplication

Total Lines 526
Duplicated Lines 0 %

Test Coverage

Coverage 6.97%

Importance

Changes 0
Metric Value
dl 0
loc 526
ccs 14
cts 201
cp 0.0697
rs 1.5789
c 0
b 0
f 0
wmc 98

51 Methods

Rating   Name   Duplication   Size   Complexity  
A walkInputParameter() 0 4 2
A setQueryComponent() 0 9 2
A walkHavingClause() 0 4 2
A walkDeleteStatement() 0 4 2
A walkConditionalPrimary() 0 4 2
A walkPathExpression() 0 4 2
A walkGroupByItem() 0 4 2
A walkSubselect() 0 4 2
A walkUpdateClause() 0 4 2
A walkSimpleArithmeticExpression() 0 4 2
A walkSelectClause() 0 4 2
A walkQuantifiedExpression() 0 4 2
A walkFunction() 0 4 2
A walkResultVariable() 0 4 2
A walkEmptyCollectionComparisonExpression() 0 4 2
A walkCollectionMemberExpression() 0 4 2
A walkSimpleSelectExpression() 0 4 2
A walkSubselectFromClause() 0 4 2
A walkAggregateExpression() 0 4 2
A walkInExpression() 0 4 2
A walkSelectExpression() 0 4 2
A walkInstanceOfExpression() 0 4 2
A getExecutor() 0 2 1
A walkExistsExpression() 0 4 2
A walkConditionalExpression() 0 4 2
A walkStringPrimary() 0 4 2
A walkComparisonExpression() 0 4 2
A walkGroupByClause() 0 4 2
A walkArithmeticFactor() 0 4 2
A walkStateFieldPathExpression() 0 4 2
A walkUpdateStatement() 0 4 2
A walkNullComparisonExpression() 0 4 2
A walkLikeExpression() 0 4 2
A walkOrderByClause() 0 4 2
A walkUpdateItem() 0 4 2
A addTreeWalker() 0 3 1
A walkArithmeticExpression() 0 4 2
A getQueryComponents() 0 3 1
A walkArithmeticTerm() 0 4 2
A __construct() 0 4 1
A walkLiteral() 0 4 2
A walkJoin() 0 4 2
A walkWhereClause() 0 4 2
A walkDeleteClause() 0 4 2
A walkBetweenExpression() 0 4 2
A walkOrderByItem() 0 4 2
A walkConditionalFactor() 0 4 2
A walkSimpleSelectClause() 0 4 2
A walkFromClause() 0 4 2
A walkConditionalTerm() 0 4 2
A walkSelectStatement() 0 6 2

How to fix   Complexity   

Complex Class

Complex classes like TreeWalkerChain 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 TreeWalkerChain, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Query;
6
7
/**
8
 * Represents a chain of tree walkers that modify an AST and finally emit output.
9
 * Only the last walker in the chain can emit output. Any previous walkers can modify
10
 * the AST to influence the final output produced by the last walker.
11
 */
12
class TreeWalkerChain implements TreeWalker
13
{
14
    /**
15
     * The tree walkers.
16
     *
17
     * @var TreeWalker[]
18
     */
19
    private $walkers;
20
21
    /**
22
     * The query components of the original query (the "symbol table") that was produced by the Parser.
23
     *
24
     * @var mixed[][]
25
     */
26
    private $queryComponents;
27
28
    /**
29
     * Returns the internal queryComponents array.
30
     *
31
     * @return mixed[][]
32
     */
33 95
    public function getQueryComponents()
34
    {
35 95
        return $this->queryComponents;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function setQueryComponent($dqlAlias, array $queryComponent)
42
    {
43
        $requiredKeys = ['metadata', 'parent', 'relation', 'map', 'nestingLevel', 'token'];
44
45
        if (array_diff($requiredKeys, array_keys($queryComponent))) {
46
            throw QueryException::invalidQueryComponent($dqlAlias);
47
        }
48
49
        $this->queryComponents[$dqlAlias] = $queryComponent;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 95
    public function __construct($query, $parserResult, array $queryComponents)
56
    {
57 95
        $this->queryComponents = $queryComponents;
58 95
        $this->walkers         = new TreeWalkerChainIterator($this, $query, $parserResult);
0 ignored issues
show
Documentation Bug introduced by
It seems like new Doctrine\ORM\Query\T... $query, $parserResult) of type Doctrine\ORM\Query\TreeWalkerChainIterator is incompatible with the declared type Doctrine\ORM\Query\TreeWalker[] of property $walkers.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
59 95
    }
60
61
    /**
62
     * Adds a tree walker to the chain.
63
     *
64
     * @param string $walkerClass The class of the walker to instantiate.
65
     */
66 95
    public function addTreeWalker($walkerClass)
67
    {
68 95
        $this->walkers[] = $walkerClass;
69 95
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74 95
    public function walkSelectStatement(AST\SelectStatement $AST)
75
    {
76 95
        foreach ($this->walkers as $walker) {
77 95
            $walker->walkSelectStatement($AST);
78
79 89
            $this->queryComponents = $walker->getQueryComponents();
80
        }
81 89
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function walkSelectClause($selectClause)
87
    {
88
        foreach ($this->walkers as $walker) {
89
            $walker->walkSelectClause($selectClause);
90
        }
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function walkFromClause($fromClause)
97
    {
98
        foreach ($this->walkers as $walker) {
99
            $walker->walkFromClause($fromClause);
100
        }
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106
    public function walkFunction($function)
107
    {
108
        foreach ($this->walkers as $walker) {
109
            $walker->walkFunction($function);
110
        }
111
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116
    public function walkOrderByClause($orderByClause)
117
    {
118
        foreach ($this->walkers as $walker) {
119
            $walker->walkOrderByClause($orderByClause);
120
        }
121
    }
122
123
    /**
124
     * {@inheritdoc}
125
     */
126
    public function walkOrderByItem($orderByItem)
127
    {
128
        foreach ($this->walkers as $walker) {
129
            $walker->walkOrderByItem($orderByItem);
130
        }
131
    }
132
133
    /**
134
     * {@inheritdoc}
135
     */
136
    public function walkHavingClause($havingClause)
137
    {
138
        foreach ($this->walkers as $walker) {
139
            $walker->walkHavingClause($havingClause);
140
        }
141
    }
142
143
    /**
144
     * {@inheritdoc}
145
     */
146
    public function walkJoin($join)
147
    {
148
        foreach ($this->walkers as $walker) {
149
            $walker->walkJoin($join);
150
        }
151
    }
152
153
    /**
154
     * {@inheritdoc}
155
     */
156
    public function walkSelectExpression($selectExpression)
157
    {
158
        foreach ($this->walkers as $walker) {
159
            $walker->walkSelectExpression($selectExpression);
160
        }
161
    }
162
163
    /**
164
     * {@inheritdoc}
165
     */
166
    public function walkQuantifiedExpression($qExpr)
167
    {
168
        foreach ($this->walkers as $walker) {
169
            $walker->walkQuantifiedExpression($qExpr);
170
        }
171
    }
172
173
    /**
174
     * {@inheritdoc}
175
     */
176
    public function walkSubselect($subselect)
177
    {
178
        foreach ($this->walkers as $walker) {
179
            $walker->walkSubselect($subselect);
180
        }
181
    }
182
183
    /**
184
     * {@inheritdoc}
185
     */
186
    public function walkSubselectFromClause($subselectFromClause)
187
    {
188
        foreach ($this->walkers as $walker) {
189
            $walker->walkSubselectFromClause($subselectFromClause);
190
        }
191
    }
192
193
    /**
194
     * {@inheritdoc}
195
     */
196
    public function walkSimpleSelectClause($simpleSelectClause)
197
    {
198
        foreach ($this->walkers as $walker) {
199
            $walker->walkSimpleSelectClause($simpleSelectClause);
200
        }
201
    }
202
203
    /**
204
     * {@inheritdoc}
205
     */
206
    public function walkSimpleSelectExpression($simpleSelectExpression)
207
    {
208
        foreach ($this->walkers as $walker) {
209
            $walker->walkSimpleSelectExpression($simpleSelectExpression);
210
        }
211
    }
212
213
    /**
214
     * {@inheritdoc}
215
     */
216
    public function walkAggregateExpression($aggExpression)
217
    {
218
        foreach ($this->walkers as $walker) {
219
            $walker->walkAggregateExpression($aggExpression);
220
        }
221
    }
222
223
    /**
224
     * {@inheritdoc}
225
     */
226
    public function walkGroupByClause($groupByClause)
227
    {
228
        foreach ($this->walkers as $walker) {
229
            $walker->walkGroupByClause($groupByClause);
230
        }
231
    }
232
233
    /**
234
     * {@inheritdoc}
235
     */
236
    public function walkGroupByItem($groupByItem)
237
    {
238
        foreach ($this->walkers as $walker) {
239
            $walker->walkGroupByItem($groupByItem);
240
        }
241
    }
242
243
    /**
244
     * {@inheritdoc}
245
     */
246
    public function walkUpdateStatement(AST\UpdateStatement $AST)
247
    {
248
        foreach ($this->walkers as $walker) {
249
            $walker->walkUpdateStatement($AST);
250
        }
251
    }
252
253
    /**
254
     * {@inheritdoc}
255
     */
256
    public function walkDeleteStatement(AST\DeleteStatement $AST)
257
    {
258
        foreach ($this->walkers as $walker) {
259
            $walker->walkDeleteStatement($AST);
260
        }
261
    }
262
263
    /**
264
     * {@inheritdoc}
265
     */
266
    public function walkDeleteClause(AST\DeleteClause $deleteClause)
267
    {
268
        foreach ($this->walkers as $walker) {
269
            $walker->walkDeleteClause($deleteClause);
270
        }
271
    }
272
273
    /**
274
     * {@inheritdoc}
275
     */
276
    public function walkUpdateClause($updateClause)
277
    {
278
        foreach ($this->walkers as $walker) {
279
            $walker->walkUpdateClause($updateClause);
280
        }
281
    }
282
283
    /**
284
     * {@inheritdoc}
285
     */
286
    public function walkUpdateItem($updateItem)
287
    {
288
        foreach ($this->walkers as $walker) {
289
            $walker->walkUpdateItem($updateItem);
290
        }
291
    }
292
293
    /**
294
     * {@inheritdoc}
295
     */
296
    public function walkWhereClause($whereClause)
297
    {
298
        foreach ($this->walkers as $walker) {
299
            $walker->walkWhereClause($whereClause);
300
        }
301
    }
302
303
    /**
304
     * {@inheritdoc}
305
     */
306
    public function walkConditionalExpression($condExpr)
307
    {
308
        foreach ($this->walkers as $walker) {
309
            $walker->walkConditionalExpression($condExpr);
310
        }
311
    }
312
313
    /**
314
     * {@inheritdoc}
315
     */
316
    public function walkConditionalTerm($condTerm)
317
    {
318
        foreach ($this->walkers as $walker) {
319
            $walker->walkConditionalTerm($condTerm);
320
        }
321
    }
322
323
    /**
324
     * {@inheritdoc}
325
     */
326
    public function walkConditionalFactor($factor)
327
    {
328
        foreach ($this->walkers as $walker) {
329
            $walker->walkConditionalFactor($factor);
330
        }
331
    }
332
333
    /**
334
     * {@inheritdoc}
335
     */
336
    public function walkConditionalPrimary($condPrimary)
337
    {
338
        foreach ($this->walkers as $walker) {
339
            $walker->walkConditionalPrimary($condPrimary);
340
        }
341
    }
342
343
    /**
344
     * {@inheritdoc}
345
     */
346
    public function walkExistsExpression($existsExpr)
347
    {
348
        foreach ($this->walkers as $walker) {
349
            $walker->walkExistsExpression($existsExpr);
350
        }
351
    }
352
353
    /**
354
     * {@inheritdoc}
355
     */
356
    public function walkCollectionMemberExpression($collMemberExpr)
357
    {
358
        foreach ($this->walkers as $walker) {
359
            $walker->walkCollectionMemberExpression($collMemberExpr);
360
        }
361
    }
362
363
    /**
364
     * {@inheritdoc}
365
     */
366
    public function walkEmptyCollectionComparisonExpression($emptyCollCompExpr)
367
    {
368
        foreach ($this->walkers as $walker) {
369
            $walker->walkEmptyCollectionComparisonExpression($emptyCollCompExpr);
370
        }
371
    }
372
373
    /**
374
     * {@inheritdoc}
375
     */
376
    public function walkNullComparisonExpression($nullCompExpr)
377
    {
378
        foreach ($this->walkers as $walker) {
379
            $walker->walkNullComparisonExpression($nullCompExpr);
380
        }
381
    }
382
383
    /**
384
     * {@inheritdoc}
385
     */
386
    public function walkInExpression($inExpr)
387
    {
388
        foreach ($this->walkers as $walker) {
389
            $walker->walkInExpression($inExpr);
390
        }
391
    }
392
393
    /**
394
     * {@inheritdoc}
395
     */
396
    public function walkInstanceOfExpression($instanceOfExpr)
397
    {
398
        foreach ($this->walkers as $walker) {
399
            $walker->walkInstanceOfExpression($instanceOfExpr);
400
        }
401
    }
402
403
    /**
404
     * {@inheritdoc}
405
     */
406
    public function walkLiteral($literal)
407
    {
408
        foreach ($this->walkers as $walker) {
409
            $walker->walkLiteral($literal);
410
        }
411
    }
412
413
    /**
414
     * {@inheritdoc}
415
     */
416
    public function walkBetweenExpression($betweenExpr)
417
    {
418
        foreach ($this->walkers as $walker) {
419
            $walker->walkBetweenExpression($betweenExpr);
420
        }
421
    }
422
423
    /**
424
     * {@inheritdoc}
425
     */
426
    public function walkLikeExpression($likeExpr)
427
    {
428
        foreach ($this->walkers as $walker) {
429
            $walker->walkLikeExpression($likeExpr);
430
        }
431
    }
432
433
    /**
434
     * {@inheritdoc}
435
     */
436
    public function walkStateFieldPathExpression($stateFieldPathExpression)
437
    {
438
        foreach ($this->walkers as $walker) {
439
            $walker->walkStateFieldPathExpression($stateFieldPathExpression);
440
        }
441
    }
442
443
    /**
444
     * {@inheritdoc}
445
     */
446
    public function walkComparisonExpression($compExpr)
447
    {
448
        foreach ($this->walkers as $walker) {
449
            $walker->walkComparisonExpression($compExpr);
450
        }
451
    }
452
453
    /**
454
     * {@inheritdoc}
455
     */
456
    public function walkInputParameter($inputParam)
457
    {
458
        foreach ($this->walkers as $walker) {
459
            $walker->walkInputParameter($inputParam);
460
        }
461
    }
462
463
    /**
464
     * {@inheritdoc}
465
     */
466
    public function walkArithmeticExpression($arithmeticExpr)
467
    {
468
        foreach ($this->walkers as $walker) {
469
            $walker->walkArithmeticExpression($arithmeticExpr);
470
        }
471
    }
472
473
    /**
474
     * {@inheritdoc}
475
     */
476
    public function walkArithmeticTerm($term)
477
    {
478
        foreach ($this->walkers as $walker) {
479
            $walker->walkArithmeticTerm($term);
480
        }
481
    }
482
483
    /**
484
     * {@inheritdoc}
485
     */
486
    public function walkStringPrimary($stringPrimary)
487
    {
488
        foreach ($this->walkers as $walker) {
489
            $walker->walkStringPrimary($stringPrimary);
490
        }
491
    }
492
493
    /**
494
     * {@inheritdoc}
495
     */
496
    public function walkArithmeticFactor($factor)
497
    {
498
        foreach ($this->walkers as $walker) {
499
            $walker->walkArithmeticFactor($factor);
500
        }
501
    }
502
503
    /**
504
     * {@inheritdoc}
505
     */
506
    public function walkSimpleArithmeticExpression($simpleArithmeticExpr)
507
    {
508
        foreach ($this->walkers as $walker) {
509
            $walker->walkSimpleArithmeticExpression($simpleArithmeticExpr);
510
        }
511
    }
512
513
    /**
514
     * {@inheritdoc}
515
     */
516
    public function walkPathExpression($pathExpr)
517
    {
518
        foreach ($this->walkers as $walker) {
519
            $walker->walkPathExpression($pathExpr);
520
        }
521
    }
522
523
    /**
524
     * {@inheritdoc}
525
     */
526
    public function walkResultVariable($resultVariable)
527
    {
528
        foreach ($this->walkers as $walker) {
529
            $walker->walkResultVariable($resultVariable);
530
        }
531
    }
532
533
    /**
534
     * {@inheritdoc}
535
     */
536
    public function getExecutor($AST)
537
    {
538
    }
539
}
540