Completed
Pull Request — master (#25)
by Alexander
02:46
created

GeneratorDetector::enterNode()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 9.2
cc 4
eloc 6
nc 3
nop 1
crap 4
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 1
    public function enterNode(Node $node)
28
    {
29
        // There may be internal generators in closures, we do not need to look at them
30 1
        if ($node instanceof Node\Expr\Closure) {
31 1
            return NodeTraverser::DONT_TRAVERSE_CHILDREN;
32
        }
33
34 1
        if ($node instanceof Node\Expr\Yield_ || $node instanceof Node\Expr\YieldFrom) {
35 1
            $this->isGenerator = true;
36
        }
37
38 1
        return null;
39
    }
40
41
    /**
42
     * Returns the
43
     *
44
     * @return bool
45
     */
46 1
    public function isGenerator()
47
    {
48 1
        return $this->isGenerator;
49
    }
50
}
51