Completed
Push — master ( ca93ac...3df503 )
by Taosikai
11:49
created

LoggerSubscriber::onAuthError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
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
13
/**
14
 * @codeCoverageIgnore
15
 */
16
class LoggerSubscriber extends Subscriber
17
{
18
    /**
19
     * @var Logger
20
     */
21
    protected $logger;
22
23
    public function __construct(Application $client)
24
    {
25
        parent::__construct($client);
26
        $this->logger =  $client->getLogger();
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function getEvents()
33
    {
34
        return [
35
            EventStore::CLIENT_RUN => 'onClientRun',
36
            EventStore::CONNECT_TO_SERVER => 'onConnectToServer',
37
            EventStore::CANNOT_CONNECT_TO_SERVER => 'onCannotConnectToServer',
38
            EventStore::RECEIVE_MESSAGE => 'onReceiveMessage',
39
            EventStore::CONNECTION_ERROR => 'onConnectionError',
40
            EventStore::AUTH_ERROR => 'onAuthError',
41
            EventStore::REGISTER_TUNNEL_ERROR => 'onRegisterTunnelError',
42
            EventStore::DISCONNECT_FROM_SERVER => 'onDisconnectFromServer'
43
        ];
44
    }
45
46
    public function onAuthError(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...
47
    {
48
        $this->logger->error('Auth error, please checks your configuration file');
49
    }
50
51
    public function onRegisterTunnelError(Event $event)
52
    {
53
        $this->logger->error(sprintf('Registers the tunnel "%s" error, message: %s',
54
            $event->getArgument('tunnel'),
55
            $event->getArgument('errorMessage')
56
        ));
57
    }
58
59
    public function onDisconnectFromServer(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...
60
    {
61
        $this->logger->error('Disconnect from the server');
62
    }
63
64
    public function onReceiveMessage(Event $event)
65
    {
66
        $this->logger->info("Received a message:\r\n" . $event->getArgument('message'));
67
    }
68
69
    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...
70
    {
71
        $this->logger->info("The client is running ...");
72
    }
73
74
    public function onConnectionError(Event $event)
75
    {
76
        $this->logger->warning(sprintf('Got a bad protocol message: "%s" from "%s"',
77
            $event->getArgument('exception')->getMessage(),
78
            $event->getArgument('connection')->getRemoteAddress()
79
        ));
80
    }
81
82
    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...
83
    {
84
        $this->logger->info("The client has connected to the server.");
85
    }
86
87
    public function onCannotConnectToServer(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...
88
    {
89
        $this->logger->error("Cannot connect to the server. the server may not be available");
90
    }
91
}