Completed
Push — master ( 761a9e...d7f2fe )
by Taosikai
13:59
created

LoggerListener   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

12 Methods

Rating   Name   Duplication   Size   Complexity  
A onAuthSuccess() 0 4 1
A __construct() 0 4 1
A getLogger() 0 4 1
A onAuthError() 0 4 1
A onRegisterTunnelError() 0 7 1
A onDisconnectFromServer() 0 4 1
A onReceiveMessage() 0 4 1
A onClientRun() 0 4 1
A onConnectionError() 0 7 1
A onConnectToServer() 0 4 1
A onCannotConnectToServer() 0 4 1
A getSubscribedEvents() 0 14 1
1
<?php
2
3
/*
4
 * This file is part of the slince/spike package.
5
 *
6
 * (c) Slince <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Spike\Client\Listener;
13
14
use Slince\EventDispatcher\Event;
15
use Slince\EventDispatcher\SubscriberInterface;
16
use Spike\Client\Client;
17
use Spike\Client\Event\Events;
18
use Spike\Client\Event\FilterActionHandlerEvent;
19
use Spike\Common\Logger\Logger;
20
21
/**
22
 * @codeCoverageIgnore
23
 */
24
class LoggerListener implements SubscriberInterface
25
{
26
    /**
27
     * @var Client
28
     */
29
    protected $client;
30
31
    public function __construct(Client $client)
32
    {
33
        $this->client = $client;
34
    }
35
36
    /**
37
     * @return Logger
38
     */
39
    protected function getLogger()
40
    {
41
        return $this->client->getLogger();
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public static function getSubscribedEvents()
48
    {
49
        return [
50
            Events::CLIENT_RUN => 'onClientRun',
51
            Events::CLIENT_CONNECT => 'onConnectToServer',
52
            Events::CANNOT_CONNECT_SERVER => 'onCannotConnectToServer',
53
            Events::CLIENT_ACTION => 'onReceiveMessage',
54
            Events::CONNECTION_ERROR => 'onConnectionError',
55
            Events::AUTH_ERROR => 'onAuthError',
56
            Events::AUTH_SUCCESS => 'onAuthSuccess',
57
            Events::REGISTER_TUNNEL_ERROR => 'onRegisterTunnelError',
58
            Events::DISCONNECT_FROM_SERVER => 'onDisconnectFromServer',
59
        ];
60
    }
61
62
    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...
63
    {
64
        $this->getLogger()->error('Auth error, please check your configuration file');
65
    }
66
67
    public function onAuthSuccess(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...
68
    {
69
        $this->getLogger()->info('Auth success');
70
    }
71
72
    public function onRegisterTunnelError(Event $event)
73
    {
74
        $this->getLogger()->error(sprintf('Registers tunnel "%s" error, message: "%s"',
75
            $event->getArgument('tunnel'),
76
            $event->getArgument('errorMessage')
77
        ));
78
    }
79
80
    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...
81
    {
82
        $this->getLogger()->error('Disconnect from the server');
83
    }
84
85
    public function onReceiveMessage(FilterActionHandlerEvent $event)
86
    {
87
        $this->getLogger()->info("Received a message:\r\n".$event->getMessage());
88
    }
89
90
    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...
91
    {
92
        $this->getLogger()->info('The client is running ...');
93
    }
94
95
    public function onConnectionError(Event $event)
96
    {
97
        $this->getLogger()->warning(sprintf('Got a bad protocol message: "%s" from "%s"',
98
            $event->getArgument('exception')->getMessage(),
99
            $event->getArgument('connection')->getRemoteAddress()
100
        ));
101
    }
102
103
    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...
104
    {
105
        $this->getLogger()->info('The client has connected to the server.');
106
    }
107
108
    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...
109
    {
110
        $this->getLogger()->error('Cannot connect to the server. the server may not be available');
111
    }
112
}