Completed
Push — master ( 9621c0...4bb787 )
by Tobias
01:47
created

Settings::update()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Billogram\Api;
6
7
use Billogram\Model\Setting\Setting;
8
9
/**
10
 * @author Ibrahim Hizeoui <[email protected]>
11
 */
12
class Settings extends HttpApi
13
{
14
    /**
15
     * @return mixed|\Psr\Http\Message\ResponseInterface
16
     *
17
     * @see https://billogram.com/api/documentation#settings_fetch
18
     */
19 1
    public function fetch()
20
    {
21 1
        $response = $this->httpGet('/settings');
22 1
        if (!$this->hydrator) {
23
            return $response;
24
        }
25
        // Use any valid status code here
26 1
        if ($response->getStatusCode() !== 200) {
27
            $this->handleErrors($response);
28
        }
29
30 1
        return $this->hydrator->hydrate($response, Setting::class);
31
    }
32
33
    /**
34
     * @return mixed|\Psr\Http\Message\ResponseInterface
35
     *
36
     * @see https://billogram.com/api/documentation#settings_fetch
37
     */
38 1
    public function update(Setting $setting)
39
    {
40 1
        $response = $this->httpPUT('/settings', $setting->toArray());
41 1
        if (!$this->hydrator) {
42
            return $response;
43
        }
44
        // Use any valid status code here
45 1
        if ($response->getStatusCode() !== 200) {
46
            $this->handleErrors($response);
47
        }
48
49 1
        return $this->hydrator->hydrate($response, Setting::class);
50
    }
51
}
52