Skip to content

Commit d5aec60

Browse files
committed
Leverage the match expression
1 parent 42eca5c commit d5aec60

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

Exception/ProcessTimedOutException.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,10 @@ public function isIdleTimeout()
5555

5656
public function getExceededTimeout()
5757
{
58-
switch ($this->timeoutType) {
59-
case self::TYPE_GENERAL:
60-
return $this->process->getTimeout();
61-
62-
case self::TYPE_IDLE:
63-
return $this->process->getIdleTimeout();
64-
65-
default:
66-
throw new \LogicException(sprintf('Unknown timeout type "%d".', $this->timeoutType));
67-
}
58+
return match ($this->timeoutType) {
59+
self::TYPE_GENERAL => $this->process->getTimeout(),
60+
self::TYPE_IDLE => $this->process->getIdleTimeout(),
61+
default => throw new \LogicException(sprintf('Unknown timeout type "%d".', $this->timeoutType)),
62+
};
6863
}
6964
}

Tests/NonStopableProcess.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,11 @@
1818
*/
1919
function handleSignal($signal)
2020
{
21-
switch ($signal) {
22-
case \SIGTERM:
23-
$name = 'SIGTERM';
24-
break;
25-
case \SIGINT:
26-
$name = 'SIGINT';
27-
break;
28-
default:
29-
$name = $signal.' (unknown)';
30-
break;
31-
}
21+
$name = match ($signal) {
22+
\SIGTERM => 'SIGTERM',
23+
\SIGINT => 'SIGINT',
24+
default => $signal . ' (unknown)',
25+
};
3226

3327
echo "signal $name\n";
3428
}

0 commit comments

Comments
 (0)