Passed
Push — master ( d46d5f...674e23 )
by Luis
44s queued 12s
created

TypeResolver::resolveForAttribute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
nc 3
nop 2
dl 0
loc 9
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 8.0
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
8
namespace PhUml\Parser\Code;
9
10
use PhUml\Code\UseStatements;
11
use PhUml\Code\Variables\TypeDeclaration;
12
use PhUml\Parser\Code\Builders\TagType;
13
use PhUml\Parser\Code\Builders\TagTypeFactory;
14
15
final class TypeResolver
16
{
17
    public function __construct(private TagTypeFactory $factory)
18
    {
19
    }
20
21
    public function resolveForParameter(
22
        ?string $methodComment,
23
        string $name,
24
        UseStatements $useStatements
25
    ): TypeDeclaration {
26
        if ($methodComment === null) {
27
            return TypeDeclaration::absent();
28
        }
29
30
        $parameterType = $this->factory->parameterTypeFrom($methodComment, $name);
31
32
        return $parameterType instanceof TagType ? $parameterType->resolve($useStatements) : TypeDeclaration::absent();
33
    }
34
35
    public function resolveForReturn(?string $methodComment, UseStatements $useStatements): TypeDeclaration
36
    {
37
        if ($methodComment === null) {
38
            return TypeDeclaration::absent();
39
        }
40
41
        $returnType = $this->factory->returnTypeFrom($methodComment);
42
43
        return $returnType instanceof TagType ? $returnType->resolve($useStatements) : TypeDeclaration::absent();
44
    }
45
46
    public function resolveForAttribute(?string $attributeComment, UseStatements $useStatements): TypeDeclaration
47
    {
48
        if ($attributeComment === null) {
49
            return TypeDeclaration::absent();
50
        }
51
52
        $attributeType = $this->factory->attributeTypeFrom($attributeComment);
53
54
        return $attributeType instanceof TagType ? $attributeType->resolve($useStatements) : TypeDeclaration::absent();
55
    }
56
}
57