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 ( 9cf620...2a1f44 )
by Dragos
13:25
created

Device::getDeviceCredentials()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

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