Passed
Pull Request — master (#23)
by
unknown
13:36 queued 10:51
created

ParsedMethodsBuilder::buildMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

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