Code Duplication    Length = 45-45 lines in 2 locations

src/Reader/Reader.php 1 location

@@ 18-62 (lines=45) @@
15
 *
16
 * @package GravityMedia\Stream\Reader
17
 */
18
class Reader
19
{
20
    /**
21
     * @var StreamInterface
22
     */
23
    protected $stream;
24
25
    /**
26
     * Create reader object
27
     *
28
     * @throws Exception\InvalidArgumentException An exception will be thrown for non-readable streams
29
     *
30
     * @param StreamInterface $stream
31
     */
32
    public function __construct(StreamInterface $stream)
33
    {
34
        if (!$stream->isReadable()) {
35
            throw new Exception\InvalidArgumentException('Stream not readable');
36
        }
37
38
        $this->stream = $stream;
39
    }
40
41
    /**
42
     * Get stream
43
     *
44
     * @return StreamInterface
45
     */
46
    public function getStream()
47
    {
48
        return $this->stream;
49
    }
50
51
    /**
52
     * Read up to $length number of bytes of data from the stream
53
     *
54
     * @param int $length The maximum number of bytes to read
55
     *
56
     * @return string
57
     */
58
    public function read($length)
59
    {
60
        return $this->getStream()->read($length);
61
    }
62
}
63

src/Writer/Writer.php 1 location

@@ 18-62 (lines=45) @@
15
 *
16
 * @package GravityMedia\Stream\Writer
17
 */
18
class Writer
19
{
20
    /**
21
     * @var StreamInterface
22
     */
23
    protected $stream;
24
25
    /**
26
     * Create writer object
27
     *
28
     * @throws Exception\InvalidArgumentException An exception will be thrown for non-writable streams
29
     *
30
     * @param StreamInterface $stream
31
     */
32
    public function __construct(StreamInterface $stream)
33
    {
34
        if (!$stream->isWritable()) {
35
            throw new Exception\InvalidArgumentException('Stream not writable');
36
        }
37
38
        $this->stream = $stream;
39
    }
40
41
    /**
42
     * Get stream
43
     *
44
     * @return StreamInterface
45
     */
46
    public function getStream()
47
    {
48
        return $this->stream;
49
    }
50
51
    /**
52
     * Write data to the stream and return the number of bytes written
53
     *
54
     * @param string $data The data
55
     *
56
     * @return int
57
     */
58
    public function write($data)
59
    {
60
        return $this->getStream()->write($data);
61
    }
62
}
63