Browse Source

PHPDoc cleanup in ResourceStream and StringStream classes

pull/40/head
Paul Rock 6 years ago
parent
commit
049df4bb4c
  1. 27
      src/Streams/ResourceStream.php
  2. 24
      src/Streams/StringStream.php

27
src/Streams/ResourceStream.php

@ -38,10 +38,10 @@ class ResourceStream implements StreamInterface
} }
/** /**
* @param int $length
* @return string
* @throws \RouterOS\Exceptions\StreamException
* @throws \InvalidArgumentException
* @inheritDoc
*
* @throws \RouterOS\Exceptions\StreamException when length parameter is invalid
* @throws \InvalidArgumentException when the stream have been totally read and read method is called again
*/ */
public function read(int $length): string public function read(int $length): string
{ {
@ -60,17 +60,9 @@ class ResourceStream implements StreamInterface
} }
/** /**
* Writes a string to a stream
*
* Write $length bytes of string, if not mentioned, write all the string
* Must be binary safe (as fread).
* if $length is greater than string length, write all string and return number of writen bytes
* if $length os smaller than string length, remaining bytes are losts.
* @inheritDoc
* *
* @param string $string
* @param int|null $length the numer of bytes to read
* @return int the number of written bytes
* @throws \RouterOS\Exceptions\StreamException
* @throws \RouterOS\Exceptions\StreamException when not possible to write bytes
*/ */
public function write(string $string, int $length = null): int public function write(string $string, int $length = null): int
{ {
@ -89,12 +81,11 @@ class ResourceStream implements StreamInterface
} }
/** /**
* Close stream connection
* @inheritDoc
* *
* @return void
* @throws \RouterOS\Exceptions\StreamException
* @throws \RouterOS\Exceptions\StreamException when not possible to close the stream
*/ */
public function close()
public function close(): void
{ {
$hasBeenClosed = false; $hasBeenClosed = false;

24
src/Streams/StringStream.php

@ -2,6 +2,7 @@
namespace RouterOS\Streams; namespace RouterOS\Streams;
use InvalidArgumentException;
use RouterOS\Interfaces\StreamInterface; use RouterOS\Interfaces\StreamInterface;
use RouterOS\Exceptions\StreamException; use RouterOS\Exceptions\StreamException;
@ -31,18 +32,18 @@ class StringStream implements StreamInterface
$this->buffer = $string; $this->buffer = $string;
} }
/** /**
* {@inheritDoc}
* @inheritDoc
* *
* @throws \InvalidArgumentException when length parameter is invalid
* @throws StreamException when the stream have been tatly red and read methd is called again
* @throws \RouterOS\Exceptions\StreamException
*/ */
public function read(int $length): string public function read(int $length): string
{ {
$remaining = strlen($this->buffer); $remaining = strlen($this->buffer);
if ($length < 0) { if ($length < 0) {
throw new \InvalidArgumentException('Cannot read a negative count of bytes from a stream');
throw new InvalidArgumentException('Cannot read a negative count of bytes from a stream');
} }
if (0 === $remaining) { if (0 === $remaining) {
@ -65,12 +66,9 @@ class StringStream implements StreamInterface
} }
/** /**
* Fake write method, do nothing except return the "writen" length
* @inheritDoc
* *
* @param string $string The string to write
* @param int|null $length the number of characters to write
* @return int number of "writen" bytes
* @throws \InvalidArgumentException on invalid length
* @throws \InvalidArgumentException on invalid length
*/ */
public function write(string $string, int $length = null): int public function write(string $string, int $length = null): int
{ {
@ -79,18 +77,16 @@ class StringStream implements StreamInterface
} }
if ($length < 0) { if ($length < 0) {
throw new \InvalidArgumentException('Cannot write a negative count of bytes');
throw new InvalidArgumentException('Cannot write a negative count of bytes');
} }
return min($length, strlen($string)); return min($length, strlen($string));
} }
/** /**
* Close stream connection
*
* @return void
* @inheritDoc
*/ */
public function close()
public function close(): void
{ {
$this->buffer = ''; $this->buffer = '';
} }

Loading…
Cancel
Save