Completed
Push — master ( 8d738d...8ee41c )
by Daniel
14:24
created

Writer::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 8
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
/**
3
 * This file is part of the stream package
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Stream\Writer;
9
10
use GravityMedia\Stream\Exception;
11
use GravityMedia\Stream\StreamInterface;
12
13
/**
14
 * Stream writer
15
 *
16
 * @package GravityMedia\Stream\Writer
17
 */
18 View Code Duplication
class Writer
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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