2222 */
2323abstract class AbstractNode implements Countable
2424{
25- /**
26- * @var string
27- */
28- private $ name ;
29-
30- /**
31- * @var string
32- */
33- private $ pathAsString ;
34-
35- /**
36- * @var array
37- */
38- private $ pathAsArray ;
39-
40- /**
41- * @var AbstractNode
42- */
43- private $ parent ;
44-
45- /**
46- * @var string
47- */
48- private $ id ;
25+ private string $ name ;
26+
27+ private string $ pathAsString ;
28+
29+ private array $ pathAsArray ;
30+
31+ private ?AbstractNode $ parent ;
32+
33+ private string $ id ;
4934
5035 public function __construct (string $ name , self $ parent = null )
5136 {
@@ -55,6 +40,9 @@ public function __construct(string $name, self $parent = null)
5540
5641 $ this ->name = $ name ;
5742 $ this ->parent = $ parent ;
43+
44+ $ this ->processId ();
45+ $ this ->processPath ();
5846 }
5947
6048 public function name (): string
@@ -64,50 +52,16 @@ public function name(): string
6452
6553 public function id (): string
6654 {
67- if ($ this ->id === null ) {
68- $ parent = $ this ->parent ();
69-
70- if ($ parent === null ) {
71- $ this ->id = 'index ' ;
72- } else {
73- $ parentId = $ parent ->id ();
74-
75- if ($ parentId === 'index ' ) {
76- $ this ->id = str_replace (': ' , '_ ' , $ this ->name );
77- } else {
78- $ this ->id = $ parentId . '/ ' . $ this ->name ;
79- }
80- }
81- }
82-
8355 return $ this ->id ;
8456 }
8557
8658 public function pathAsString (): string
8759 {
88- if ($ this ->pathAsString === null ) {
89- if ($ this ->parent === null ) {
90- $ this ->pathAsString = $ this ->name ;
91- } else {
92- $ this ->pathAsString = $ this ->parent ->pathAsString () . DIRECTORY_SEPARATOR . $ this ->name ;
93- }
94- }
95-
9660 return $ this ->pathAsString ;
9761 }
9862
9963 public function pathAsArray (): array
10064 {
101- if ($ this ->pathAsArray === null ) {
102- if ($ this ->parent === null ) {
103- $ this ->pathAsArray = [];
104- } else {
105- $ this ->pathAsArray = $ this ->parent ->pathAsArray ();
106- }
107-
108- $ this ->pathAsArray [] = $ this ;
109- }
110-
11165 return $ this ->pathAsArray ;
11266 }
11367
@@ -248,4 +202,36 @@ abstract public function numberOfTestedMethods(): int;
248202 abstract public function numberOfFunctions (): int ;
249203
250204 abstract public function numberOfTestedFunctions (): int ;
205+
206+ private function processId (): void
207+ {
208+ if ($ this ->parent === null ) {
209+ $ this ->id = 'index ' ;
210+
211+ return ;
212+ }
213+
214+ $ parentId = $ this ->parent ->id ();
215+
216+ if ($ parentId === 'index ' ) {
217+ $ this ->id = str_replace (': ' , '_ ' , $ this ->name );
218+ } else {
219+ $ this ->id = $ parentId . '/ ' . $ this ->name ;
220+ }
221+ }
222+
223+ private function processPath (): void
224+ {
225+ if ($ this ->parent === null ) {
226+ $ this ->pathAsArray = [$ this ];
227+ $ this ->pathAsString = $ this ->name ;
228+
229+ return ;
230+ }
231+
232+ $ this ->pathAsArray = $ this ->parent ->pathAsArray ();
233+ $ this ->pathAsString = $ this ->parent ->pathAsString () . DIRECTORY_SEPARATOR . $ this ->name ;
234+
235+ $ this ->pathAsArray [] = $ this ;
236+ }
251237}
0 commit comments