KernelLogSubscriber   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 8
dl 0
loc 120
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 12 1
A writePayStartingLog() 0 4 1
A writePayStartedLog() 0 7 1
A writeApiRequestingLog() 0 4 1
A writeApiRequestedLog() 0 4 1
A writeSignFailedLog() 0 4 1
A writeRequestReceivedLog() 0 4 1
A writeMethodCalledLog() 0 4 1
1
<?php
2
3
namespace Yansongda\Pay\Listeners;
4
5
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
6
use Yansongda\Pay\Events;
7
use Yansongda\Pay\Log;
8
9
class KernelLogSubscriber implements EventSubscriberInterface
10
{
11
    /**
12
     * Returns an array of event names this subscriber wants to listen to.
13
     *
14
     * The array keys are event names and the value can be:
15
     *
16
     *  * The method name to call (priority defaults to 0)
17
     *  * An array composed of the method name to call and the priority
18
     *  * An array of arrays composed of the method names to call and respective
19
     *    priorities, or 0 if unset
20
     *
21
     * For instance:
22
     *
23
     *  * array('eventName' => 'methodName')
24
     *  * array('eventName' => array('methodName', $priority))
25
     *  * array('eventName' => array(array('methodName1', $priority), array('methodName2')))
26
     *
27
     * @return array The event names to listen to
28
     */
29
    public static function getSubscribedEvents()
30
    {
31
        return [
32
            Events\PayStarting::class => ['writePayStartingLog', 256],
33
            Events\PayStarted::class => ['writePayStartedLog', 256],
34
            Events\ApiRequesting::class => ['writeApiRequestingLog', 256],
35
            Events\ApiRequested::class => ['writeApiRequestedLog', 256],
36
            Events\SignFailed::class => ['writeSignFailedLog', 256],
37
            Events\RequestReceived::class => ['writeRequestReceivedLog', 256],
38
            Events\MethodCalled::class => ['writeMethodCalledLog', 256],
39
        ];
40
    }
41
42
    /**
43
     * writePayStartingLog.
44
     *
45
     * @author yansongda <[email protected]>
46
     *
47
     * @param Events\PayStarting $event
48
     */
49
    public function writePayStartingLog(Events\PayStarting $event)
50
    {
51
        Log::debug("Starting To {$event->driver}", [$event->gateway, $event->params]);
52
    }
53
54
    /**
55
     * writePayStartedLog.
56
     *
57
     * @author yansongda <[email protected]>
58
     *
59
     * @param Events\PayStarted $event
60
     */
61
    public function writePayStartedLog(Events\PayStarted $event)
62
    {
63
        Log::info(
64
            "{$event->driver} {$event->gateway} Has Started",
65
            [$event->endpoint, $event->payload]
66
        );
67
    }
68
69
    /**
70
     * writeApiRequestingLog.
71
     *
72
     * @author yansongda <[email protected]>
73
     *
74
     * @param Events\ApiRequesting $event
75
     */
76
    public function writeApiRequestingLog(Events\ApiRequesting $event)
77
    {
78
        Log::debug("Requesting To {$event->driver} Api", [$event->endpoint, $event->payload]);
79
    }
80
81
    /**
82
     * writeApiRequestedLog.
83
     *
84
     * @author yansongda <[email protected]>
85
     *
86
     * @param Events\ApiRequested $event
87
     */
88
    public function writeApiRequestedLog(Events\ApiRequested $event)
89
    {
90
        Log::debug("Result Of {$event->driver} Api", $event->result);
91
    }
92
93
    /**
94
     * writeSignFailedLog.
95
     *
96
     * @author yansongda <[email protected]>
97
     *
98
     * @param Events\SignFailed $event
99
     */
100
    public function writeSignFailedLog(Events\SignFailed $event)
101
    {
102
        Log::warning("{$event->driver} Sign Verify FAILED", $event->data);
103
    }
104
105
    /**
106
     * writeRequestReceivedLog.
107
     *
108
     * @author yansongda <[email protected]>
109
     *
110
     * @param Events\RequestReceived $event
111
     */
112
    public function writeRequestReceivedLog(Events\RequestReceived $event)
113
    {
114
        Log::info("Received {$event->driver} Request", $event->data);
115
    }
116
117
    /**
118
     * writeMethodCalledLog.
119
     *
120
     * @author yansongda <[email protected]>
121
     *
122
     * @param Events\MethodCalled $event
123
     */
124
    public function writeMethodCalledLog(Events\MethodCalled $event)
125
    {
126
        Log::info("{$event->driver} {$event->gateway} Method Has Called", [$event->endpoint, $event->payload]);
127
    }
128
}
129