Completed
Push — master ( da873d...74929b )
by Tobias
03:47
created

BaseResponse   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 23.33 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 14
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() 14 14 3
A getWebhookUrl() 0 6 2
A getMessage() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Model\Webhook;
11
12
use Mailgun\Model\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 View Code Duplication
    public static function create(array $data)
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...
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