Skip to content

Commit db9559f

Browse files
committed
fix try statement
1 parent 1b3be78 commit db9559f

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

src/StaticAnalysis/ExecutableLinesFindingVisitor.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
use PhpParser\Node\Stmt\Return_;
4646
use PhpParser\Node\Stmt\Switch_;
4747
use PhpParser\Node\Stmt\Throw_;
48-
use PhpParser\Node\Stmt\TryCatch;
4948
use PhpParser\Node\Stmt\Unset_;
5049
use PhpParser\Node\Stmt\While_;
5150
use PhpParser\NodeAbstract;
@@ -325,7 +324,6 @@ private function isExecutable(Node $node): bool
325324
$node instanceof Switch_ ||
326325
$node instanceof Ternary ||
327326
$node instanceof Throw_ ||
328-
$node instanceof TryCatch ||
329327
$node instanceof Unset_ ||
330328
$node instanceof While_;
331329
}

tests/_files/source_with_heavy_indentation.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function variable(): bool
127127
return $v2 === $v3;
128128
}
129129

130-
public function else(): int
130+
public function noElse(): int
131131
{
132132
$res = 0;
133133
if (mt_rand() === 0) {
@@ -141,6 +141,20 @@ public function else(): int
141141
return $res;
142142
}
143143

144+
public function noTry(): int
145+
{
146+
$res = 0;
147+
try {
148+
if (mt_rand() === 0) {
149+
throw new \Exception();
150+
}
151+
} catch (\Exception $e) {
152+
$res = 1;
153+
}
154+
155+
return $res;
156+
}
157+
144158
private static $staticState = 1;
145159
private const CONST_STATE = 1.1;
146160
}

tests/tests/Data/RawCodeCoverageDataTest.php

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -366,28 +366,35 @@ public function testHeavyIndentationIsHandledCorrectly(): void
366366
134,
367367
135,
368368
136,
369-
// line 137 is else statement, not in xdebug output
369+
// line 137 is else statement, not in xdebug output (only if/elseif conditions are covered)
370370
138,
371371
141,
372-
150,
372+
146,
373+
// line 147 is try statement, not in xdebug output (only catch condition is covered)
374+
148,
375+
149,
376+
151,
373377
152,
374-
154,
375-
156,
376-
158,
377-
160,
378-
162,
378+
155,
379379
164,
380380
166,
381381
168,
382-
190,
383-
195,
384-
199,
385-
202,
386-
206,
387-
210,
382+
170,
383+
172,
384+
174,
385+
176,
386+
178,
387+
180,
388+
182,
389+
204,
390+
209,
391+
213,
388392
216,
389393
220,
390-
226,
394+
224,
395+
230,
396+
234,
397+
240,
391398
],
392399
array_keys(RawCodeCoverageData::fromUncoveredFile($file, new ParsingFileAnalyser(true, true))->lineCoverage()[$file])
393400
);

0 commit comments

Comments
 (0)