Completed
Push — master ( 454e04...38876e )
by Marco
21s queued 11s
created

assertValidDefineFunctionCall()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.5386
c 0
b 0
f 0
cc 7
nc 7
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\BetterReflection\Util;
6
7
use PhpParser\Node;
8
use Roave\BetterReflection\Reflection\Exception\InvalidConstantNode;
9
use function count;
10
use function in_array;
11
12
/**
13
 * @internal
14
 */
15
final class ConstantNodeChecker
16
{
17
    /**
18
     * @throws InvalidConstantNode
19
     */
20
    public static function assertValidDefineFunctionCall(Node\Expr\FuncCall $node) : void
21
    {
22
        if (! ($node->name instanceof Node\Name)) {
23
            throw InvalidConstantNode::create($node);
24
        }
25
26
        if ($node->name->toLowerString() !== 'define') {
27
            throw InvalidConstantNode::create($node);
28
        }
29
30
        if (! in_array(count($node->args), [2, 3], true)) {
31
            throw InvalidConstantNode::create($node);
32
        }
33
34
        if (! ($node->args[0]->value instanceof Node\Scalar\String_)) {
35
            throw InvalidConstantNode::create($node);
36
        }
37
38
        $valueNode = $node->args[1]->value;
39
40
        if ($valueNode instanceof Node\Expr\FuncCall) {
41
            throw InvalidConstantNode::create($node);
42
        }
43
44
        if ($valueNode instanceof Node\Expr\Variable) {
45
            throw InvalidConstantNode::create($node);
46
        }
47
    }
48
}
49