Passed
Push — dependabot/npm_and_yarn/semant... ( 8258be )
by
unknown
04:40
created

ParametersBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 26
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A build() 0 16 1
1
<?php declare(strict_types=1);
2
/**
3
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
4
 */
5
6
namespace PhUml\Parser\Code\Builders\Members;
7
8
use PhpParser\Comment\Doc;
0 ignored issues
show
Bug introduced by
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...
9
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...
10
use PhUml\Code\Parameters\Parameter;
11
use PhUml\Code\UseStatements;
12
use PhUml\Code\Variables\Variable;
13
14
final class ParametersBuilder
15
{
16 46
    public function __construct(private readonly TypeBuilder $typeBuilder)
17
    {
18
    }
19
20
    /**
21
     * @param Param[] $parameters
22
     * @return Parameter[]
23
     */
24 23
    public function build(array $parameters, ?Doc $methodDocBlock, UseStatements $useStatements): array
25
    {
26 23
        return array_map(function (Param $parameter) use ($methodDocBlock, $useStatements): Parameter {
27
            /** @var \PhpParser\Node\Expr\Variable $parsedParameter Since the parser throws error by default */
28 20
            $parsedParameter = $parameter->var;
29
30
            /** @var string $parameterName Since it's a parameter not a variable */
31 20
            $parameterName = $parsedParameter->name;
32
33 20
            $name = "\${$parameterName}";
34 20
            $type = $parameter->type;
35
36 20
            $typeDeclaration = $this->typeBuilder->fromMethodParameter($type, $methodDocBlock, $name, $useStatements);
37
38 20
            return new Parameter(new Variable($name, $typeDeclaration), $parameter->variadic, $parameter->byRef);
39
        }, $parameters);
40
    }
41
}
42