|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHP version 7.1 |
|
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\Code; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* It represents a class attribute |
|
12
|
|
|
* |
|
13
|
|
|
* It does not distinguish yet static attributes |
|
14
|
|
|
*/ |
|
15
|
|
|
class Attribute extends Variable |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var Visibility */ |
|
18
|
|
|
private $modifier; |
|
19
|
|
|
|
|
20
|
81 |
|
protected function __construct(string $name, Visibility $modifier, TypeDeclaration $type) |
|
21
|
|
|
{ |
|
22
|
81 |
|
parent::__construct($name, $type); |
|
23
|
81 |
|
$this->modifier = $modifier; |
|
24
|
81 |
|
} |
|
25
|
|
|
|
|
26
|
51 |
|
public static function public(string $name, TypeDeclaration $type = null): Attribute |
|
27
|
|
|
{ |
|
28
|
51 |
|
return new Attribute($name, Visibility::public(), $type ?? TypeDeclaration::absent()); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
42 |
|
public static function protected(string $name, TypeDeclaration $type = null): Attribute |
|
32
|
|
|
{ |
|
33
|
42 |
|
return new Attribute($name, Visibility::protected(), $type ?? TypeDeclaration::absent()); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
60 |
|
public static function private(string $name, TypeDeclaration $type = null): Attribute |
|
37
|
|
|
{ |
|
38
|
60 |
|
return new Attribute($name, Visibility::private(), $type ?? TypeDeclaration::absent()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
12 |
|
public function isTyped(): bool |
|
42
|
|
|
{ |
|
43
|
12 |
|
return $this->type->isPresent(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
12 |
|
public function hasVisibility(Visibility $modifier): bool |
|
47
|
|
|
{ |
|
48
|
12 |
|
return $this->modifier()->equals($modifier); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
21 |
|
public function modifier(): Visibility |
|
52
|
|
|
{ |
|
53
|
21 |
|
return $this->modifier; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* It doesn't currently support information type |
|
58
|
|
|
* |
|
59
|
|
|
* @see GraphvizProcessor#getClassDefinition In its original version |
|
60
|
|
|
*/ |
|
61
|
24 |
|
public function __toString() |
|
62
|
|
|
{ |
|
63
|
24 |
|
return sprintf('%s%s', $this->modifier, $this->name); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|