@@ -18,58 +18,58 @@ class ThrowsScope
18
18
private const CAUGHT_EXCEPTIONS_ATTRIBUTE = '__CAUGHT_EXCEPTIONS_ATTRIBUTE__ ' ;
19
19
20
20
/**
21
- * @var array<Type|null>
21
+ * @var int
22
22
*/
23
- private $ throwsAnnotationBlock = [] ;
23
+ private $ stackIndex = - 1 ;
24
24
25
25
/**
26
- * @var int
26
+ * @var array<Type|null>
27
27
*/
28
- private $ throwsAnnotationBlockIndex = - 1 ;
28
+ private $ throwsAnnotationBlockStack = [] ;
29
29
30
30
/**
31
31
* @var bool[][]
32
32
*/
33
- private $ usedThrowsAnnotations = [];
33
+ private $ usedThrowsAnnotationsStack = [];
34
34
35
35
/**
36
36
* @var TryCatch[][]
37
37
*/
38
- private $ tryCatchQueue = [];
38
+ private $ tryCatchStack = [];
39
39
40
40
public function enterToThrowsAnnotationBlock (?Type $ type ): void
41
41
{
42
- $ this ->throwsAnnotationBlockIndex ++;
42
+ $ this ->stackIndex ++;
43
43
44
- $ this ->throwsAnnotationBlock [$ this ->throwsAnnotationBlockIndex ] = $ type ;
45
- $ this ->usedThrowsAnnotations [$ this ->throwsAnnotationBlockIndex ] = [];
46
- $ this ->tryCatchQueue [$ this ->throwsAnnotationBlockIndex ] = [];
44
+ $ this ->throwsAnnotationBlockStack [$ this ->stackIndex ] = $ type ;
45
+ $ this ->usedThrowsAnnotationsStack [$ this ->stackIndex ] = [];
46
+ $ this ->tryCatchStack [$ this ->stackIndex ] = [];
47
47
}
48
48
49
49
/**
50
50
* @return string[]
51
51
*/
52
52
public function exitFromThrowsAnnotationBlock (): array
53
53
{
54
- $ usedThrowsAnnotations = $ this ->usedThrowsAnnotations [$ this ->throwsAnnotationBlockIndex ];
54
+ $ usedThrowsAnnotations = $ this ->usedThrowsAnnotationsStack [$ this ->stackIndex ];
55
55
56
- unset($ this ->throwsAnnotationBlock [$ this ->throwsAnnotationBlockIndex ]);
57
- unset($ this ->usedThrowsAnnotations [$ this ->throwsAnnotationBlockIndex ]);
58
- unset($ this ->tryCatchQueue [$ this ->throwsAnnotationBlockIndex ]);
56
+ unset($ this ->throwsAnnotationBlockStack [$ this ->stackIndex ]);
57
+ unset($ this ->usedThrowsAnnotationsStack [$ this ->stackIndex ]);
58
+ unset($ this ->tryCatchStack [$ this ->stackIndex ]);
59
59
60
- $ this ->throwsAnnotationBlockIndex --;
60
+ $ this ->stackIndex --;
61
61
62
62
return array_keys ($ usedThrowsAnnotations );
63
63
}
64
64
65
65
public function enterToTryCatch (TryCatch $ tryCatch ): void
66
66
{
67
- $ this ->tryCatchQueue [$ this ->throwsAnnotationBlockIndex ][] = $ tryCatch ;
67
+ $ this ->tryCatchStack [$ this ->stackIndex ][] = $ tryCatch ;
68
68
}
69
69
70
70
public function exitFromTry (): void
71
71
{
72
- array_pop ($ this ->tryCatchQueue [$ this ->throwsAnnotationBlockIndex ]);
72
+ array_pop ($ this ->tryCatchStack [$ this ->stackIndex ]);
73
73
}
74
74
75
75
/**
@@ -93,8 +93,8 @@ public function getCaughtExceptions(Name $name): array
93
93
94
94
private function isExceptionCaught (string $ exceptionClassName ): bool
95
95
{
96
- foreach (array_reverse (array_keys ($ this ->tryCatchQueue [$ this ->throwsAnnotationBlockIndex ])) as $ catchKey ) {
97
- $ catches = $ this ->tryCatchQueue [$ this ->throwsAnnotationBlockIndex ][$ catchKey ];
96
+ foreach (array_reverse (array_keys ($ this ->tryCatchStack [$ this ->stackIndex ])) as $ catchKey ) {
97
+ $ catches = $ this ->tryCatchStack [$ this ->stackIndex ][$ catchKey ];
98
98
99
99
foreach ($ catches ->catches as $ catch ) {
100
100
foreach ($ catch ->types as $ type ) {
@@ -116,11 +116,11 @@ private function isExceptionCaught(string $exceptionClassName): bool
116
116
}
117
117
}
118
118
119
- if ($ this ->throwsAnnotationBlock [$ this ->throwsAnnotationBlockIndex ] !== null ) {
120
- $ throwsExceptionClasses = TypeUtils::getDirectClassNames ($ this ->throwsAnnotationBlock [$ this ->throwsAnnotationBlockIndex ]);
119
+ if ($ this ->throwsAnnotationBlockStack [$ this ->stackIndex ] !== null ) {
120
+ $ throwsExceptionClasses = TypeUtils::getDirectClassNames ($ this ->throwsAnnotationBlockStack [$ this ->stackIndex ]);
121
121
foreach ($ throwsExceptionClasses as $ throwsExceptionClass ) {
122
122
if (is_a ($ exceptionClassName , $ throwsExceptionClass , true )) {
123
- $ this ->usedThrowsAnnotations [$ this ->throwsAnnotationBlockIndex ][$ throwsExceptionClass ] = true ;
123
+ $ this ->usedThrowsAnnotationsStack [$ this ->stackIndex ][$ throwsExceptionClass ] = true ;
124
124
return true ;
125
125
}
126
126
}
0 commit comments