Passed
Push — variadic-params-visibility-con... ( ca0a66 )
by Luis
13:54
created

ParametersBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A build() 0 16 1
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 7.2
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\Members;
9
10
use PhpParser\Node\Param;
0 ignored issues
show
Bug introduced by
The type PhpParser\Node\Param was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use PhUml\Code\Methods\MethodDocBlock;
12
use PhUml\Code\Parameters\Parameter;
13
use PhUml\Code\Variables\Variable;
14
15
final class ParametersBuilder
16
{
17
    /** @var TypeBuilder */
18
    private $typeBuilder;
19
20
    public function __construct(TypeBuilder $typeBuilder)
21
    {
22
        $this->typeBuilder = $typeBuilder;
23
    }
24
25
    /**
26
     * @param Param[] $parameters
27
     * @return Parameter[]
28
     */
29
    public function build(array $parameters, MethodDocBlock $methodDocBlock): array
30
    {
31
        return array_map(function (Param $parameter) use ($methodDocBlock): Parameter {
32
            /** @var \PhpParser\Node\Expr\Variable $parsedParameter Since the parser throws error by default */
33
            $parsedParameter = $parameter->var;
34
35
            /** @var string $parameterName Since it's a parameter not a variable */
36
            $parameterName = $parsedParameter->name;
37
38
            $name = "\${$parameterName}";
39
            $type = $parameter->type;
40
41
            $typeDeclaration = $this->typeBuilder->fromMethodParameter($type, $methodDocBlock, $name);
42
43
            return new Parameter(new Variable($name, $typeDeclaration), $parameter->variadic, $parameter->byRef);
44
        }, $parameters);
45
    }
46
}
47