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

ResolveExpressionTrait::resolveFunctionName()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4.5435

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 9
c 1
b 0
f 1
nc 2
nop 2
dl 0
loc 15
ccs 4
cts 9
cp 0.4444
crap 4.5435
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