Skip to content

Commit 55eaa1f

Browse files
authored
ThrowsScope: better naming (#41)
1 parent 5cc3a4f commit 55eaa1f

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/Rules/ThrowsScope.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,58 +18,58 @@ class ThrowsScope
1818
private const CAUGHT_EXCEPTIONS_ATTRIBUTE = '__CAUGHT_EXCEPTIONS_ATTRIBUTE__';
1919

2020
/**
21-
* @var array<Type|null>
21+
* @var int
2222
*/
23-
private $throwsAnnotationBlock = [];
23+
private $stackIndex = -1;
2424

2525
/**
26-
* @var int
26+
* @var array<Type|null>
2727
*/
28-
private $throwsAnnotationBlockIndex = -1;
28+
private $throwsAnnotationBlockStack = [];
2929

3030
/**
3131
* @var bool[][]
3232
*/
33-
private $usedThrowsAnnotations = [];
33+
private $usedThrowsAnnotationsStack = [];
3434

3535
/**
3636
* @var TryCatch[][]
3737
*/
38-
private $tryCatchQueue = [];
38+
private $tryCatchStack = [];
3939

4040
public function enterToThrowsAnnotationBlock(?Type $type): void
4141
{
42-
$this->throwsAnnotationBlockIndex++;
42+
$this->stackIndex++;
4343

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] = [];
4747
}
4848

4949
/**
5050
* @return string[]
5151
*/
5252
public function exitFromThrowsAnnotationBlock(): array
5353
{
54-
$usedThrowsAnnotations = $this->usedThrowsAnnotations[$this->throwsAnnotationBlockIndex];
54+
$usedThrowsAnnotations = $this->usedThrowsAnnotationsStack[$this->stackIndex];
5555

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]);
5959

60-
$this->throwsAnnotationBlockIndex--;
60+
$this->stackIndex--;
6161

6262
return array_keys($usedThrowsAnnotations);
6363
}
6464

6565
public function enterToTryCatch(TryCatch $tryCatch): void
6666
{
67-
$this->tryCatchQueue[$this->throwsAnnotationBlockIndex][] = $tryCatch;
67+
$this->tryCatchStack[$this->stackIndex][] = $tryCatch;
6868
}
6969

7070
public function exitFromTry(): void
7171
{
72-
array_pop($this->tryCatchQueue[$this->throwsAnnotationBlockIndex]);
72+
array_pop($this->tryCatchStack[$this->stackIndex]);
7373
}
7474

7575
/**
@@ -93,8 +93,8 @@ public function getCaughtExceptions(Name $name): array
9393

9494
private function isExceptionCaught(string $exceptionClassName): bool
9595
{
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];
9898

9999
foreach ($catches->catches as $catch) {
100100
foreach ($catch->types as $type) {
@@ -116,11 +116,11 @@ private function isExceptionCaught(string $exceptionClassName): bool
116116
}
117117
}
118118

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]);
121121
foreach ($throwsExceptionClasses as $throwsExceptionClass) {
122122
if (is_a($exceptionClassName, $throwsExceptionClass, true)) {
123-
$this->usedThrowsAnnotations[$this->throwsAnnotationBlockIndex][$throwsExceptionClass] = true;
123+
$this->usedThrowsAnnotationsStack[$this->stackIndex][$throwsExceptionClass] = true;
124124
return true;
125125
}
126126
}

0 commit comments

Comments
 (0)