Completed
Push — master ( f98365...7d52cd )
by Saurabh
10:18
created

DocumentJob   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 59
Duplicated Lines 38.98 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 23
loc 59
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 16 1
A create() 23 23 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 DocumentJob extends BaseClass
6
{
7
    /** The URI of the action */
8
    const URI = 'https://api.signere.no/api/DocumentJob';
9
10
    /**
11
     * Retrieves a document job in the form of a response
12
     * object containing the document job parameters.
13
     *
14
     * @param  string $jobId
15
     * @return object
16
     */
17 1
    public function get(string $jobId)
18
    {
19
        // make the URL for this request
20 1
        $url = sprintf('%s/%s', $this->getBaseUrl(), $jobId);
21
22
        // get the headers for this request
23 1
        $headers = $this->headers->make('GET', $url);
24
25
        // get the response
26 1
        $response = $this->client->get($url, [
27 1
            'headers' => $headers,
28
        ]);
29
30
        // return the response
31 1
        return $response;
32
    }
33
34
    /**
35
     * Creates a document job.
36
     *
37
     * @param  array  $body
38
     * @return object
39
     */
40 1 View Code Duplication
    public function create(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...
41
    {
42
        // keys that are mandatory for this request
43 1
        $needKeys = ['Contact_Email', 'Contact_Phone'];
44
45
        // if the body doesn't have needed fields, throw an exception
46 1
        $this->validateHasKeys($body, $needKeys);
47
48
        // make the URL for this request
49 1
        $url = $this->getBaseUrl();
50
51
        // get the headers for this request
52 1
        $headers = $this->headers->make('POST', $url, $body);
53
54
        // get the response
55 1
        $response = $this->client->post($url, [
56 1
            'headers' => $headers,
57 1
            'json' => $body,
58
        ]);
59
60
        // return the response
61 1
        return $response;
62
    }
63
}
64