GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#16)
by Gallice
03:47
created

CallbackEventFactory::create()   C

Complexity

Conditions 8
Paths 8

Size

Total Lines 38
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 5.3846
c 0
b 0
f 0
cc 8
eloc 16
nc 8
nop 1
1
<?php
2
3
namespace Tgallice\FBMessenger;
4
5
use Tgallice\FBMessenger\Callback\AccountLinkingEvent;
6
use Tgallice\FBMessenger\Callback\AuthenticationEvent;
7
use Tgallice\FBMessenger\Callback\CallbackEvent;
8
use Tgallice\FBMessenger\Callback\MessageDeliveryEvent;
9
use Tgallice\FBMessenger\Callback\MessageEchoEvent;
10
use Tgallice\FBMessenger\Callback\MessageEvent;
11
use Tgallice\FBMessenger\Callback\MessageReadEvent;
12
use Tgallice\FBMessenger\Callback\PostbackEvent;
13
use Tgallice\FBMessenger\Callback\RawEvent;
14
use Tgallice\FBMessenger\Model\Callback\AccountLinking;
15
use Tgallice\FBMessenger\Model\Callback\Delivery;
16
use Tgallice\FBMessenger\Model\Callback\Message;
17
use Tgallice\FBMessenger\Model\Callback\MessageEcho;
18
use Tgallice\FBMessenger\Model\Callback\Optin;
19
use Tgallice\FBMessenger\Model\Callback\Postback;
20
use Tgallice\FBMessenger\Model\Callback\Read;
21
22
class CallbackEventFactory
23
{
24
    /**
25
     * @param array $payload
26
     *
27
     * @return CallbackEvent
28
     */
29
    public static function create(array $payload)
30
    {
31
        // MessageEvent & MessageEchoEvent
32
        if (isset($payload['message'])) {
33
            if (isset($payload['message']['is_echo'])) {
34
                return self::createMessageEchoEvent($payload);
35
            }
36
37
            return self::createMessageEvent($payload);
38
        }
39
        
40
        // PostbackEvent
41
        if (isset($payload['postback'])) {
42
            return self::createPostbackEvent($payload);
43
        }
44
45
        // AuthenticationEvent
46
        if (isset($payload['optin'])) {
47
            return self::createAuthenticationEvent($payload);
48
        }
49
50
        // AccountLinkingEvent
51
        if (isset($payload['account_linking'])) {
52
            return self::createAccountLinkingEvent($payload);
53
        }
54
55
        // MessageDeliveryEvent
56
        if (isset($payload['delivery'])) {
57
            return self::createMessageDeliveryEvent($payload);
58
        }
59
60
        // MessageReadEvent
61
        if (isset($payload['read'])) {
62
            return self::createMessageReadEvent($payload);
63
        }
64
65
        return new RawEvent($payload['sender']['id'], $payload['recipient']['id'], $payload);
66
    }
67
68
    /**
69
     * @param array $payload
70
     *
71
     * @return MessageEvent
72
     */
73 View Code Duplication
    public static function createMessageEvent(array $payload)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
    {
75
        $message = Message::create($payload['message']);
76
        $senderId = $payload['sender']['id'];
77
        $recipientId = $payload['recipient']['id'];
78
        $timestamp = $payload['timestamp'];
79
80
        return new MessageEvent($senderId, $recipientId, $timestamp, $message);
81
    }
82
83
    /**
84
     * @param array $payload
85
     *
86
     * @return MessageEchoEvent
87
     */
88 View Code Duplication
    public static function createMessageEchoEvent(array $payload)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
    {
90
        $message = MessageEcho::create($payload['message']);
91
        $senderId = $payload['sender']['id'];
92
        $recipientId = $payload['recipient']['id'];
93
        $timestamp = $payload['timestamp'];
94
95
        return new MessageEchoEvent($senderId, $recipientId, $timestamp, $message);
96
    }
97
98
    /**
99
     * @param array $payload
100
     *
101
     * @return PostbackEvent
102
     */
103 View Code Duplication
    public static function createPostbackEvent(array $payload)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
104
    {
105
        $postback = Postback::create($payload['postback']);
106
        $senderId = $payload['sender']['id'];
107
        $recipientId = $payload['recipient']['id'];
108
        $timestamp = $payload['timestamp'];
109
110
        return new PostbackEvent($senderId, $recipientId, $timestamp, $postback);
111
    }
112
113
    /**
114
     * @param array $payload
115
     *
116
     * @return AuthenticationEvent
117
     */
118 View Code Duplication
    public static function createAuthenticationEvent(array $payload)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
119
    {
120
        $optin = Optin::create($payload['optin']);
121
        $senderId = $payload['sender']['id'];
122
        $recipientId = $payload['recipient']['id'];
123
        $timestamp = $payload['timestamp'];
124
125
        return new AuthenticationEvent($senderId, $recipientId, $timestamp, $optin);
126
    }
127
128
    /**
129
     * @param array $payload
130
     *
131
     * @return AccountLinkingEvent
132
     */
133 View Code Duplication
    public static function createAccountLinkingEvent(array $payload)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
134
    {
135
        $accountLinking = AccountLinking::create($payload['account_linking']);
136
        $senderId = $payload['sender']['id'];
137
        $recipientId = $payload['recipient']['id'];
138
        $timestamp = $payload['timestamp'];
139
140
        return new AccountLinkingEvent($senderId, $recipientId, $timestamp, $accountLinking);
141
    }
142
143
    /**
144
     * @param array $payload
145
     *
146
     * @return MessageDeliveryEvent
147
     */
148
    public static function createMessageDeliveryEvent(array $payload)
149
    {
150
        $delivery = Delivery::create($payload['delivery']);
151
        $senderId = $payload['sender']['id'];
152
        $recipientId = $payload['recipient']['id'];
153
154
        return new MessageDeliveryEvent($senderId, $recipientId, $delivery);
155
    }
156
157
    /**
158
     * @param array $payload
159
     * 
160
     * @return MessageReadEvent
161
     */
162 View Code Duplication
    public static function createMessageReadEvent(array $payload)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
163
    {
164
        $read = Read::create($payload['read']);
165
        $senderId = $payload['sender']['id'];
166
        $recipientId = $payload['recipient']['id'];
167
        $timestamp = $payload['timestamp'];
168
169
        return new MessageReadEvent($senderId, $recipientId, $timestamp, $read);
170
    }
171
}
172