Passed
Pull Request — 5.0 (#11)
by Luis
11:53 queued 09:06
created

ParsedAttributesBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 8.0
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\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...
11
use PhpParser\Node\Stmt\Property;
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...
12
use PhUml\Code\Attributes\Attribute;
13
use PhUml\Code\UseStatements;
14
use PhUml\Code\Variables\Variable;
15
use PhUml\Parser\Code\Builders\Filters\PrivateVisibilityFilter;
16
use PhUml\Parser\Code\Builders\Filters\ProtectedVisibilityFilter;
17
18
/**
19
 * It builds an array of `Attributes` for a `ClassDefinition` or a `TraitDefinition`
20
 *
21
 * It applies one or more `VisibilityFilter`s
22
 *
23
 * @see PrivateVisibilityFilter
24
 * @see ProtectedVisibilityFilter
25
 */
26
final class ParsedAttributesBuilder implements AttributesBuilder
27
{
28 42
    public function __construct(
29
        private VisibilityBuilder $visibilityBuilder,
30
        private TypeBuilder $typeBuilder,
31
    ) {
32 42
    }
33
34
    /**
35
     * @param Property[] $parsedAttributes
36
     * @return Attribute[]
37
     */
38 31
    public function build(array $parsedAttributes, UseStatements $useStatements): array
39
    {
40 31
        return array_map(function (Property $attribute) use ($useStatements): Attribute {
41 18
            $variable = new Variable(
42 18
                "\${$attribute->props[0]->name}",
43 18
                $this->typeBuilder->fromAttributeType($attribute->type, $attribute->getDocComment(), $useStatements)
44
            );
45 18
            $visibility = $this->visibilityBuilder->build($attribute);
46
47 18
            return new Attribute($variable, $visibility, $attribute->isStatic());
48 31
        }, $parsedAttributes);
49
    }
50
51
    /**
52
     * @param Node\Param[] $promotedProperties
53
     * @return Attribute[]
54
     */
55 20
    public function fromPromotedProperties(array $promotedProperties, UseStatements $useStatements): array
56
    {
57 20
        return array_map(function (Node\Param $param) use ($useStatements): Attribute {
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...
58
            /** @var Node\Expr\Variable $var */
59 9
            $var = $param->var;
60
61
            /** @var string $name */
62 9
            $name = $var->name;
63
64 9
            $type = $this->typeBuilder->fromMethodParameter(
65 9
                $param->type,
66 9
                $param->getDocComment(),
67
                $name,
68
                $useStatements
69
            );
70 9
            $visibility = $this->visibilityBuilder->fromFlags($param->flags);
71
72 9
            return new Attribute(new Variable("\$${name}", $type), $visibility);
73 20
        }, $promotedProperties);
74
    }
75
}
76