Completed
Push — master ( a61ca1...848531 )
by Saurabh
01:36
created

DocumentProvider::getUsage()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 21
Code Lines 10

Duplication

Lines 21
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 1
nop 2
dl 21
loc 21
ccs 10
cts 10
cp 1
crap 2
rs 9.3142
c 0
b 0
f 0
1
<?php
2
3
namespace Sausin\Signere;
4
5
use UnexpectedValueException;
6
7
class DocumentProvider extends BaseClass
8
{
9
    /** The URI of the action */
10
    const URI = 'https://api.signere.no/api/DocumentProvider';
11
12
    /**
13
     * Retrieves a document provider account.
14
     *
15
     * @param  string $providerId
16
     * @return object
17
     */
18 1
    public function getProviderAccount(string $providerId)
19
    {
20
        // make the URL for this request
21 1
        $url = sprintf('%s/%s', $this->getBaseUrl(), $providerId);
22
23
        // get the headers for this request
24 1
        $headers = $this->headers->make('GET', $url);
25
26
        // get the response
27 1
        $response = $this->client->get($url, [
28 1
            'headers' => $headers,
29
        ]);
30
31
        // return the response
32 1
        return $response;
33
    }
34
35
    /**
36
     * Gets the expires date for your BankID certificate. If you don't
37
     * have your own BankID certificate it will return Bad request.
38
     *
39
     * @return object
40
     */
41 1
    public function getCertExpiry()
42
    {
43
        // make the URL for this request
44 1
        $url = sprintf('%s/CertificateExpires', $this->getBaseUrl());
45
46
        // get the headers for this request
47 1
        $headers = $this->headers->make('GET', $url);
48
49
        // get the response
50 1
        $response = $this->client->get($url, [
51 1
            'headers' => $headers,
52
        ]);
53
54
        // return the response
55 1
        return $response;
56
    }
57
58
    /**
59
     * Get the usage when using prepaid or demo account.
60
     *
61
     * @param  string       $providerId
62
     * @param  bool|bool $demo
63
     * @return object
64
     */
65 2 View Code Duplication
    public function getUsage(string $providerId, bool $demo = false)
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...
66
    {
67
        // make the URL for this request
68 2
        $url = sprintf(
69 2
            '%s/quota/%s?ProviderId=%s',
70 2
            $this->getBaseUrl(),
71 2
            $demo ? 'demo' : 'prepaid',
72 2
            $providerId
73
        );
74
75
        // get the headers for this request
76 2
        $headers = $this->headers->make('GET', $url);
77
78
        // get the response
79 2
        $response = $this->client->get($url, [
80 2
            'headers' => $headers,
81
        ]);
82
83
        // return the response
84 2
        return $response;
85
    }
86
87
    /**
88
     * Creates a new document provider.
89
     *
90
     * @param  array  $body
91
     * @return object
92
     */
93 1
    public function create(array $body)
94
    {
95
        // keys that are mandatory for this request
96
        $needKeys = [
97 1
            'BillingAddress1',
98
            'BillingCity',
99
            'BillingPostalCode',
100
            'CompanyEmail',
101
            'CompanyPhone',
102
            'DealerId',
103
            'LegalContactEmail',
104
            'LegalContactName',
105
            'LegalContactPhone',
106
            'MvaNumber',
107
            'Name',
108
        ];
109
110
        // if the body doesn't have needed fields, throw an exception
111 1
        $this->validateHasKeys($body, $needKeys);
112
113 1 View Code Duplication
        if (isset($body['BillingPlan'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
114 1
            $expected = ['Small', 'Medium', 'Large'];
115 1
            if (! in_array($body['BillingPlan'], $expected)) {
116 1
                throw new UnexpectedValueException('BillingPlan should be one of '.implode(', ', $expected));
117
            }
118
        }
119
120
        // make the URL for this request
121 1
        $url = $this->getBaseUrl();
122
123
        // get the headers for this request
124 1
        $headers = $this->headers->make('POST', $url, $body);
125
126
        // get the response
127 1
        $response = $this->client->post($url, [
128 1
            'headers' => $headers,
129 1
            'json' => $body,
130
        ]);
131
132
        // return the response
133 1
        return $response;
134
    }
135
136
    /**
137
     * Updates a new document provider.
138
     *
139
     * @param  array  $body
140
     * @return object
141
     */
142 1
    public function update(array $body)
143
    {
144
        // keys that are mandatory for this request
145 1
        $needKeys = ['Mobile', 'ProviderId'];
146
147
        // if the body doesn't have needed fields, throw an exception
148 1
        $this->validateHasKeys($body, $needKeys);
149
150 1 View Code Duplication
        if (isset($body['BillingPlan'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
151
            $expected = ['Small', 'Medium', 'Large'];
152
            if (! in_array($body['BillingPlan'], $expected)) {
153
                throw new UnexpectedValueException('BillingPlan should be one of '.implode(', ', $expected));
154
            }
155
        }
156
157
        // make the URL for this request
158 1
        $url = $this->getBaseUrl();
159
160
        // get the headers for this request
161 1
        $headers = $this->headers->make('PUT', $url, $body);
162
163
        // get the response
164 1
        $response = $this->client->put($url, [
165 1
            'headers' => $headers,
166 1
            'json' => $body,
167
        ]);
168
169
        // return the response
170 1
        return $response;
171
    }
172
}
173