Passed
Push — variadic-params-visibility-con... ( ca0a66 )
by Luis
13:54
created

TypeBuilder::fromMethodParameter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 3
dl 0
loc 7
rs 10
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 7.2
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\Builders\Members;
9
10
use PhpParser\Node\Identifier;
0 ignored issues
show
Bug introduced by
The type PhpParser\Node\Identifier 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...
11
use PhpParser\Node\Name;
0 ignored issues
show
Bug introduced by
The type PhpParser\Node\Name 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
use PhpParser\Node\NullableType;
0 ignored issues
show
Bug introduced by
The type PhpParser\Node\NullableType 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...
13
use PhpParser\Node\UnionType;
0 ignored issues
show
Bug introduced by
The type PhpParser\Node\UnionType 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...
14
use PhUml\Code\Methods\MethodDocBlock;
15
use PhUml\Code\Variables\TypeDeclaration;
16
17
final class TypeBuilder
18
{
19
    /** @param Identifier|Name|NullableType|UnionType|null $type */
20
    public function fromMethodParameter($type, MethodDocBlock $docBlock, string $name): TypeDeclaration
21
    {
22
        if ($type === null) {
23
            return $docBlock->typeOfParameter($name);
24
        }
25
26
        return $this->fromParsedType($type);
27
    }
28
29
    /** @param Identifier|Name|NullableType|UnionType|null $type */
30
    public function fromMethodReturnType($type, MethodDocBlock $docBlock): TypeDeclaration
31
    {
32
        if ($type === null) {
33
            return $docBlock->returnType();
34
        }
35
36
        return $this->fromParsedType($type);
37
    }
38
39
    /** @param Identifier|Name|NullableType|UnionType|null $type */
40
    private function fromParsedType($type): TypeDeclaration
41
    {
42
        if ($type instanceof NullableType) {
43
            return TypeDeclaration::fromNullable((string) $type->type);
44
        }
45
46
        if ($type instanceof Name) {
47
            return TypeDeclaration::from($type->getLast());
48
        }
49
50
        if ($type instanceof Identifier) {
51
            return TypeDeclaration::from((string) $type);
52
        }
53
54
        throw UnsupportedType::declaredAs($type);
55
    }
56
}
57