Skip to content

Commit

Permalink
logic exception
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Jan 8, 2024
1 parent a6105b9 commit dd4ae88
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/StreamWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

use Chevere\Writer\Interfaces\WriterInterface;
use InvalidArgumentException;
use LogicException;
use Psr\Http\Message\StreamInterface;
use RuntimeException;
use Throwable;

/**
Expand Down Expand Up @@ -45,7 +45,7 @@ public function write(string $string): void
try {
$this->stream->write($string);
} catch (Throwable $e) {
throw new RuntimeException(
throw new LogicException(
previous: $e,
message: 'Unable to write provided string'
);
Expand Down
8 changes: 3 additions & 5 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
namespace Chevere\Writer;

use Chevere\Writer\Interfaces\WritersInterface;
use ErrorException;
use InvalidArgumentException;
use LogicException;
use Nyholm\Psr7\Stream;
use Psr\Http\Message\StreamInterface;

Expand All @@ -34,10 +34,8 @@ function streamFor(string $uri, string $mode): StreamInterface
if ($fopen === false) {
$error = error_get_last();

throw new ErrorException(
message: $error['message'] ?? 'An error occured',
code: 0,
severity: $error['type'] ?? 1
throw new LogicException(
$error['message'] ?? 'An error occured',
);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use Chevere\Writer\Writers;
use Chevere\Writer\WritersInstance;
use ErrorException;
use LogicException;
use PHPUnit\Framework\TestCase;
use function Chevere\Writer\streamFor;
use function Chevere\Writer\writers;
Expand All @@ -42,7 +42,7 @@ public function testStreamForError(): void
{
$uri = '404';
$mode = 'r+';
$this->expectException(ErrorException::class);
$this->expectException(LogicException::class);
$this->expectExceptionMessage(
<<<PLAIN
fopen(404): Failed to open stream: No such file or directory
Expand Down

0 comments on commit dd4ae88

Please sign in to comment.