Completed
Push — master ( dc7a60...9aa4ca )
by Taosikai
11:35
created

LoggerSubscriber::onReceiveMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Spike library
4
 * @author Tao <[email protected]>
5
 */
6
namespace Spike\Client\Subscriber;
7
8
use Slince\Event\Event;
9
use Spike\Client\Application;
10
use Spike\Client\EventStore;
11
use Spike\Logger\Logger;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
/**
15
 * @codeCoverageIgnore
16
 */
17
class LoggerSubscriber extends Subscriber
18
{
19
    /**
20
     * @var Logger
21
     */
22
    protected $logger;
23
24
    public function __construct(Application $client)
25
    {
26
        parent::__construct($client);
27
        $this->logger =  $client->getLogger();
28
    }
29
30
31
    public function getEvents()
32
    {
33
        return [
34
            EventStore::CLIENT_RUN => 'onClientRun',
35
            EventStore::RECEIVE_MESSAGE => 'onReceiveMessage',
36
            EventStore::SOCKET_ERROR => 'onSocketError',
37
            EventStore::CONNECTION_ERROR => 'onConnectionError',
38
            EventStore::CONNECT_TO_SERVER => 'onConnectToServer',
39
        ];
40
    }
41
42
    public function onReceiveMessage(Event $event)
43
    {
44
        $this->logger->info("Received a message:\r\n" . $event->getArgument('message'));
45
    }
46
47
    public function onClientRun(Event $event)
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
48
    {
49
        $this->logger->info("The client is running ...");
50
    }
51
52
    public function onSocketError(Event $event)
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
53
    {
54
        $this->logger->error("Client error.");
55
    }
56
57
    public function onConnectionError(Event $event)
58
    {
59
        $this->logger->warning($event->getArgument('exception')->getMessage());
60
    }
61
62
    public function onConnectToServer(Event $event)
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
63
    {
64
        $this->logger->info("The client has connected to the server.");
65
    }
66
}