Passed
Pull Request — master (#25)
by
unknown
06:49 queued 04:40
created

MembersBuilder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 69
ccs 21
cts 21
cp 1
rs 10
c 1
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A constants() 0 9 1
A properties() 0 14 2
A __construct() 0 6 1
A methods() 0 6 1
A fromPromotedProperties() 0 11 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;
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\ClassConst;
0 ignored issues
show
Bug introduced by
The type PhpParser\Node\Stmt\ClassConst 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 PhpParser\Node\Stmt\ClassMethod;
0 ignored issues
show
Bug introduced by
The type PhpParser\Node\Stmt\ClassMethod 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 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...
12
use PhUml\Code\Methods\Method;
13
use PhUml\Code\Properties\Constant;
14
use PhUml\Code\Properties\Property;
15
use PhUml\Code\UseStatements;
16
use PhUml\Parser\Code\Builders\Members\ConstantsBuilder;
17
use PhUml\Parser\Code\Builders\Members\MethodsBuilder;
18
use PhUml\Parser\Code\Builders\Members\PropertiesBuilder;
19
use PhUml\Parser\Code\Builders\Members\VisibilityFilters;
20
21
/**
22
 * It builds the constants, properties and methods of a definition
23
 *
24
 * @see ConstantsBuilder for more details about the constants creation
25
 * @see PropertiesBuilder for more details about the properties creation
26
 * @see MethodsBuilder for more details about the methods creation
27
 */
28
final class MembersBuilder
29
{
30 48
    public function __construct(
31
        private readonly ConstantsBuilder $constantsBuilder,
32
        private readonly PropertiesBuilder $propertiesBuilder,
33
        private readonly MethodsBuilder $methodsBuilder,
34
        private readonly VisibilityFilters $filters,
35
    ) {
36
    }
37
38
    /**
39
     * @param Node[] $members
40
     * @return Constant[]
41
     */
42 32
    public function constants(array $members): array
43
    {
44
        /** @var ClassConst[] $constants */
45 32
        $constants = array_filter($members, static fn ($property): bool => $property instanceof ClassConst);
46
47
        /** @var ClassConst[] $filteredConstants */
48 32
        $filteredConstants = $this->filters->apply($constants);
49
50 32
        return $this->constantsBuilder->build($filteredConstants);
51
    }
52
53
    /**
54
     * @param Node[] $members
55
     * @return Property[]
56
     */
57 37
    public function properties(array $members, ?ClassMethod $constructor, UseStatements $useStatements): array
58
    {
59 37
        $properties = [];
60 37
        if ($constructor !== null) {
61 24
            $properties = $this->fromPromotedProperties($constructor, $useStatements);
62
        }
63
64
        /** @var ParsedProperty[] $parsedProperties */
65 37
        $parsedProperties = array_filter($members, static fn ($property): bool => $property instanceof ParsedProperty);
66
67
        /** @var ParsedProperty[] $filteredProperties */
68 37
        $filteredProperties = $this->filters->apply($parsedProperties);
69
70 37
        return array_merge($this->propertiesBuilder->build($filteredProperties, $useStatements), $properties);
71
    }
72
73
    /**
74
     * @param ClassMethod[] $methods
75
     * @return Method[]
76
     */
77 36
    public function methods(array $methods, UseStatements $useStatements): array
78
    {
79
        /** @var ClassMethod[] $filteredMethods */
80 36
        $filteredMethods = $this->filters->apply($methods);
81
82 36
        return $this->methodsBuilder->build($filteredMethods, $useStatements);
83
    }
84
85
    /** @return Property[] */
86 24
    private function fromPromotedProperties(ClassMethod $constructor, UseStatements $useStatements): array
87
    {
88 24
        $promotedProperties = array_filter(
89 24
            $constructor->getParams(),
90 24
            static fn (Node\Param $param) => $param->flags !== 0
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...
91
        );
92
93
        /** @var Node\Param[] $filteredPromotedProperties */
94 24
        $filteredPromotedProperties = $this->filters->apply($promotedProperties);
95
96 24
        return $this->propertiesBuilder->fromPromotedProperties($filteredPromotedProperties, $useStatements);
97
    }
98
}
99