GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#1)
by Šimon
04:15
created

Visitor::visitInParallel()   D

Complexity

Conditions 17
Paths 1

Size

Total Lines 48
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 31
CRAP Score 17.0087

Importance

Changes 0
Metric Value
dl 0
loc 48
ccs 31
cts 32
cp 0.9688
rs 4.9412
c 0
b 0
f 0
cc 17
eloc 33
nc 1
nop 1
crap 17.0087

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace GraphQL\Language;
3
4
use GraphQL\Language\AST\Node;
5
use GraphQL\Language\AST\NodeKind;
6
use GraphQL\Language\AST\NodeList;
7
use GraphQL\Utils\TypeInfo;
8
9
class VisitorOperation
10
{
11
    public $doBreak;
12
13
    public $doContinue;
14
15
    public $removeNode;
16
}
17
18
/**
19
 * Utility for efficient AST traversal and modification.
20
 *
21
 * `visit()` will walk through an AST using a depth first traversal, calling
22
 * the visitor's enter function at each node in the traversal, and calling the
23
 * leave function after visiting that node and all of it's child nodes.
24
 *
25
 * By returning different values from the enter and leave functions, the
26
 * behavior of the visitor can be altered, including skipping over a sub-tree of
27
 * the AST (by returning false), editing the AST by returning a value or null
28
 * to remove the value, or to stop the whole traversal by returning BREAK.
29
 *
30
 * When using `visit()` to edit an AST, the original AST will not be modified, and
31
 * a new version of the AST with the changes applied will be returned from the
32
 * visit function.
33
 *
34
 *     $editedAST = Visitor::visit($ast, [
35
 *       'enter' => function ($node, $key, $parent, $path, $ancestors) {
36
 *         // return
37
 *         //   null: no action
38
 *         //   Visitor::skipNode(): skip visiting this node
39
 *         //   Visitor::stop(): stop visiting altogether
40
 *         //   Visitor::removeNode(): delete this node
41
 *         //   any value: replace this node with the returned value
42
 *       },
43
 *       'leave' => function ($node, $key, $parent, $path, $ancestors) {
44
 *         // return
45
 *         //   null: no action
46
 *         //   Visitor::stop(): stop visiting altogether
47
 *         //   Visitor::removeNode(): delete this node
48
 *         //   any value: replace this node with the returned value
49
 *       }
50
 *     ]);
51
 *
52
 * Alternatively to providing enter() and leave() functions, a visitor can
53
 * instead provide functions named the same as the [kinds of AST nodes](reference.md#graphqllanguageastnodekind),
54
 * or enter/leave visitors at a named key, leading to four permutations of
55
 * visitor API:
56
 *
57
 * 1) Named visitors triggered when entering a node a specific kind.
58
 *
59
 *     Visitor::visit($ast, [
60
 *       'Kind' => function ($node) {
61
 *         // enter the "Kind" node
62
 *       }
63
 *     ]);
64
 *
65
 * 2) Named visitors that trigger upon entering and leaving a node of
66
 *    a specific kind.
67
 *
68
 *     Visitor::visit($ast, [
69
 *       'Kind' => [
70
 *         'enter' => function ($node) {
71
 *           // enter the "Kind" node
72
 *         }
73
 *         'leave' => function ($node) {
74
 *           // leave the "Kind" node
75
 *         }
76
 *       ]
77
 *     ]);
78
 *
79
 * 3) Generic visitors that trigger upon entering and leaving any node.
80
 *
81
 *     Visitor::visit($ast, [
82
 *       'enter' => function ($node) {
83
 *         // enter any node
84
 *       },
85
 *       'leave' => function ($node) {
86
 *         // leave any node
87
 *       }
88
 *     ]);
89
 *
90
 * 4) Parallel visitors for entering and leaving nodes of a specific kind.
91
 *
92
 *     Visitor::visit($ast, [
93
 *       'enter' => [
94
 *         'Kind' => function($node) {
95
 *           // enter the "Kind" node
96
 *         }
97
 *       },
98
 *       'leave' => [
99
 *         'Kind' => function ($node) {
100
 *           // leave the "Kind" node
101
 *         }
102
 *       ]
103
 *     ]);
104
 */
105
class Visitor
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
106
{
107
    public static $visitorKeys = [
108
        NodeKind::NAME => [],
109
        NodeKind::DOCUMENT => ['definitions'],
110
        NodeKind::OPERATION_DEFINITION => ['name', 'variableDefinitions', 'directives', 'selectionSet'],
111
        NodeKind::VARIABLE_DEFINITION => ['variable', 'type', 'defaultValue'],
112
        NodeKind::VARIABLE => ['name'],
113
        NodeKind::SELECTION_SET => ['selections'],
114
        NodeKind::FIELD => ['alias', 'name', 'arguments', 'directives', 'selectionSet'],
115
        NodeKind::ARGUMENT => ['name', 'value'],
116
        NodeKind::FRAGMENT_SPREAD => ['name', 'directives'],
117
        NodeKind::INLINE_FRAGMENT => ['typeCondition', 'directives', 'selectionSet'],
118
        NodeKind::FRAGMENT_DEFINITION => [
119
            'name',
120
            // Note: fragment variable definitions are experimental and may be changed
121
            // or removed in the future.
122
            'variableDefinitions',
123
            'typeCondition',
124
            'directives',
125
            'selectionSet'
126
        ],
127
128
        NodeKind::INT => [],
129
        NodeKind::FLOAT => [],
130
        NodeKind::STRING => [],
131
        NodeKind::BOOLEAN => [],
132
        NodeKind::NULL => [],
133
        NodeKind::ENUM => [],
134
        NodeKind::LST => ['values'],
135
        NodeKind::OBJECT => ['fields'],
136
        NodeKind::OBJECT_FIELD => ['name', 'value'],
137
        NodeKind::DIRECTIVE => ['name', 'arguments'],
138
        NodeKind::NAMED_TYPE => ['name'],
139
        NodeKind::LIST_TYPE => ['type'],
140
        NodeKind::NON_NULL_TYPE => ['type'],
141
142
        NodeKind::SCHEMA_DEFINITION => ['directives', 'operationTypes'],
143
        NodeKind::OPERATION_TYPE_DEFINITION => ['type'],
144
        NodeKind::SCALAR_TYPE_DEFINITION => ['description', 'name', 'directives'],
145
        NodeKind::OBJECT_TYPE_DEFINITION => ['description', 'name', 'interfaces', 'directives', 'fields'],
146
        NodeKind::FIELD_DEFINITION => ['description', 'name', 'arguments', 'type', 'directives'],
147
        NodeKind::INPUT_VALUE_DEFINITION => ['description', 'name', 'type', 'defaultValue', 'directives'],
148
        NodeKind::INTERFACE_TYPE_DEFINITION => ['description', 'name', 'directives', 'fields'],
149
        NodeKind::UNION_TYPE_DEFINITION => ['description', 'name', 'directives', 'types'],
150
        NodeKind::ENUM_TYPE_DEFINITION => ['description', 'name', 'directives', 'values'],
151
        NodeKind::ENUM_VALUE_DEFINITION => ['description', 'name', 'directives'],
152
        NodeKind::INPUT_OBJECT_TYPE_DEFINITION => ['description', 'name', 'directives', 'fields'],
153
154
        NodeKind::SCALAR_TYPE_EXTENSION => ['name', 'directives'],
155
        NodeKind::OBJECT_TYPE_EXTENSION => ['name', 'interfaces', 'directives', 'fields'],
156
        NodeKind::INTERFACE_TYPE_EXTENSION => ['name', 'directives', 'fields'],
157
        NodeKind::UNION_TYPE_EXTENSION => ['name', 'directives', 'types'],
158
        NodeKind::ENUM_TYPE_EXTENSION => ['name', 'directives', 'values'],
159
        NodeKind::INPUT_OBJECT_TYPE_EXTENSION => ['name', 'directives', 'fields'],
160
161
        NodeKind::DIRECTIVE_DEFINITION => ['description', 'name', 'arguments', 'locations']
162
    ];
163
164
    /**
165
     * Visit the AST (see class description for details)
166
     *
167
     * @api
168
     * @param Node $root
169
     * @param array $visitor
170
     * @param array $keyMap
171
     * @return Node|mixed
172
     * @throws \Exception
173
     */
174 563
    public static function visit($root, $visitor, $keyMap = null)
175
    {
176 563
        $visitorKeys = $keyMap ?: self::$visitorKeys;
177
178 563
        $stack = null;
179 563
        $inArray = $root instanceof NodeList || is_array($root);
0 ignored issues
show
introduced by
The condition is_array($root) is always false.
Loading history...
180 563
        $keys = [$root];
181 563
        $index = -1;
182 563
        $edits = [];
183 563
        $parent = null;
184 563
        $path = [];
185 563
        $ancestors = [];
186 563
        $newRoot = $root;
187
188 563
        $UNDEFINED = null;
189
190
        do {
191 563
            $index++;
192 563
            $isLeaving = $index === count($keys);
193 563
            $key = null;
194 563
            $node = null;
195 563
            $isEdited = $isLeaving && count($edits) !== 0;
196
197 563
            if ($isLeaving) {
198 561
                $key = !$ancestors ? $UNDEFINED : $path[count($path) - 1];
199 561
                $node = $parent;
200 561
                $parent = array_pop($ancestors);
201
202 561
                if ($isEdited) {
203 84
                    if ($inArray) {
204
                        // $node = $node; // arrays are value types in PHP
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
205 76
                        if ($node instanceof NodeList) {
206 76
                            $node = clone $node;
207
                        }
208
                    } else {
209 84
                        $node = clone $node;
210
                    }
211 84
                    $editOffset = 0;
212 84
                    for ($ii = 0; $ii < count($edits); $ii++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
213 84
                        $editKey = $edits[$ii][0];
214 84
                        $editValue = $edits[$ii][1];
215
216 84
                        if ($inArray) {
217 76
                            $editKey -= $editOffset;
218
                        }
219 84
                        if ($inArray && $editValue === null) {
220 4
                            if ($node instanceof NodeList) {
221 4
                                $node->splice($editKey, 1);
222
                            } else {
223
                                array_splice($node, $editKey, 1);
0 ignored issues
show
Bug introduced by
$node of type object|null is incompatible with the type array expected by parameter $input of array_splice(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

223
                                array_splice(/** @scrutinizer ignore-type */ $node, $editKey, 1);
Loading history...
224
                            }
225 4
                            $editOffset++;
226
                        } else {
227 84
                            if ($node instanceof NodeList || is_array($node)) {
228 76
                                $node[$editKey] = $editValue;
229
                            } else {
230 84
                                $node->{$editKey} = $editValue;
231
                            }
232
                        }
233
                    }
234
                }
235 561
                $index = $stack['index'];
236 561
                $keys = $stack['keys'];
237 561
                $edits = $stack['edits'];
238 561
                $inArray = $stack['inArray'];
239 561
                $stack = $stack['prev'];
240
            } else {
241 563
                $key = $parent ? ($inArray ? $index : $keys[$index]) : $UNDEFINED;
242 563
                $node = $parent ? (($parent instanceof NodeList || is_array($parent)) ? $parent[$key] : $parent->{$key}) : $newRoot;
243 563
                if ($node === null || $node === $UNDEFINED) {
244 544
                    continue;
245
                }
246 563
                if ($parent) {
247 548
                    $path[] = $key;
248
                }
249
            }
250
251 563
            $result = null;
252 563
            if (!$node instanceof NodeList && !is_array($node)) {
253 563
                if (!($node instanceof Node)) {
254 2
                    throw new \Exception('Invalid AST Node: ' . json_encode($node));
255
                }
256
257 561
                $visitFn = self::getVisitFn($visitor, $node->kind, $isLeaving);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $visitFn is correct as self::getVisitFn($visito...node->kind, $isLeaving) targeting GraphQL\Language\Visitor::getVisitFn() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
258
259 561
                if ($visitFn) {
260 561
                    $result = call_user_func($visitFn, $node, $key, $parent, $path, $ancestors);
0 ignored issues
show
Bug introduced by
$visitFn of type void is incompatible with the type callable expected by parameter $function of call_user_func(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

260
                    $result = call_user_func(/** @scrutinizer ignore-type */ $visitFn, $node, $key, $parent, $path, $ancestors);
Loading history...
261
262 561
                    if ($result !== null) {
263 149
                        if ($result instanceof VisitorOperation) {
264 7
                            if ($result->doBreak) {
265 2
                                break;
266
                            }
267 5
                            if (!$isLeaving && $result->doContinue) {
268 1
                                array_pop($path);
269 1
                                continue;
270
                            }
271 4
                            if ($result->removeNode) {
272 4
                                $editValue = null;
273
                            }
274
                        } else {
275 142
                            $editValue = $result;
276
                        }
277
278 146
                        $edits[] = [$key, $editValue];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $editValue does not seem to be defined for all execution paths leading up to this point.
Loading history...
279 146
                        if (!$isLeaving) {
280 64
                            if ($editValue instanceof Node) {
281 4
                                $node = $editValue;
282
                            } else {
283 60
                                array_pop($path);
284 60
                                continue;
285
                            }
286
                        }
287
                    }
288
                }
289
            }
290
291 561
            if ($result === null && $isEdited) {
292 76
                $edits[] = [$key, $node];
293
            }
294
295 561
            if ($isLeaving) {
296 561
                array_pop($path);
297
            } else {
298
                $stack = [
299 561
                    'inArray' => $inArray,
300 561
                    'index' => $index,
301 561
                    'keys' => $keys,
302 561
                    'edits' => $edits,
303 561
                    'prev' => $stack
304
                ];
305 561
                $inArray = $node instanceof NodeList || is_array($node);
306
307 561
                $keys = ($inArray ? $node : $visitorKeys[$node->kind]) ?: [];
0 ignored issues
show
Bug introduced by
The property kind does not seem to exist on GraphQL\Language\AST\NodeList.
Loading history...
308 561
                $index = -1;
309 561
                $edits = [];
310 561
                if ($parent) {
311 548
                    $ancestors[] = $parent;
312
                }
313 561
                $parent = $node;
314
            }
315
316 561
        } while ($stack);
317
318 561
        if (count($edits) !== 0) {
319 146
            $newRoot = $edits[0][1];
320
        }
321
322 561
        return $newRoot;
323
    }
324
325
    /**
326
     * Returns marker for visitor break
327
     *
328
     * @api
329
     * @return VisitorOperation
330
     */
331 6
    public static function stop()
332
    {
333 6
        $r = new VisitorOperation();
334 6
        $r->doBreak = true;
335 6
        return $r;
336
    }
337
338
    /**
339
     * Returns marker for skipping current node
340
     *
341
     * @api
342
     * @return VisitorOperation
343
     */
344 176
    public static function skipNode()
345
    {
346 176
        $r = new VisitorOperation();
347 176
        $r->doContinue = true;
348 176
        return $r;
349
    }
350
351
    /**
352
     * Returns marker for removing a node
353
     *
354
     * @api
355
     * @return VisitorOperation
356
     */
357 4
    public static function removeNode()
358
    {
359 4
        $r = new VisitorOperation();
360 4
        $r->removeNode = true;
361 4
        return $r;
362
    }
363
364
    /**
365
     * @param $visitors
366
     * @return array
367
     */
368 519
    static function visitInParallel($visitors)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
369
    {
370 519
        $visitorsCount = count($visitors);
371 519
        $skipping = new \SplFixedArray($visitorsCount);
372
373
        return [
374
            'enter' => function ($node) use ($visitors, $skipping, $visitorsCount) {
375 519
                for ($i = 0; $i < $visitorsCount; $i++) {
376 519
                    if (empty($skipping[$i])) {
377 519
                        $fn = self::getVisitFn($visitors[$i], $node->kind, /* isLeaving */ false);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $fn is correct as self::getVisitFn($visito...i], $node->kind, false) targeting GraphQL\Language\Visitor::getVisitFn() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
378
379 519
                        if ($fn) {
380 459
                            $result = call_user_func_array($fn, func_get_args());
0 ignored issues
show
Bug introduced by
$fn of type void is incompatible with the type callable expected by parameter $function of call_user_func_array(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

380
                            $result = call_user_func_array(/** @scrutinizer ignore-type */ $fn, func_get_args());
Loading history...
381
382 459
                            if ($result instanceof VisitorOperation) {
383 177
                                if ($result->doContinue) {
384 174
                                    $skipping[$i] = $node;
385 3
                                } else if ($result->doBreak) {
386 2
                                    $skipping[$i] = $result;
387 1
                                } else if ($result->removeNode) {
388 177
                                    return $result;
389
                                }
390 414
                            } else if ($result !== null) {
391
                                return $result;
392
                            }
393
                        }
394
                    }
395
                }
396 519
            },
397
            'leave' => function ($node) use ($visitors, $skipping, $visitorsCount) {
398 519
                for ($i = 0; $i < $visitorsCount; $i++) {
399 519
                    if (empty($skipping[$i])) {
400 516
                        $fn = self::getVisitFn($visitors[$i], $node->kind, /* isLeaving */ true);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $fn is correct as self::getVisitFn($visito...$i], $node->kind, true) targeting GraphQL\Language\Visitor::getVisitFn() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
401
402 516
                        if ($fn) {
403 235
                            $result = call_user_func_array($fn, func_get_args());
0 ignored issues
show
Bug introduced by
$fn of type void is incompatible with the type callable expected by parameter $function of call_user_func_array(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

403
                            $result = call_user_func_array(/** @scrutinizer ignore-type */ $fn, func_get_args());
Loading history...
404 235
                            if ($result instanceof VisitorOperation) {
405 12
                                if ($result->doBreak) {
406 2
                                    $skipping[$i] = $result;
407 10
                                } else if ($result->removeNode) {
408 12
                                    return $result;
409
                                }
410 235
                            } else if ($result !== null) {
411 516
                                return $result;
412
                            }
413
                        }
414 178
                    } else if ($skipping[$i] === $node) {
415 174
                        $skipping[$i] = null;
416
                    }
417
                }
418 519
            }
419
        ];
420
    }
421
422
    /**
423
     * Creates a new visitor instance which maintains a provided TypeInfo instance
424
     * along with visiting visitor.
425
     */
426 515
    static function visitWithTypeInfo(TypeInfo $typeInfo, $visitor)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
427
    {
428
        return [
429
            'enter' => function ($node) use ($typeInfo, $visitor) {
430 515
                $typeInfo->enter($node);
431 515
                $fn = self::getVisitFn($visitor, $node->kind, false);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $fn is correct as self::getVisitFn($visitor, $node->kind, false) targeting GraphQL\Language\Visitor::getVisitFn() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
432
433 515
                if ($fn) {
0 ignored issues
show
introduced by
$fn is of type null, thus it always evaluated to false.
Loading history...
434 515
                    $result = call_user_func_array($fn, func_get_args());
435 515
                    if ($result) {
436 1
                        $typeInfo->leave($node);
437 1
                        if ($result instanceof Node) {
438 1
                            $typeInfo->enter($result);
439
                        }
440
                    }
441 515
                    return $result;
442
                }
443 150
                return null;
444 515
            },
445 515
            'leave' => function ($node) use ($typeInfo, $visitor) {
446 515
                $fn = self::getVisitFn($visitor, $node->kind, true);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $fn is correct as self::getVisitFn($visitor, $node->kind, true) targeting GraphQL\Language\Visitor::getVisitFn() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
447 515
                $result = $fn ? call_user_func_array($fn, func_get_args()) : null;
0 ignored issues
show
introduced by
$fn is of type null, thus it always evaluated to false.
Loading history...
448 515
                $typeInfo->leave($node);
449 515
                return $result;
450 515
            }
451
        ];
452
    }
453
454
    /**
455
     * @param $visitor
456
     * @param $kind
457
     * @param $isLeaving
458
     * @return null
459
     */
460 561
    public static function getVisitFn($visitor, $kind, $isLeaving)
461
    {
462 561
        if (!$visitor) {
463 118
            return null;
464
        }
465 561
        $kindVisitor = isset($visitor[$kind]) ? $visitor[$kind] : null;
466
467 561
        if (!$isLeaving && is_callable($kindVisitor)) {
468
            // { Kind() {} }
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
469 445
            return $kindVisitor;
470
        }
471
472 561
        if (is_array($kindVisitor)) {
473 230
            if ($isLeaving) {
474 230
                $kindSpecificVisitor = isset($kindVisitor['leave']) ? $kindVisitor['leave'] : null;
475
            } else {
476 230
                $kindSpecificVisitor = isset($kindVisitor['enter']) ? $kindVisitor['enter'] : null;
477
            }
478
479 230
            if ($kindSpecificVisitor && is_callable($kindSpecificVisitor)) {
480
                // { Kind: { enter() {}, leave() {} } }
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
481 230
                return $kindSpecificVisitor;
482
            }
483 172
            return null;
484
        }
485
486 560
        $visitor += ['leave' => null, 'enter' => null];
487 560
        $specificVisitor = $isLeaving ? $visitor['leave'] : $visitor['enter'];
488
489 560
        if ($specificVisitor) {
490 558
            if (is_callable($specificVisitor)) {
491
                // { enter() {}, leave() {} }
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
492 532
                return $specificVisitor;
493
            }
494 81
            $specificKindVisitor = isset($specificVisitor[$kind]) ? $specificVisitor[$kind] : null;
495
496 81
            if (is_callable($specificKindVisitor)) {
497
                // { enter: { Kind() {} }, leave: { Kind() {} } }
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
498 81
                return $specificKindVisitor;
499
            }
500
        }
501 534
        return null;
502
    }
503
}
504