Total Complexity | 9 |
Total Lines | 54 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
16 | final class Variable implements HasType |
||
17 | { |
||
18 | use WithTypeDeclaration; |
||
19 | |||
20 | /** @var string */ |
||
21 | protected $name; |
||
22 | 189 | ||
23 | public function __construct(string $name, TypeDeclaration $type) |
||
24 | 189 | { |
|
25 | 189 | $this->name = $name; |
|
26 | 189 | $this->type = $type; |
|
27 | } |
||
28 | 117 | ||
29 | /** |
||
30 | 117 | * References to arrays need to have the `[]` removed from their names in order to create |
|
31 | * external definitions with a proper name |
||
32 | * |
||
33 | 57 | * The edges created from these references need to map to the names without the suffix |
|
34 | * |
||
35 | 57 | * @see \PhUml\Parser\Code\ExternalAssociationsResolver::resolveExternalAttributes() |
|
36 | 57 | * @see \PhUml\Parser\Code\ExternalAssociationsResolver::resolveExternalConstructorParameters() |
|
37 | 57 | * @see \PhUml\Graphviz\Builders\EdgesBuilder::addAssociation() |
|
38 | 57 | */ |
|
39 | public function referenceName(): Name |
||
40 | { |
||
41 | $name = $this->isArray() ? $this->arrayTypeName() : $this->typeName(); |
||
42 | if ($name === null) { |
||
43 | throw new BadMethodCallException('This attribute is not a reference to a code definition'); |
||
44 | } |
||
45 | return $name; |
||
46 | } |
||
47 | |||
48 | public function __toString() |
||
49 | { |
||
50 | return sprintf( |
||
51 | '%s%s', |
||
52 | 57 | $this->name, |
|
53 | $this->type->isPresent() ? ": {$this->type}" : '' |
||
54 | 57 | ); |
|
55 | } |
||
56 | |||
57 | 54 | private function typeName(): ?Name |
|
58 | { |
||
59 | 54 | return $this->type->name(); |
|
60 | } |
||
61 | |||
62 | 57 | private function isArray(): bool |
|
63 | { |
||
64 | 57 | return $this->type->isArray(); |
|
65 | } |
||
66 | |||
67 | 3 | private function arrayTypeName(): Name |
|
70 | } |
||
71 | } |
||
72 |