Skip to content

Commit 4bd5e8d

Browse files
committed
Check else branch as well
1 parent b2c6d83 commit 4bd5e8d

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/Exercise/ThrowAnExpression.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function check(Input $input): ResultInterface
7878
return Failure::fromNameAndReason($this->getName(), 'No ternary statement found');
7979
}
8080

81-
if (!$ternary->if instanceof Throw_) {
81+
if (!$ternary->if instanceof Throw_ && !$ternary->else instanceof Throw_) {
8282
return Failure::fromNameAndReason($this->getName(), 'Ternary does not make use of throw expression');
8383
}
8484

test/Exercise/ThrowAnExpressionTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,12 @@ public function testSuccessfulSolution(): void
8181
$this->assertVerifyWasSuccessful();
8282
$this->assertOutputWasCorrect();
8383
}
84+
85+
public function testSuccessfulSolutionThrowOnElse(): void
86+
{
87+
$this->runExercise('solution-correct-else.php');
88+
89+
$this->assertVerifyWasSuccessful();
90+
$this->assertOutputWasCorrect();
91+
}
8492
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
echo !str_starts_with($_SERVER['REQUEST_URI'], '/forbidden')
4+
? 'Welcome!'
5+
: throw new InvalidArgumentException('Access denied!');

0 commit comments

Comments
 (0)