Test Failed
Pull Request — master (#74)
by
unknown
08:19
created

EventFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 39
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 15 4
1
<?php
2
3
namespace Kerox\Messenger\Event;
4
5
class EventFactory
6
{
7
    const EVENTS = [
8
        'message'             => MessageEvent::class,
9
        'postback'            => PostbackEvent::class,
10
        'optin'               => OptinEvent::class,
11
        'account_linking'     => AccountLinkingEvent::class,
12
        'delivery'            => DeliveryEvent::class,
13
        'read'                => ReadEvent::class,
14
        'payment'             => PaymentEvent::class,
15
        'checkout_update'     => CheckoutUpdateEvent::class,
16
        'pre_checkout'        => PreCheckoutEvent::class,
17
        'take_thread_control' => TakeThreadControlEvent::class,
18
        'pass_thread_control' => PassThreadControlEvent::class,
19
        'policy-enforcement'  => PolicyEnforcementEvent::class,
20
        'app_roles'           => AppRolesEvent::class,
21
    ];
22
23
    /**
24
     * @param array $payload
25
     *
26
     * @return \Kerox\Messenger\Event\AbstractEvent
27
     */
28 13
    public static function create(array $payload): AbstractEvent
29
    {
30 13
        foreach (array_keys($payload) as $key) {
31 13
            if (array_key_exists($key, self::EVENTS)) {
32 12
                $className = self::EVENTS[$key];
33 12
                if (isset($payload['message']['is_echo'])) {
34
                    $className = MessageEchoEvent::class;
35
                }
36
37 13
                return $className::create($payload);
38
            }
39
        }
40
41 1
        return RawEvent::create($payload);
42
    }
43
}
44