| Total Complexity | 7 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | class ResourceOutputStream implements OutputStream |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var resource |
||
| 17 | */ |
||
| 18 | private $stream; |
||
| 19 | |||
| 20 | public function __construct($stream = \STDOUT) |
||
| 21 | { |
||
| 22 | if (!is_resource($stream) || get_resource_type($stream) !== 'stream') { |
||
| 23 | throw new \InvalidArgumentException('Expected a valid stream'); |
||
| 24 | } |
||
| 25 | |||
| 26 | $meta = stream_get_meta_data($stream); |
||
| 27 | if (strpos($meta['mode'], 'r') !== false && strpos($meta['mode'], '+') === false) { |
||
| 28 | throw new \InvalidArgumentException('Expected a writable stream'); |
||
| 29 | } |
||
| 30 | |||
| 31 | $this->stream = $stream; |
||
| 32 | } |
||
| 33 | |||
| 34 | public function write(string $buffer): void |
||
| 35 | { |
||
| 36 | fwrite($this->stream, $buffer); |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Whether the stream is connected to an interactive terminal |
||
| 41 | */ |
||
| 42 | public function isInteractive() : bool |
||
| 45 | } |
||
| 46 | } |
||
| 47 |