Completed
Push — master ( de13ff...b1f949 )
by Tobias
03:27
created

BaseResponse   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 60
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 14 3
A getWebhookUrl() 0 6 2
A getMessage() 0 4 1
1
<?php
2
3
/*
4
 * Copyright (C) 2013-2016 Mailgun
5
 *
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license. See the LICENSE file for details.
8
 */
9
10
namespace Mailgun\Resource\Api\Webhook;
11
12
use Mailgun\Resource\ApiResponse;
13
14
/**
15
 * This is only mean to be the base response for Webhook API.
16
 *
17
 * @author Tobias Nyholm <[email protected]>
18
 */
19
abstract class BaseResponse implements ApiResponse
20
{
21
    /**
22
     * @var array
23
     */
24
    private $webhook = [];
25
26
    /**
27
     * @var string
28
     */
29
    private $message;
30
31
    /**
32
     * @param array  $webhook
33
     * @param string $message
34
     */
35
    public function __construct(array $webhook, $message)
36
    {
37
        $this->webhook = $webhook;
38
        $this->message = $message;
39
    }
40
41
    /**
42
     * @param array $data
43
     *
44
     * @return static
45
     */
46
    public static function create(array $data)
47
    {
48
        $webhook = [];
49
        $message = '';
50
        if (isset($data['webhook'])) {
51
            $webhook = $data['webhook'];
52
        }
53
54
        if (isset($data['message'])) {
55
            $message = $data['message'];
56
        }
57
58
        return new static($webhook, $message);
59
    }
60
61
    /**
62
     * @return string|null
63
     */
64
    public function getWebhookUrl()
65
    {
66
        if (isset($this->webhook['url'])) {
67
            return $this->webhook['url'];
68
        }
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function getMessage()
75
    {
76
        return $this->message;
77
    }
78
}
79