-
-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathClassDescriptionBuilder.php
More file actions
156 lines (118 loc) · 3.33 KB
/
ClassDescriptionBuilder.php
File metadata and controls
156 lines (118 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
declare(strict_types=1);
namespace Arkitect\Analyzer;
use Webmozart\Assert\Assert;
class ClassDescriptionBuilder
{
/** @var list<ClassDependency> */
private $classDependencies = [];
/** @var ?FullyQualifiedClassName */
private $FQCN;
/** @var list<FullyQualifiedClassName> */
private $interfaces = [];
/** @var ?FullyQualifiedClassName */
private $extend;
/** @var bool */
private $final = false;
/** @var bool */
private $abstract = false;
/** @var list<string> */
private $docBlock = [];
/** @var list<FullyQualifiedClassName> */
private $attributes = [];
/** @var bool */
private $interface = false;
/** @var bool */
private $trait = false;
/** @var bool */
private $enum = false;
public function clear(): void
{
$this->FQCN = null;
$this->classDependencies = [];
$this->interfaces = [];
$this->extend = null;
$this->final = false;
$this->abstract = false;
$this->docBlock = [];
$this->attributes = [];
$this->interface = false;
$this->trait = false;
$this->enum = false;
}
public function setClassName(string $FQCN): self
{
$this->FQCN = FullyQualifiedClassName::fromString($FQCN);
return $this;
}
public function addInterface(string $FQCN, int $line): self
{
$this->addDependency(new ClassDependency($FQCN, $line));
$this->interfaces[] = FullyQualifiedClassName::fromString($FQCN);
return $this;
}
public function addDependency(ClassDependency $cd): self
{
$this->classDependencies[] = $cd;
return $this;
}
public function setExtends(string $FQCN, int $line): self
{
$this->addDependency(new ClassDependency($FQCN, $line));
$this->extend = FullyQualifiedClassName::fromString($FQCN);
return $this;
}
public function setFinal(bool $final): self
{
$this->final = $final;
return $this;
}
public function setAbstract(bool $abstract): self
{
$this->abstract = $abstract;
return $this;
}
public function setInterface(bool $interface): self
{
$this->interface = $interface;
return $this;
}
public function setTrait(bool $trait): self
{
$this->trait = $trait;
return $this;
}
public function setEnum(bool $enum): self
{
$this->enum = $enum;
return $this;
}
public function addDocBlock(string $docBlock): self
{
$this->docBlock[] = $docBlock;
return $this;
}
public function addAttribute(string $FQCN, int $line): self
{
$this->addDependency(new ClassDependency($FQCN, $line));
$this->attributes[] = FullyQualifiedClassName::fromString($FQCN);
return $this;
}
public function build(): ClassDescription
{
Assert::notNull($this->FQCN, 'You must set an FQCN');
return new ClassDescription(
$this->FQCN,
$this->classDependencies,
$this->interfaces,
$this->extend,
$this->final,
$this->abstract,
$this->interface,
$this->trait,
$this->enum,
$this->docBlock,
$this->attributes
);
}
}