Passed
Push — master ( d09870...716959 )
by Luis
02:38
created

RawClassBuilder::buildInterfaces()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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\Raw\Builders;
9
10
use PhpParser\Node\Name;
11
use PhpParser\Node\Stmt\Class_;
12
use PhUml\Parser\Raw\RawDefinition;
13
14
/**
15
 * It builds an associative array with meta-information of a class
16
 *
17
 * The array has the following structure
18
 *
19
 * - `class` The class name
20
 * - `attributes` The meta-information of the class attributes
21
 * - `methods` The meta-information of the methods of the class
22
 * - `implements` The names of the interfaces it implements, if any
23
 * - `extends` The name of the class it extends, if any
24
 *
25
 * @see AttributesBuilder for more details about the attributes information
26
 * @see MethodsBuilder for more details about the methods information
27
 */
28
class RawClassBuilder
29
{
30
    /** @var AttributesBuilder */
31
    private $attributesBuilder;
32
33
    /** @var MethodsBuilder */
34
    private $methodsBuilder;
35
36 72
    public function __construct(
37
        AttributesBuilder $attributesBuilder = null,
38
        MethodsBuilder $methodsBuilder = null
39
    ) {
40 72
        $this->attributesBuilder = $attributesBuilder ?? new AttributesBuilder();
41 72
        $this->methodsBuilder = $methodsBuilder ?? new MethodsBuilder();
42 72
    }
43
44 48
    public function build(Class_ $class): RawDefinition
45
    {
46 48
        return RawDefinition::class([
47 48
            'class' => $class->name,
48 48
            'attributes' => $this->attributesBuilder->build($class->stmts),
49 48
            'methods' => $this->methodsBuilder->build($class),
50 48
            'implements' => $this->buildInterfaces($class->implements),
51 48
            'extends' => !empty($class->extends) ? end($class->extends->parts) : null,
52
        ]);
53
    }
54
55
    /** @return string[] */
56
    private function buildInterfaces(array $implements): array
57
    {
58 48
        return array_map(function (Name $name) {
59 6
            return $name->getLast();
60 48
        }, $implements);
61
    }
62
}
63