Completed
Push — master ( e41c6a...6a7f08 )
by Saurabh
03:07
created

Message   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 125
Duplicated Lines 27.2 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 34
loc 125
ccs 33
cts 33
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 16 1
A all() 0 16 1
A sendMessage() 0 17 1
A sendNewMessage() 17 17 1
A sendExternalMessage() 17 17 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
namespace Sausin\Signere;
4
5
class Message extends BaseClass
6
{
7
    /** The URI of the action */
8
    const URI = 'https://api.signere.no/api/Message';
9
10
    /**
11
     * Get a list of messages sent for the given document ID.
12
     *
13
     * @param  string $messageId
14
     * @return object
15
     */
16 1
    public function get(string $messageId)
17
    {
18
        // make the URL for this request
19 1
        $url = $this->transformUrl(sprintf('%s/%s', self::URI, $messageId));
20
21
        // get the headers for this request
22 1
        $headers = $this->headers->make('GET', $url);
23
24
        // get the response
25 1
        $response = $this->client->get($url, [
26 1
            'headers' => $headers,
27
        ]);
28
29
        // return the response
30 1
        return $response;
31
    }
32
33
    /**
34
     * Retrieves a list of all the messages that
35
     * are sent for the given document.
36
     *
37
     * @param  string $documentId
38
     * @return object
39
     */
40 1
    public function all(string $documentId)
41
    {
42
        // make the URL for this request
43 1
        $url = $this->transformUrl(sprintf('%s/Document/%s', self::URI, $documentId));
44
45
        // get the headers for this request
46 1
        $headers = $this->headers->make('GET', $url);
47
48
        // get the response
49 1
        $response = $this->client->get($url, [
50 1
            'headers' => $headers,
51
        ]);
52
53
        // return the response
54 1
        return $response;
55
    }
56
57
    /**
58
     * Sends a message to the signees of a given document.
59
     *
60
     * @param  array  $body
61
     * @return object
62
     */
63 1
    public function sendMessage(array $body)
64
    {
65
        // make the URL for this request
66 1
        $url = $this->transformUrl(self::URI);
67
68
        // get the headers for this request
69 1
        $headers = $this->headers->make('POST', $url, $body);
70
71
        // get the response
72 1
        $response = $this->client->post($url, [
73 1
            'headers' => $headers,
74 1
            'json' => $body,
75
        ]);
76
77
        // return the response
78 1
        return $response;
79
    }
80
81
    /**
82
     * Sends a new message to the Signeeref if the first one failed.
83
     *
84
     * @param  array  $body
85
     * @return object
86
     */
87 1 View Code Duplication
    public function sendNewMessage(array $body)
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...
88
    {
89
        // make the URL for this request
90 1
        $url = $this->transformUrl(sprintf('%s/SendNewDocumentMessage', self::URI));
91
92
        // get the headers for this request
93 1
        $headers = $this->headers->make('PUT', $url, $body);
94
95
        // get the response
96 1
        $response = $this->client->post($url, [
97 1
            'headers' => $headers,
98 1
            'json' => $body,
99
        ]);
100
101
        // return the response
102 1
        return $response;
103
    }
104
105
    /**
106
     * Sends a message to an external person with a link/URL
107
     * to view a document.
108
     *
109
     * @param  array  $body
110
     * @return object
111
     */
112 1 View Code Duplication
    public function sendExternalMessage(array $body)
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...
113
    {
114
        // make the URL for this request
115 1
        $url = $this->transformUrl(sprintf('%s/SendExternalMessage', self::URI));
116
117
        // get the headers for this request
118 1
        $headers = $this->headers->make('POST', $url, $body);
119
120
        // get the response
121 1
        $response = $this->client->post($url, [
122 1
            'headers' => $headers,
123 1
            'json' => $body,
124
        ]);
125
126
        // return the response
127 1
        return $response;
128
    }
129
}
130