GeneratorDetector   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 31
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A enterNode() 0 13 4
A isGenerator() 0 4 1
1
<?php
2
/**
3
 * Parser Reflection API
4
 *
5
 * @copyright Copyright 2015, Lisachenko Alexander <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Go\ParserReflection\NodeVisitor;
12
13
use PhpParser\Node;
14
use PhpParser\NodeTraverser;
15
use PhpParser\NodeVisitorAbstract;
16
17
/**
18
 * Visitor to check if the method body
19
 */
20
class GeneratorDetector extends NodeVisitorAbstract
21
{
22
    private $isGenerator = false;
23
24
    /**
25
     * {@inheritDoc}
26
     */
27 9
    public function enterNode(Node $node)
28
    {
29
        // There may be internal generators in closures, we do not need to look at them
30 9
        if ($node instanceof Node\Expr\Closure) {
31 1
            return NodeTraverser::DONT_TRAVERSE_CHILDREN;
32
        }
33
34 9
        if ($node instanceof Node\Expr\Yield_ || $node instanceof Node\Expr\YieldFrom) {
35 1
            $this->isGenerator = true;
36
        }
37
38 9
        return null;
39
    }
40
41
    /**
42
     * Returns the
43
     *
44
     * @return bool
45
     */
46 64
    public function isGenerator()
47
    {
48 64
        return $this->isGenerator;
49
    }
50
}
51