Passed
Pull Request — master (#12)
by Aydin
01:54
created

NonBlockingResourceInputStream   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
c 1
b 0
f 0
dl 0
loc 30
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isInteractive() 0 3 1
A read() 0 3 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpSchool\Terminal\IO;
6
7
class NonBlockingResourceInputStream implements InputStream
8
{
9
    /**
10
     * @var InputStream
11
     */
12
    private $innerStream;
13
14
    /**
15
     * @param resource $stream
16
     */
17
    public function __construct($stream = null)
18
    {
19
        $this->innerStream = new ResourceInputStream($stream ?? STDIN);
20
        stream_set_blocking($stream, false);
21
    }
22
23
    /**
24
     * @inheritDoc
25
     */
26
    public function read(int $numBytes, callable $callback): void
27
    {
28
        $this->innerStream->read($numBytes, $callback);
29
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34
    public function isInteractive(): bool
35
    {
36
        return $this->innerStream->isInteractive();
37
    }
38
}
39