Completed
Push — master ( 9d1ab7...13f027 )
by Luis
04:13 queued 02:19
created

MethodsBuilder::build()   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\Param;
11
use PhpParser\Node\Stmt\ClassMethod;
12
13
/**
14
 * It builds an array with the meta-information of a method
15
 *
16
 * The generated array has the following structure
17
 *
18
 * - name
19
 * - visibility
20
 * - parameters
21
 *    - name
22
 *    - type
23
 * - doc block
24
 *
25
 * You can run one or more filters, the current available filters will exclude
26
 *
27
 * - protected methods
28
 * - private methods
29
 * - both protected and private if both filters are provided
30
 *
31
 * @see PrivateMembersFilter
32
 * @see ProtectedMembersFilter
33
 */
34
class MethodsBuilder extends MembersBuilder
35
{
36
    /** @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\Interface_ $definition */
37
    public function build(array $classMethods): array
38
    {
39 84
        return array_map(function (ClassMethod $method) {
40 66
            return $this->buildMethod($method);
41 84
        }, $this->runFilters($classMethods));
42
    }
43
44 66
    private function buildMethod(ClassMethod $method): array
45
    {
46
        return [
47 66
            $method->name,
48 66
            $this->resolveVisibility($method),
49 66
            $this->buildParameters($method->params),
50 66
            $method->getDocComment(),
51
        ];
52
    }
53
54
    private function buildParameters(array $parameters): array
55
    {
56 66
        return array_map(function (Param $parameter) {
57
            return [
58 57
                "\${$parameter->name}",
59 57
                $parameter->type,
60
            ];
61 66
        }, $parameters);
62
    }
63
}
64