Completed
Push — master ( d82f0a...49e44e )
by Дмитрий
03:44
created

ResolveExpressionTrait::findReturnStatement()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 4
c 1
b 0
f 1
nc 3
nop 1
dl 0
loc 8
ccs 0
cts 7
cp 0
crap 12
rs 9.4285
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\Analyzer\Helper;
7
8
use PhpParser\Node\Expr\FuncCall;
9
use PhpParser\Node\Stmt\Return_;
10
use PHPSA\Context;
11
12
trait ResolveExpressionTrait
13
{
14
    /**
15
     * @param FuncCall $funcCall
16
     * @param Context $context
17
     * @return string|bool
18
     * @throws \PHPSA\Exception\RuntimeException
19
     */
20 5
    public function resolveFunctionName(FuncCall $funcCall, Context $context)
21
    {
22 5
        $funcNameCompiledExpression = $context->getExpressionCompiler()->compile($funcCall->name);
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $funcNameCompiledExpression exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
23
24 5
        if ($funcNameCompiledExpression->isString() && $funcNameCompiledExpression->isCorrectValue()) {
25 5
            return $funcNameCompiledExpression->getValue();
26
        } else {
27
            $context->debug(
28
                'Unexpected function name type ' . $funcNameCompiledExpression->getType(),
29
                $funcCall->name
30
            );
31
        }
32
33
        return false;
34
    }
35
36
    /**
37
     * @param \PhpParser\Node[] $nodes
38
     * @return \PhpParser\Node\Stmt\Return_
39
     */
40
    private function findReturnStatement(array $nodes)
41
    {
42
        foreach ($nodes as $node) {
43
            if ($node instanceof Return_) {
44
                yield $node;
45
            }
46
        }
47
    }
48
}
49