Passed
Push — master ( deecf0...b54cbd )
by Luis
03:32
created

MethodsBuilder   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 45
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A buildMethod() 0 7 1
A build() 0 7 2
A resolveVisibility() 0 9 3
A buildParameters() 0 11 2
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\Builders;
9
10
use PhpParser\Node\Stmt\ClassMethod;
11
12
class MethodsBuilder
13
{
14
    /** @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\Interface_ $definition */
15 54
    public function build($definition): array
16
    {
17 54
        $methods = [];
18 54
        foreach ($definition->getMethods() as $method) {
19 36
            $methods[] = $this->buildMethod($method);
20
        }
21 54
        return $methods;
22
    }
23
24 36
    public function buildMethod(ClassMethod $method): array
25
    {
26
        return [
27 36
            $method->name,
28 36
            $this->resolveVisibility($method),
29 36
            $this->buildParameters($method->params),
30 36
            $method->getDocComment(),
31
        ];
32
    }
33
34 36
    private function resolveVisibility(ClassMethod $statement): string
35
    {
36
        switch (true) {
37 36
            case $statement->isPublic():
38 36
                return 'public';
39 27
            case $statement->isPrivate():
40 27
                return 'private';
41
            default:
42 3
                return 'protected';
43
        }
44
    }
45
46 36
    private function buildParameters(array $parameters): array
47
    {
48 36
        $params = [];
49
        /** @var \PhpParser\Node\Param $parameter */
50 36
        foreach ($parameters as $parameter) {
51 36
            $params[] = [
52 36
                $parameter->type,
53 36
                "\${$parameter->name}",
54
            ];
55
        }
56 36
        return $params;
57
    }
58
}
59