SparkpostApiService::bind()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Swm\Bundle\MailHookBundle\ApiService;
4
5
use Swm\Bundle\MailHookBundle\Hook\DefaultHook;
6
use Swm\Bundle\MailHookBundle\SwmMailHookEvent;
7
8
class SparkpostApiService extends BaseApiService
9
{
10
    private $eventAssoc = array(
11
        'open'             => SwmMailHookEvent::MAILHOOK_OPEN,
12
        'click'            => SwmMailHookEvent::MAILHOOK_CLICK,
13
        'bounce'           => SwmMailHookEvent::MAILHOOK_HARDBOUNCE,
14
        'spam_complaint'   => SwmMailHookEvent::MAILHOOK_SPAM,
15
        'list_unsubscribe' => SwmMailHookEvent::MAILHOOK_UNSUB,
16
        'link_unsubscribe' => SwmMailHookEvent::MAILHOOK_UNSUB,
17
        'delay'            => SwmMailHookEvent::MAILHOOK_DEFERRAL,
18
        'delivery'         => SwmMailHookEvent::MAILHOOK_SEND,
19
        'policy_rejection' => SwmMailHookEvent::MAILHOOK_REJECT,
20
        'out_of_band'      => SwmMailHookEvent::MAILHOOK_HARDBOUNCE,
21
    );
22
23
    /**
24
     * @param  array  $hook
25
     * @return HookInterface
26
     */
27
    private function bindHook(array $hook)
28
    {
29
        $email = $hook['msys']['message_event']['rcpt_to'];
30
        $event = $hook['msys']['message_event']['type'];
31
32
        if (!isset($this->eventAssoc[$event])) {
33
            return;
34
        }
35
36
        return new DefaultHook($event, $email, 'mandrill', $hook, $this->eventAssoc[$event]);
37
    }
38
39
    /**
40
     * @return array<HookInterface>
41
     */
42 View Code Duplication
    public function bind()
0 ignored issues
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...
43
    {
44
        if (!$this->request->getContent()) {
45
            throw new \Exception("Could not find data");
46
        }
47
48
        $sparkpostEvents = json_decode($this->request->getContent(), true);
49
50
        return array_map([$this, 'bindHook'], $sparkpostEvents);
51
    }
52
}
53