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

ParametersBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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