Passed
Pull Request — master (#26)
by Luis
23:49 queued 20:47
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
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...
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
{
19 46
    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
     */
30 35
    public function build(array $methods, UseStatements $useStatements): array
31
    {
32 35
        return array_map(
33 35
            fn (ClassMethod $method): Method => $this->buildMethod($method, $useStatements),
34
            $methods
35
        );
36
    }
37
38 23
    private function buildMethod(ClassMethod $method, UseStatements $useStatements): Method
39
    {
40 23
        $name = $method->name->name;
41 23
        $visibility = $this->visibilityBuilder->build($method);
42 23
        $docBlock = $method->getDocComment();
43 23
        $returnType = $this->typeBuilder->fromType($method->returnType, $docBlock, TagName::RETURN, $useStatements);
44 23
        $parameters = $this->parametersBuilder->build($method->params, $docBlock, $useStatements);
45
        return match (true) {
46 23
            $method->isAbstract() => new Method($name, $visibility, $returnType, $parameters, isAbstract: true),
47 23
            $method->isStatic() => new Method($name, $visibility, $returnType, $parameters, isStatic: true),
48 23
            default => new Method($name, $visibility, $returnType, $parameters),
49
        };
50
    }
51
}
52