Code Duplication    Length = 48-48 lines in 2 locations

src/Reader/SignedCharReader.php 1 location

@@ 18-65 (lines=48) @@
15
 *
16
 * @package GravityMedia\Stream\Reader
17
 */
18
class SignedCharReader
19
{
20
    /**
21
     * @var StreamInterface
22
     */
23
    protected $stream;
24
25
    /**
26
     * Create signed char (8-bit integer) 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 string data from the stream
53
     *
54
     * @throws Exception\IOException    An exception will be thrown for invalid stream resources or when the data could
55
     *                                  not be read
56
     *
57
     * @return int
58
     */
59
    public function read()
60
    {
61
        $data = unpack('c', $this->stream->read(1));
62
63
        return $data[1];
64
    }
65
}
66

src/Reader/UnsignedCharReader.php 1 location

@@ 18-65 (lines=48) @@
15
 *
16
 * @package GravityMedia\Stream\Reader
17
 */
18
class UnsignedCharReader
19
{
20
    /**
21
     * @var StreamInterface
22
     */
23
    protected $stream;
24
25
    /**
26
     * Create unsigned char (8-bit integer) 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 string data from the stream
53
     *
54
     * @throws Exception\IOException    An exception will be thrown for invalid stream resources or when the data could
55
     *                                  not be read
56
     *
57
     * @return int
58
     */
59
    public function read()
60
    {
61
        $data = unpack('C', $this->stream->read(1));
62
63
        return $data[1];
64
    }
65
}
66