Passed
Push — master ( f58add...4aa999 )
by Luis
54s queued 13s
created

Parser/Code/Builders/Members/ParametersBuilder.php (1 issue)

Labels
Severity
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 7.4
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\Comment\Doc;
0 ignored issues
show
The type PhpParser\Comment\Doc 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 PhpParser\Node\Param;
12
use PhUml\Code\Parameters\Parameter;
13
use PhUml\Code\Variables\Variable;
14
15
final class ParametersBuilder
16
{
17
    private TypeBuilder $typeBuilder;
18
19
    public function __construct(TypeBuilder $typeBuilder)
20
    {
21
        $this->typeBuilder = $typeBuilder;
22
    }
23
24
    /**
25
     * @param Param[] $parameters
26
     * @return Parameter[]
27
     */
28
    public function build(array $parameters, ?Doc $methodDocBlock): array
29
    {
30
        return array_map(function (Param $parameter) use ($methodDocBlock): Parameter {
31
            /** @var \PhpParser\Node\Expr\Variable $parsedParameter Since the parser throws error by default */
32
            $parsedParameter = $parameter->var;
33
34
            /** @var string $parameterName Since it's a parameter not a variable */
35
            $parameterName = $parsedParameter->name;
36
37
            $name = "\${$parameterName}";
38
            $type = $parameter->type;
39
40
            $typeDeclaration = $this->typeBuilder->fromMethodParameter($type, $methodDocBlock, $name);
41
42
            return new Parameter(new Variable($name, $typeDeclaration), $parameter->variadic, $parameter->byRef);
43
        }, $parameters);
44
    }
45
}
46