Skip to content

Commit 2d238aa

Browse files
committed
Refactor ExceptionHandler: streamline constructor with readonly properties and simplify write method logic.
1 parent 6e9e07f commit 2d238aa

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/Cli/ExceptionHandler.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,16 @@
1515

1616
class ExceptionHandler
1717
{
18-
/**
19-
* @var resource
20-
*/
21-
private mixed $outputStream;
18+
public function __construct(
19+
private string|\Exception|\Throwable $e,
20+
private readonly mixed $outputStream = STDERR,
21+
) {}
2222

23-
/**
24-
* @param string|\Exception|\Throwable $e
25-
* @param resource $outputStream
26-
*/
27-
public function __construct(string|\Exception|\Throwable $e, mixed $outputStream = STDERR)
23+
public function write(): void
2824
{
29-
$this->outputStream = $outputStream;
30-
$message = is_string($e) ? $e : (string) $e;
31-
fwrite($this->outputStream, $message . PHP_EOL);
25+
fwrite(
26+
$this->outputStream,
27+
(is_string($this->e) ? $this->e : (string) $this->e) . PHP_EOL
28+
);
3229
}
3330
}

0 commit comments

Comments
 (0)