Completed
Pull Request — master (#47)
by Povilas
02:04
created

ArgumentExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 34
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A extend() 0 4 1
A ignoreFunc() 0 12 3
1
<?php
2
3
namespace Povils\PHPMND\Extension;
4
5
use PhpParser\Node;
6
use PhpParser\Node\Arg;
7
use PhpParser\Node\Expr\FuncCall;
8
use PhpParser\Node\Name;
9
10
/**
11
 * Class ArgumentExtension
12
 *
13
 * @package Povils\PHPMND\Extension
14
 */
15
class ArgumentExtension implements FunctionAwareExtension
16
{
17
    /**
18
     * @inheritdoc
19
     */
20
    public function getName()
21
    {
22
        return 'argument';
23
    }
24
25
    /**
26
     * @inheritdoc
27
     */
28
    public function extend(Node $node)
29
    {
30
        return $node->getAttribute('parent') instanceof Arg;
31
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36
    public function ignoreFunc(Node $node, array $ignoreFuncs)
37
    {
38
        /** @var FuncCall $funcCallNode */
39
        $funcCallNode = $node->getAttribute('parent')->getAttribute('parent');
40
41
        return
42
            $funcCallNode instanceof FuncCall
43
            &&
44
            $funcCallNode->name instanceof Name
45
            &&
46
            in_array($funcCallNode->name->getLast(), $ignoreFuncs, true);
47
    }
48
}
49