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

SocketOutput   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 1 Features 2
Metric Value
wmc 5
c 4
b 1
f 2
lcom 1
cbo 2
dl 0
loc 27
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A write() 0 7 2
A writeln() 0 4 1
A disconnect() 0 4 1
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