ParsedPropertiesBuilder::fromPromotedProperties()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

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