Passed
Push — dependabot/npm_and_yarn/semant... ( 8258be )
by
unknown
04:40
created

TypeResolver   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 40
ccs 16
cts 16
cp 1
rs 10
c 1
b 0
f 0
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A resolveForParameter() 0 12 3
A __construct() 0 2 1
A resolveForReturn() 0 9 3
A resolveForProperty() 0 9 3
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;
7
8
use PhUml\Code\UseStatements;
9
use PhUml\Code\Variables\TypeDeclaration;
10
use PhUml\Parser\Code\Builders\TagType;
11
use PhUml\Parser\Code\Builders\TagTypeFactory;
0 ignored issues
show
Bug introduced by
The type PhUml\Parser\Code\Builders\TagTypeFactory 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
final class TypeResolver
14
{
15 84
    public function __construct(private readonly TagTypeFactory $factory)
16
    {
17
    }
18
19 29
    public function resolveForParameter(
20
        ?string $methodComment,
21
        string $name,
22
        UseStatements $useStatements
23
    ): TypeDeclaration {
24 29
        if ($methodComment === null) {
25 14
            return TypeDeclaration::absent();
26
        }
27
28 29
        $parameterType = $this->factory->parameterTypeFrom($methodComment, $name);
29
30 29
        return $parameterType instanceof TagType ? $parameterType->resolve($useStatements) : TypeDeclaration::absent();
31
    }
32
33 32
    public function resolveForReturn(?string $methodComment, UseStatements $useStatements): TypeDeclaration
34
    {
35 32
        if ($methodComment === null) {
36 19
            return TypeDeclaration::absent();
37
        }
38
39 28
        $returnType = $this->factory->returnTypeFrom($methodComment);
40
41 28
        return $returnType instanceof TagType ? $returnType->resolve($useStatements) : TypeDeclaration::absent();
42
    }
43
44 28
    public function resolveForProperty(?string $propertyComment, UseStatements $useStatements): TypeDeclaration
45
    {
46 28
        if ($propertyComment === null) {
47 18
            return TypeDeclaration::absent();
48
        }
49
50 23
        $propertyType = $this->factory->propertyTypeFrom($propertyComment);
51
52 23
        return $propertyType instanceof TagType ? $propertyType->resolve($useStatements) : TypeDeclaration::absent();
53
    }
54
}
55