GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( bf7e34...1e8dac )
by Dragos
14:49
created

Device::update()   B

Complexity

Conditions 2
Paths 3

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 24
rs 8.9713
cc 2
eloc 14
nc 3
nop 3
1
<?php
2
3
namespace Speicher210\KontaktIO\Resource;
4
5
use GuzzleHttp\Exception\ClientException;
6
use Speicher210\KontaktIO\AbstractResource;
7
use Speicher210\KontaktIO\Model\Device as DeviceModel;
8
9
/**
10
 * Device resource.
11
 */
12
class Device extends AbstractResource
13
{
14
    /**
15
     * Get a device.
16
     *
17
     * @param string $uniqueId The device unique ID.
18
     * @return DeviceModel
19
     */
20 View Code Duplication
    public function getDevice($uniqueId)
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...
21
    {
22
        try {
23
            $response = $this->client->get('/device/'.$uniqueId);
24
25
            return $this->serializer->deserialize($response->getBody(), DeviceModel::class, 'json');
26
        } catch (ClientException $e) {
27
            throw $this->createApiException($e);
28
        }
29
    }
30
31
    /**
32
     * Update devices.
33
     *
34
     * @param string|array $uniqueId The unique IDs to update.
35
     * @param string $deviceType The device type. One of the DEVICE_TYPE_* Device model constants.
36
     * @param DeviceModel $values The values for the device(s).
37
     * @return boolean
38
     */
39
    public function update($uniqueId, $deviceType, DeviceModel $values)
40
    {
41
        $jsonSerialized = $this->serializer->serialize($values, 'json');
42
        $values = \GuzzleHttp\json_decode($jsonSerialized, true);
43
44
        $values['uniqueId'] = implode(',', (array)$uniqueId);
45
        $values['deviceType'] = $deviceType;
46
47
        try {
48
            $response = $this->client->post(
49
                '/device/update',
50
                [
51
                    'form_params' => $values,
52
                    'headers' => [
53
                        'Content-Type' => 'application/x-www-form-urlencoded',
54
                    ],
55
                ]
56
            );
57
58
            return $response->getStatusCode() == 200;
59
        } catch (ClientException $e) {
60
            throw $this->createApiException($e);
61
        }
62
    }
63
}
64