From 2482da9e34222b999c9429d0e79dd4645bf033ef Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Fri, 4 Dec 2020 14:03:25 +0500 Subject: [PATCH] cs fix --- src/Exception/UnopenableStreamException.php | 3 +- src/Exception/UnreadableStreamException.php | 3 +- src/Exception/UnseekableStreamException.php | 3 +- src/Exception/UntellableStreamException.php | 3 +- src/Exception/UnwritableStreamException.php | 3 +- src/Stream.php | 94 +++++++-------------- src/StreamFactory.php | 3 +- 7 files changed, 42 insertions(+), 70 deletions(-) diff --git a/src/Exception/UnopenableStreamException.php b/src/Exception/UnopenableStreamException.php index 9acfde7..14d906c 100644 --- a/src/Exception/UnopenableStreamException.php +++ b/src/Exception/UnopenableStreamException.php @@ -20,4 +20,5 @@ * UnopenableStreamException */ class UnopenableStreamException extends RuntimeException -{} +{ +} diff --git a/src/Exception/UnreadableStreamException.php b/src/Exception/UnreadableStreamException.php index 316435d..2a0b940 100644 --- a/src/Exception/UnreadableStreamException.php +++ b/src/Exception/UnreadableStreamException.php @@ -20,4 +20,5 @@ * UnreadableStreamException */ class UnreadableStreamException extends RuntimeException -{} +{ +} diff --git a/src/Exception/UnseekableStreamException.php b/src/Exception/UnseekableStreamException.php index 6721b3d..8eb424f 100644 --- a/src/Exception/UnseekableStreamException.php +++ b/src/Exception/UnseekableStreamException.php @@ -20,4 +20,5 @@ * UnseekableStreamException */ class UnseekableStreamException extends RuntimeException -{} +{ +} diff --git a/src/Exception/UntellableStreamException.php b/src/Exception/UntellableStreamException.php index 52fac44..bae0974 100644 --- a/src/Exception/UntellableStreamException.php +++ b/src/Exception/UntellableStreamException.php @@ -20,4 +20,5 @@ * UntellableStreamException */ class UntellableStreamException extends RuntimeException -{} +{ +} diff --git a/src/Exception/UnwritableStreamException.php b/src/Exception/UnwritableStreamException.php index 93c4d5c..9e82942 100644 --- a/src/Exception/UnwritableStreamException.php +++ b/src/Exception/UnwritableStreamException.php @@ -20,4 +20,5 @@ * UnwritableStreamException */ class UnwritableStreamException extends RuntimeException -{} +{ +} diff --git a/src/Stream.php b/src/Stream.php index 90a4955..1748dcc 100644 --- a/src/Stream.php +++ b/src/Stream.php @@ -40,8 +40,7 @@ class Stream implements StreamInterface */ public function __construct($resource) { - if (! \is_resource($resource)) - { + if (! \is_resource($resource)) { throw new \InvalidArgumentException('Invalid stream resource'); } @@ -73,8 +72,7 @@ public function detach() */ public function close() : void { - if (! \is_resource($this->resource)) - { + if (! \is_resource($this->resource)) { return; } @@ -92,8 +90,7 @@ public function close() : void */ public function eof() : bool { - if (! \is_resource($this->resource)) - { + if (! \is_resource($this->resource)) { return true; } @@ -111,15 +108,13 @@ public function eof() : bool */ public function tell() : int { - if (! \is_resource($this->resource)) - { + if (! \is_resource($this->resource)) { throw new Exception\UntellableStreamException('Stream is not resourceable'); } $result = \ftell($this->resource); - if (false === $result) - { + if (false === $result) { throw new Exception\UntellableStreamException('Unable to get the stream pointer position'); } @@ -133,8 +128,7 @@ public function tell() : int */ public function isSeekable() : bool { - if (! \is_resource($this->resource)) - { + if (! \is_resource($this->resource)) { return false; } @@ -154,20 +148,17 @@ public function isSeekable() : bool */ public function rewind() : void { - if (! \is_resource($this->resource)) - { + if (! \is_resource($this->resource)) { throw new Exception\UnseekableStreamException('Stream is not resourceable'); } - if (! $this->isSeekable()) - { + if (! $this->isSeekable()) { throw new Exception\UnseekableStreamException('Stream is not seekable'); } $result = \fseek($this->resource, 0, \SEEK_SET); - if (! (0 === $result)) - { + if (! (0 === $result)) { throw new Exception\UnseekableStreamException('Unable to move the stream pointer to beginning'); } } @@ -186,20 +177,17 @@ public function rewind() : void */ public function seek($offset, $whence = \SEEK_SET) : void { - if (! \is_resource($this->resource)) - { + if (! \is_resource($this->resource)) { throw new Exception\UnseekableStreamException('Stream is not resourceable'); } - if (! $this->isSeekable()) - { + if (! $this->isSeekable()) { throw new Exception\UnseekableStreamException('Stream is not seekable'); } $result = \fseek($this->resource, $offset, $whence); - if (! (0 === $result)) - { + if (! (0 === $result)) { throw new Exception\UnseekableStreamException('Unable to move the stream pointer to the given position'); } } @@ -211,8 +199,7 @@ public function seek($offset, $whence = \SEEK_SET) : void */ public function isWritable() : bool { - if (! \is_resource($this->resource)) - { + if (! \is_resource($this->resource)) { return false; } @@ -236,20 +223,17 @@ public function isWritable() : bool */ public function write($string) : int { - if (! \is_resource($this->resource)) - { + if (! \is_resource($this->resource)) { throw new Exception\UnwritableStreamException('Stream is not resourceable'); } - if (! $this->isWritable()) - { + if (! $this->isWritable()) { throw new Exception\UnwritableStreamException('Stream is not writable'); } $result = \fwrite($this->resource, $string); - if (false === $result) - { + if (false === $result) { throw new Exception\UnwritableStreamException('Unable to write to the stream'); } @@ -263,8 +247,7 @@ public function write($string) : int */ public function isReadable() : bool { - if (! \is_resource($this->resource)) - { + if (! \is_resource($this->resource)) { return false; } @@ -286,20 +269,17 @@ public function isReadable() : bool */ public function read($length) : string { - if (! \is_resource($this->resource)) - { + if (! \is_resource($this->resource)) { throw new Exception\UnreadableStreamException('Stream is not resourceable'); } - if (! $this->isReadable()) - { + if (! $this->isReadable()) { throw new Exception\UnreadableStreamException('Stream is not readable'); } $result = \fread($this->resource, $length); - if (false === $result) - { + if (false === $result) { throw new Exception\UnreadableStreamException('Unable to read from the stream'); } @@ -317,20 +297,17 @@ public function read($length) : string */ public function getContents() : string { - if (! \is_resource($this->resource)) - { + if (! \is_resource($this->resource)) { throw new Exception\UnreadableStreamException('Stream is not resourceable'); } - if (! $this->isReadable()) - { + if (! $this->isReadable()) { throw new Exception\UnreadableStreamException('Stream is not readable'); } $result = \stream_get_contents($this->resource); - if (false === $result) - { + if (false === $result) { throw new Exception\UnreadableStreamException('Unable to read remainder of the stream'); } @@ -348,15 +325,13 @@ public function getContents() : string */ public function getMetadata($key = null) { - if (! \is_resource($this->resource)) - { + if (! \is_resource($this->resource)) { return null; } $metadata = \stream_get_meta_data($this->resource); - if (! (null === $key)) - { + if (! (null === $key)) { return $metadata[$key] ?? null; } @@ -374,15 +349,13 @@ public function getMetadata($key = null) */ public function getSize() : ?int { - if (! \is_resource($this->resource)) - { + if (! \is_resource($this->resource)) { return null; } $stats = \fstat($this->resource); - if (false === $stats) - { + if (false === $stats) { return null; } @@ -398,20 +371,15 @@ public function getSize() : ?int */ public function __toString() { - try - { - if ($this->isReadable()) - { - if ($this->isSeekable()) - { + try { + if ($this->isReadable()) { + if ($this->isSeekable()) { $this->rewind(); } return $this->getContents(); } - } - catch (\Throwable $e) - { + } catch (\Throwable $e) { // ignore... } diff --git a/src/StreamFactory.php b/src/StreamFactory.php index 2abc15d..c5f02ed 100644 --- a/src/StreamFactory.php +++ b/src/StreamFactory.php @@ -48,8 +48,7 @@ public function createStreamFromFile(string $filename, string $mode = 'r') : Str // See http://php.net/manual/en/function.fopen.php $resource = @ \fopen($filename, $mode); - if (false === $resource) - { + if (false === $resource) { throw new Exception\UnopenableStreamException( \sprintf('Unable to open file "%s" in mode "%s"', $filename, $mode) );