Failed Conditions
Pull Request — master (#7272)
by
unknown
12:11
created

TreeWalkerAdapter   C

Complexity

Total Complexity 53

Size/Duplication

Total Lines 402
Duplicated Lines 0 %

Test Coverage

Coverage 12.73%

Importance

Changes 0
Metric Value
dl 0
loc 402
ccs 14
cts 110
cp 0.1273
rs 6.96
c 0
b 0
f 0
wmc 53

52 Methods

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

How to fix   Complexity   

Complex Class

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
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Query;
6
7
use Doctrine\ORM\AbstractQuery;
8
use function array_diff;
9
use function array_keys;
10
11
/**
12
 * An adapter implementation of the TreeWalker interface. The methods in this class
13
 * are empty. This class exists as convenience for creating tree walkers.
14
 */
15
abstract class TreeWalkerAdapter implements TreeWalker
16
{
17
    /**
18
     * The original Query.
19
     *
20
     * @var AbstractQuery
21
     */
22
    private $query;
23
24
    /**
25
     * The ParserResult of the original query that was produced by the Parser.
26
     *
27
     * @var ParserResult
28
     */
29
    private $parserResult;
30
31
    /**
32
     * The query components of the original query (the "symbol table") that was produced by the Parser.
33
     *
34
     * @var mixed[][]
35
     */
36
    private $queryComponents;
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 181
    public function __construct($query, $parserResult, array $queryComponents)
42
    {
43 181
        $this->query           = $query;
44 181
        $this->parserResult    = $parserResult;
45 181
        $this->queryComponents = $queryComponents;
46 181
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 92
    public function getQueryComponents()
52
    {
53 92
        return $this->queryComponents;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 2
    public function setQueryComponent($dqlAlias, array $queryComponent)
60
    {
61 2
        $requiredKeys = ['metadata', 'parent', 'relation', 'map', 'nestingLevel', 'token'];
62
63 2
        if (array_diff($requiredKeys, array_keys($queryComponent))) {
64
            throw QueryException::invalidQueryComponent($dqlAlias);
65
        }
66
67 2
        $this->queryComponents[$dqlAlias] = $queryComponent;
68 2
    }
69
70
    /**
71
     * Retrieves the Query Instance responsible for the current walkers execution.
72
     *
73
     * @return AbstractQuery
74
     */
75 87
    protected function getQuery()
76
    {
77 87
        return $this->query;
78
    }
79
80
    /**
81
     * Retrieves the ParserResult.
82
     *
83
     * @return ParserResult
84
     */
85
    protected function getParserResult()
86
    {
87
        return $this->parserResult;
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function walkSelectStatement(AST\SelectStatement $AST)
94
    {
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100
    public function walkSelectClause($selectClause)
101
    {
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107
    public function walkFromClause($fromClause)
108
    {
109
    }
110
111
    /**
112
     * {@inheritdoc}
113
     */
114
    public function walkFunction($function)
115
    {
116
    }
117
118
    /**
119
     * {@inheritdoc}
120
     */
121
    public function walkOrderByClause($orderByClause)
122
    {
123
    }
124
125
    /**
126
     * {@inheritdoc}
127
     */
128
    public function walkOrderByItem($orderByItem)
129
    {
130
    }
131
132
    /**
133
     * {@inheritdoc}
134
     */
135
    public function walkHavingClause($havingClause)
136
    {
137
    }
138
139
    /**
140
     * {@inheritdoc}
141
     */
142
    public function walkJoin($join)
143
    {
144
    }
145
146
    /**
147
     * {@inheritdoc}
148
     */
149
    public function walkSelectExpression($selectExpression)
150
    {
151
    }
152
153
    /**
154
     * {@inheritdoc}
155
     */
156
    public function walkQuantifiedExpression($qExpr)
157
    {
158
    }
159
160
    /**
161
     * {@inheritdoc}
162
     */
163
    public function walkSubselect($subselect)
164
    {
165
    }
166
167
    /**
168
     * {@inheritdoc}
169
     */
170
    public function walkSubselectFromClause($subselectFromClause)
171
    {
172
    }
173
174
    /**
175
     * {@inheritdoc}
176
     */
177
    public function walkSimpleSelectClause($simpleSelectClause)
178
    {
179
    }
180
181
    /**
182
     * {@inheritdoc}
183
     */
184
    public function walkSimpleSelectExpression($simpleSelectExpression)
185
    {
186
    }
187
188
    /**
189
     * {@inheritdoc}
190
     */
191
    public function walkAggregateExpression($aggExpression)
192
    {
193
    }
194
195
    /**
196
     * {@inheritdoc}
197
     */
198
    public function walkGroupByClause($groupByClause)
199
    {
200
    }
201
202
    /**
203
     * {@inheritdoc}
204
     */
205
    public function walkGroupByItem($groupByItem)
206
    {
207
    }
208
209
    /**
210
     * {@inheritdoc}
211
     */
212
    public function walkUpdateStatement(AST\UpdateStatement $AST)
213
    {
214
    }
215
216
    /**
217
     * {@inheritdoc}
218
     */
219
    public function walkDeleteStatement(AST\DeleteStatement $AST)
220
    {
221
    }
222
223
    /**
224
     * {@inheritdoc}
225
     */
226
    public function walkDeleteClause(AST\DeleteClause $deleteClause)
227
    {
228
    }
229
230
    /**
231
     * {@inheritdoc}
232
     */
233
    public function walkUpdateClause($updateClause)
234
    {
235
    }
236
237
    /**
238
     * {@inheritdoc}
239
     */
240
    public function walkUpdateItem($updateItem)
241
    {
242
    }
243
244
    /**
245
     * {@inheritdoc}
246
     */
247
    public function walkWhereClause($whereClause)
248
    {
249
    }
250
251
    /**
252
     * {@inheritdoc}
253
     */
254
    public function walkConditionalExpression($condExpr)
255
    {
256
    }
257
258
    /**
259
     * {@inheritdoc}
260
     */
261
    public function walkConditionalTerm($condTerm)
262
    {
263
    }
264
265
    /**
266
     * {@inheritdoc}
267
     */
268
    public function walkConditionalFactor($factor)
269
    {
270
    }
271
272
    /**
273
     * {@inheritdoc}
274
     */
275
    public function walkConditionalPrimary($primary)
276
    {
277
    }
278
279
    /**
280
     * {@inheritdoc}
281
     */
282
    public function walkExistsExpression($existsExpr)
283
    {
284
    }
285
286
    /**
287
     * {@inheritdoc}
288
     */
289
    public function walkCollectionMemberExpression($collMemberExpr)
290
    {
291
    }
292
293
    /**
294
     * {@inheritdoc}
295
     */
296
    public function walkEmptyCollectionComparisonExpression($emptyCollCompExpr)
297
    {
298
    }
299
300
    /**
301
     * {@inheritdoc}
302
     */
303
    public function walkNullComparisonExpression($nullCompExpr)
304
    {
305
    }
306
307
    /**
308
     * {@inheritdoc}
309
     */
310
    public function walkInExpression($inExpr)
311
    {
312
    }
313
314
    /**
315
     * {@inheritdoc}
316
     */
317
    public function walkInstanceOfExpression($instanceOfExpr)
318
    {
319
    }
320
321
    /**
322
     * {@inheritdoc}
323
     */
324
    public function walkLiteral($literal)
325
    {
326
    }
327
328
    /**
329
     * {@inheritdoc}
330
     */
331
    public function walkBetweenExpression($betweenExpr)
332
    {
333
    }
334
335
    /**
336
     * {@inheritdoc}
337
     */
338
    public function walkLikeExpression($likeExpr)
339
    {
340
    }
341
342
    /**
343
     * {@inheritdoc}
344
     */
345
    public function walkStateFieldPathExpression($stateFieldPathExpression)
346
    {
347
    }
348
349
    /**
350
     * {@inheritdoc}
351
     */
352
    public function walkComparisonExpression($compExpr)
353
    {
354
    }
355
356
    /**
357
     * {@inheritdoc}
358
     */
359
    public function walkInputParameter($inputParam)
360
    {
361
    }
362
363
    /**
364
     * {@inheritdoc}
365
     */
366
    public function walkArithmeticExpression($arithmeticExpr)
367
    {
368
    }
369
370
    /**
371
     * {@inheritdoc}
372
     */
373
    public function walkArithmeticTerm($term)
374
    {
375
    }
376
377
    /**
378
     * {@inheritdoc}
379
     */
380
    public function walkStringPrimary($stringPrimary)
381
    {
382
    }
383
384
    /**
385
     * {@inheritdoc}
386
     */
387
    public function walkArithmeticFactor($factor)
388
    {
389
    }
390
391
    /**
392
     * {@inheritdoc}
393
     */
394
    public function walkSimpleArithmeticExpression($simpleArithmeticExpr)
395
    {
396
    }
397
398
    /**
399
     * {@inheritdoc}
400
     */
401
    public function walkPathExpression($pathExpr)
402
    {
403
    }
404
405
    /**
406
     * {@inheritdoc}
407
     */
408
    public function walkResultVariable($resultVariable)
409
    {
410
    }
411
412
    /**
413
     * {@inheritdoc}
414
     */
415
    public function getExecutor($AST)
416
    {
417
    }
418
}
419