Completed
Push — master ( 579f40...ac2f15 )
by Дмитрий
16s
created

functions.php ➔ generatorHasValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA;
7
8
use PHPSA\Compiler\Expression;
9
use PHPSA\Compiler\Statement;
10
use PhpParser\Node;
11
12
/**
13
 * @param $stmt
14
 * @return Expression|Statement
15
 */
16
function nodeVisitorFactory($stmt, Context $context)
17
{
18 55
    if ($stmt instanceof Node\Stmt) {
19 47
        $visitor = new Statement($stmt, $context);
20 47
        return $visitor;
21
    }
22
23 35
    return $context->getExpressionCompiler()->compile($stmt);
24
}
25
26
/**
27
 * Especial to protect HHVM: exception: Need to call next() first
28
 *
29
 * @param \Generator $generator
30
 * @return bool
31
 */
32
function generatorHasValue(\Generator $generator)
33
{
34 1
    foreach ($generator as $v) {
35 1
        return true;
36 1
    }
37
38 1
    return false;
39
}
40