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

LoggerSubscriber   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 0
cbo 4
dl 0
loc 50
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getEvents() 0 10 1
A onReceiveMessage() 0 4 1
A onClientRun() 0 4 1
A onSocketError() 0 4 1
A onConnectionError() 0 4 1
A onConnectToServer() 0 4 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
}