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

ResolveExpressionTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 25%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 37
ccs 4
cts 16
cp 0.25
rs 10
wmc 6
lcom 0
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolveFunctionName() 0 15 3
A findReturnStatement() 0 8 3
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