Passed
Pull Request — master (#30)
by
unknown
46:28 queued 21:27
created

ParsedPropertiesBuilder::fromPromotedProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

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