Passed
Pull Request — master (#23)
by
unknown
13:36 queued 10:51
created

ParsedPropertiesBuilder::fromPromotedProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 2
dl 0
loc 19
ccs 9
cts 9
cp 1
crap 1
rs 9.9
c 0
b 0
f 0
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\Node;
0 ignored issues
show
Bug introduced by
The type PhpParser\Node 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\Stmt\Property as ParsedProperty;
0 ignored issues
show
Bug introduced by
The type PhpParser\Node\Stmt\Property 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\Properties\Property;
11
use PhUml\Code\UseStatements;
12
use PhUml\Code\Variables\Variable;
13
14
/**
15
 * It builds an array of `Property` for a `ClassDefinition` or a `TraitDefinition`
16
 */
17
final class ParsedPropertiesBuilder implements PropertiesBuilder
18
{
19 43
    public function __construct(
20
        private readonly VisibilityBuilder $visibilityBuilder,
21
        private readonly TypeBuilder $typeBuilder,
22
    ) {
23
    }
24
25
    /**
26
     * @param ParsedProperty[] $parsedProperties
27
     * @return Property[]
28
     */
29 32
    public function build(array $parsedProperties, UseStatements $useStatements): array
30
    {
31 32
        return array_map(function (ParsedProperty $property) use ($useStatements): Property {
32 18
            $variable = new Variable(
33 18
                "\${$property->props[0]->name}",
34 18
                $this->typeBuilder->fromPropertyType($property->type, $property->getDocComment(), $useStatements)
35
            );
36 18
            $visibility = $this->visibilityBuilder->build($property);
37
38 18
            return new Property($variable, $visibility, $property->isStatic());
39
        }, $parsedProperties);
40
    }
41
42
    /**
43
     * @param Node\Param[] $promotedProperties
44
     * @return Property[]
45
     */
46 20
    public function fromPromotedProperties(array $promotedProperties, UseStatements $useStatements): array
47
    {
48 20
        return array_map(function (Node\Param $param) use ($useStatements): Property {
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...
49
            /** @var Node\Expr\Variable $var */
50 9
            $var = $param->var;
51
52
            /** @var string $name */
53 9
            $name = $var->name;
54
55 9
            $type = $this->typeBuilder->fromMethodParameter(
56 9
                $param->type,
57 9
                $param->getDocComment(),
58
                $name,
59
                $useStatements
60
            );
61 9
            $visibility = $this->visibilityBuilder->fromFlags($param->flags);
62
63 9
            return new Property(new Variable("\$${name}", $type), $visibility);
64
        }, $promotedProperties);
65
    }
66
}
67