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

ParsedMethodsBuilder::buildMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 2
dl 0
loc 11
ccs 8
cts 8
cp 1
crap 1
rs 9.9666
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\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...
9
use PhUml\Code\Methods\Method;
10
use PhUml\Code\UseStatements;
11
use PhUml\Parser\Code\Builders\TagName;
12
13
/**
14
 * It builds an array with `Method`s for a `ClassDefinition`, an `InterfaceDefinition` or a
15
 * `TraitDefinition`
16
 */
17
final class ParsedMethodsBuilder implements MethodsBuilder
18 45
{
19
    public function __construct(
20
        private readonly ParametersBuilder $parametersBuilder,
21
        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...
22
        private readonly VisibilityBuilder $visibilityBuilder,
23
    ) {
24
    }
25
26
    /**
27
     * @param ClassMethod[] $methods
28
     * @return Method[]
29 34
     */
30
    public function build(array $methods, UseStatements $useStatements): array
31 34
    {
32 34
        return array_map(
33
            fn (ClassMethod $method): Method => $this->buildMethod($method, $useStatements),
34
            $methods
35
        );
36
    }
37 22
38
    private function buildMethod(ClassMethod $method, UseStatements $useStatements): Method
39 22
    {
40 22
        $name = $method->name->name;
41 22
        $visibility = $this->visibilityBuilder->build($method);
42 22
        $docBlock = $method->getDocComment();
43 22
        $returnType = $this->typeBuilder->fromType($method->returnType, $docBlock, TagName::RETURN, $useStatements);
44
        $parameters = $this->parametersBuilder->build($method->params, $docBlock, $useStatements);
45 22
        return match (true) {
46 22
            $method->isAbstract() => new Method($name, $visibility, $returnType, $parameters, isAbstract: true),
47 22
            $method->isStatic() => new Method($name, $visibility, $returnType, $parameters, isStatic: true),
48
            default => new Method($name, $visibility, $returnType, $parameters),
49
        };
50
    }
51
}
52