Completed
Push — master ( 5bda77...cb2c73 )
by Aleh
10s
created

SocketOutput::write()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 3
1
<?php
2
3
namespace Padawan\Framework\Application\Socket;
4
5
use Symfony\Component\Console\Output\OutputInterface;
6
use Symfony\Component\Console\Output\NullOutput;
7
use Amp\Socket\Client;
8
9
/**
10
 * Class SocketOutput
11
 */
12
class SocketOutput extends NullOutput
13
{
14
    public function __construct(Client $client)
15
    {
16
        $this->client = $client;
17
    }
18
19
    public function write($message, $newline = false, $options = 0)
20
    {
21
        if (is_array($message)) {
22
            $message = implode("\n", $message);
23
        }
24
        return $this->client->write($message);
25
    }
26
27
    public function writeln($message, $options = 0)
28
    {
29
        return $this->client->write($message . "\n");
30
    }
31
32
    public function disconnect()
33
    {
34
        return $this->client->close();
35
    }
36
37
    private $client;
38
}
39