Skip to content

Commit

Permalink
[BUGFIX] Throw exception for invalid options
Browse files Browse the repository at this point in the history
  • Loading branch information
mteu committed Sep 13, 2024
1 parent 5251a6d commit c6b9dd4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Classes/Config/LogLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
namespace mteu\StreamWriter\Config;

/**
* LogLevel.
*
* @author Martin Adler <[email protected]>
* @license GPL-3.0-or-later
*
* @codeCoverageIgnore
*/
enum LogLevel: string
Expand Down
2 changes: 1 addition & 1 deletion Classes/Exception/InvalidLogWriterOptionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace mteu\StreamWriter\Exception;

/**
* InvalidOptionException.
* InvalidLogWriterOptionException.
*
* @author Martin Adler <[email protected]>
* @license GPL-3.0-or-later
Expand Down
7 changes: 4 additions & 3 deletions Classes/Writer/StreamWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use mteu\StreamWriter\Config\LogLevel;
use mteu\StreamWriter\Config\StandardStream;
use mteu\StreamWriter\Exception\InvalidLogWriterConfigurationException;
use mteu\StreamWriter\Exception\InvalidLogWriterOptionException;
use TYPO3\CMS\Core\Log\LogRecord;
use TYPO3\CMS\Core\Log\Writer\AbstractWriter;
use TYPO3\CMS\Core\Log\Writer\WriterInterface;
Expand Down Expand Up @@ -57,7 +58,7 @@ final class StreamWriter extends AbstractWriter

/**
* @param array{outputStream: StandardStream} $options
* @throws InvalidLogWriterConfigurationException
* @throws InvalidLogWriterConfigurationException|\TYPO3\CMS\Core\Log\Exception\InvalidLogWriterConfigurationException
*/
public function __construct(array $options = ['outputStream' => StandardStream::Error])
{
Expand All @@ -70,15 +71,15 @@ public function __construct(array $options = ['outputStream' => StandardStream::

/**
* @return LogLevel|StandardStream|class-string[]
* @throws InvalidLogWriterConfigurationException
* @throws InvalidLogWriterOptionException
*/
public function getOption(string $option): array|LogLevel|StandardStream
{
return match ($option) {
'outputStream' => $this->outputStream,
'maxLevel' => $this->maxLevel,
'ignoredComponents' => $this->ignoredComponents,
default => throw new InvalidLogWriterConfigurationException(
default => throw new InvalidLogWriterOptionException(
'Option ' . $option . ' does not exist.',
1726173519
),
Expand Down

0 comments on commit c6b9dd4

Please sign in to comment.