Completed
Pull Request — master (#246)
by Tobias
10:39
created

BaseResponse   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 60
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
namespace Mailgun\Resource\Api\Webhook;
4
5
use Mailgun\Resource\ApiResponse;
6
7
/**
8
 * This is only mean to be the base response for Webhook API.
9
 *
10
 * @author Tobias Nyholm <[email protected]>
11
 */
12
abstract class BaseResponse implements ApiResponse
13
{
14
    /**
15
     * @var array
16
     */
17
    private $webhook = [];
18
19
    /**
20
     * @var string
21
     */
22
    private $message;
23
24
    /**
25
     * @param array  $webhook
26
     * @param string $message
27
     */
28
    public function __construct(array $webhook, $message)
29
    {
30
        $this->webhook = $webhook;
31
        $this->message = $message;
32
    }
33
34
    /**
35
     * @param array $data
36
     *
37
     * @return static
38
     */
39
    public static function create(array $data)
40
    {
41
        $webhook = [];
42
        $message = '';
43
        if (isset($data['webhook'])) {
44
            $webhook = $data['webhook'];
45
        }
46
47
        if (isset($data['message'])) {
48
            $message = $data['message'];
49
        }
50
51
        return new static($webhook, $message);
52
    }
53
54
    /**
55
     * @return string|null
56
     */
57
    public function getWebhookUrl()
58
    {
59
        if (isset($this->webhook['url'])) {
60
            return $this->webhook['url'];
61
        }
62
    }
63
64
    /**
65
     * @return string
66
     */
67
    public function getMessage()
68
    {
69
        return $this->message;
70
    }
71
}
72