InterfaceParser   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 43
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A parse() 0 16 4
A parseMethod() 0 3 1
1
<?php
2
3
namespace Padawan\Parser;
4
5
use Padawan\Domain\Project\FQN;
6
use Padawan\Domain\Project\FQCN;
7
use Padawan\Domain\Project\Node\InterfaceData;
8
use PhpParser\Node\Stmt\Interface_;
9
use PhpParser\Node\Stmt\ClassMethod;
10
11
class InterfaceParser {
12
13
    public function __construct(
14
        MethodParser $methodParser,
15
        UseParser $useParser
16
    ) {
17
        $this->methodParser = $methodParser;
18
        $this->useParser    = $useParser;
19
    }
20
21
    /**
22
     * Parses Interface node to InterfaceData
23
     *
24
     * @return InterfaceData
25
     */
26
    public function parse(Interface_ $node, FQN $fqn, $file)
27
    {
28
        $fqcn = new FQCN($node->name, $fqn);
29
        $interface = new InterfaceData($fqcn, $file);
30
        foreach ($node->extends AS $interfaceName) {
31
            $interface->addInterface(
32
                $this->useParser->getFQCN($interfaceName)
33
            );
34
        }
35
        foreach ($node->stmts AS $child) {
36
            if ($child instanceof ClassMethod) {
37
                $interface->addMethod($this->parseMethod($child));
38
            }
39
        }
40
        return $interface;
41
    }
42
43
    protected function parseMethod(ClassMethod $node) {
44
        return $this->methodParser->parse($node);
45
    }
46
47
    /** @var UseParser */
48
    private $useParser;
49
    /**
50
     * @property MethodParser
51
     */
52
    private $methodParser;
53
}
54