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
02:58
created

CallbackEventFactory::createMessageEchoEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
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
32 View Code Duplication
        if (isset($payload['message']) && !isset($payload['message']['is_echo'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
33
            return self::createMessageEvent($payload);
34
        }
35
36
        // MessageEchoEvent
37 View Code Duplication
        if (isset($payload['message']) && isset($payload['message']['is_echo'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
38
            return self::createMessageEchoEvent($payload);
39
        }
40
        
41
        // PostbackEvent
42
        if (isset($payload['postback'])) {
43
            return self::createPostbackEvent($payload);
44
        }
45
46
        // AuthenticationEvent
47
        if (isset($payload['optin'])) {
48
            return self::createAuthenticationEvent($payload);
49
        }
50
51
        // AccountLinkingEvent
52
        if (isset($payload['account_linking'])) {
53
            return self::createAccountLinkingEvent($payload);
54
        }
55
56
        // MessageDeliveryEvent
57
        if (isset($payload['delivery'])) {
58
            return self::createMessageDeliveryEvent($payload);
59
        }
60
61
        // MessageReadEvent
62
        if (isset($payload['read'])) {
63
            return self::createMessageReadEvent($payload);
64
        }
65
66
        return new RawEvent($payload['sender']['id'], $payload['recipient']['id'], $payload);
67
    }
68
69
    /**
70
     * @param array $payload
71
     *
72
     * @return MessageEvent
73
     */
74 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...
75
    {
76
        $message = Message::create($payload['message']);
77
        $senderId = $payload['sender']['id'];
78
        $recipientId = $payload['recipient']['id'];
79
        $timestamp = $payload['timestamp'];
80
81
        return new MessageEvent($senderId, $recipientId, $timestamp, $message);
82
    }
83
84
    /**
85
     * @param array $payload
86
     *
87
     * @return MessageEchoEvent
88
     */
89 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...
90
    {
91
        $message = MessageEcho::create($payload['message']);
92
        $senderId = $payload['sender']['id'];
93
        $recipientId = $payload['recipient']['id'];
94
        $timestamp = $payload['timestamp'];
95
96
        return new MessageEchoEvent($senderId, $recipientId, $timestamp, $message);
97
    }
98
99
    /**
100
     * @param array $payload
101
     *
102
     * @return PostbackEvent
103
     */
104 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...
105
    {
106
        $postback = Postback::create($payload['postback']);
107
        $senderId = $payload['sender']['id'];
108
        $recipientId = $payload['recipient']['id'];
109
        $timestamp = $payload['timestamp'];
110
111
        return new PostbackEvent($senderId, $recipientId, $timestamp, $postback);
112
    }
113
114
    /**
115
     * @param array $payload
116
     *
117
     * @return AuthenticationEvent
118
     */
119 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...
120
    {
121
        $optin = Optin::create($payload['optin']);
122
        $senderId = $payload['sender']['id'];
123
        $recipientId = $payload['recipient']['id'];
124
        $timestamp = $payload['timestamp'];
125
126
        return new AuthenticationEvent($senderId, $recipientId, $timestamp, $optin);
127
    }
128
129
    /**
130
     * @param array $payload
131
     *
132
     * @return AccountLinkingEvent
133
     */
134 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...
135
    {
136
        $accountLinking = AccountLinking::create($payload['account_linking']);
137
        $senderId = $payload['sender']['id'];
138
        $recipientId = $payload['recipient']['id'];
139
        $timestamp = $payload['timestamp'];
140
141
        return new AccountLinkingEvent($senderId, $recipientId, $timestamp, $accountLinking);
142
    }
143
144
    /**
145
     * @param array $payload
146
     *
147
     * @return MessageDeliveryEvent
148
     */
149
    public static function createMessageDeliveryEvent(array $payload)
150
    {
151
        $delivery = Delivery::create($payload['delivery']);
152
        $senderId = $payload['sender']['id'];
153
        $recipientId = $payload['recipient']['id'];
154
155
        return new MessageDeliveryEvent($senderId, $recipientId, $delivery);
156
    }
157
158
    /**
159
     * @param array $payload
160
     * 
161
     * @return MessageReadEvent
162
     */
163 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...
164
    {
165
        $read = Read::create($payload['read']);
166
        $senderId = $payload['sender']['id'];
167
        $recipientId = $payload['recipient']['id'];
168
        $timestamp = $payload['timestamp'];
169
170
        return new MessageReadEvent($senderId, $recipientId, $timestamp, $read);
171
    }
172
}
173