Passed
Push — 1.5 ( c7c5a4...fe8795 )
by Luis
06:06
created

InterfaceDefinitionBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A buildParents() 0 5 1
A build() 0 7 1
A __construct() 0 6 1
1
<?php
2
/**
3
 * PHP version 7.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
8
namespace PhUml\Parser\Code\Builders;
9
10
use PhpParser\Node\Name;
11
use PhpParser\Node\Stmt\Interface_;
12
use PhUml\Code\InterfaceDefinition;
13
use PhUml\Code\Name as InterfaceDefinitionName;
14
use PhUml\Parser\Code\Builders\Members\ConstantsBuilder;
15
use PhUml\Parser\Code\Builders\Members\MethodsBuilder;
16
17
/**
18
 * It builds an `InterfaceDefinition`
19
 *
20
 * @see ConstantsBuilder for more details about the constants creation
21
 * @see MethodsBuilder for more details about the methods creation
22
 */
23
class InterfaceDefinitionBuilder
24
{
25
    /** @var MethodsBuilder */
26
    private $methodsBuilder;
27
28
    /** @var ConstantsBuilder */
29
    private $constantsBuilder;
30
31 129
    public function __construct(
32
        ConstantsBuilder $constantsBuilder = null,
33
        MethodsBuilder $methodsBuilder = null
34
    ) {
35 129
        $this->constantsBuilder = $constantsBuilder ?? new ConstantsBuilder();
36 129
        $this->methodsBuilder = $methodsBuilder ?? new MethodsBuilder();
37 129
    }
38
39 48
    public function build(Interface_ $interface): InterfaceDefinition
40
    {
41 48
        return new InterfaceDefinition(
42 48
            InterfaceDefinitionName::from($interface->name),
0 ignored issues
show
Bug introduced by
It seems like $interface->name can also be of type null; however, parameter $text of PhUml\Code\Name::from() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

42
            InterfaceDefinitionName::from(/** @scrutinizer ignore-type */ $interface->name),
Loading history...
43 48
            $this->constantsBuilder->build($interface->stmts),
44 48
            $this->methodsBuilder->build($interface->getMethods()),
45 48
            $this->buildParents($interface)
46
        );
47
    }
48
49
    /** @return InterfaceDefinitionName[] */
50
    protected function buildParents(Interface_ $interface): array
51
    {
52 48
        return array_map(function (Name $name) {
53 6
            return InterfaceDefinitionName::from($name->getLast());
54 48
        }, $interface->extends);
55
    }
56
}
57