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.

Device::getDevices()   A
last analyzed

Complexity

Conditions 2
Paths 3

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 3
nop 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Speicher210\Estimote\Resource;
6
7
use GuzzleHttp\Exception\ClientException;
8
use Speicher210\Estimote\AbstractResource;
9
use Speicher210\Estimote\Model\Device as DeviceModel;
10
use Speicher210\Estimote\Model\Device\Update as BeaconUpdate;
11
12
class Device extends AbstractResource
13
{
14
    /**
15
     * @param string $identifier
16
     * @return DeviceModel
17
     */
18 View Code Duplication
    public function getDevice(string $identifier): 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...
19
    {
20
        try {
21
            $response = $this->client->get('/v2/devices/' . $identifier);
22
23
            return $this->serializer->deserialize(
24
                (string)$response->getBody(),
25
                DeviceModel::class,
26
                'json'
27
            );
28
        } catch (ClientException $e) {
29
            throw $this->createApiException($e);
30
        }
31
    }
32
33
    /**
34
     * @return DeviceModel[]
35
     */
36 View Code Duplication
    public function getDevices(): array
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...
37
    {
38
        try {
39
            $response = $this->client->get('/v2/devices');
40
41
            return $this->serializer->deserialize(
42
                (string)$response->getBody(),
43
                'array<Speicher210\Estimote\Model\Device>',
44
                'json'
45
            );
46
        } catch (ClientException $e) {
47
            throw $this->createApiException($e);
48
        }
49
    }
50
51
    /**
52
     * @param string $identifier The device identifier.
53
     * @param BeaconUpdate $data The data to send.
54
     * @return boolean
55
     */
56
    public function updateDevice(string $identifier, BeaconUpdate $data): bool
57
    {
58
        $updatePayload = $this->serializer->serialize($data, 'json');
59
60
        try {
61
            $response = $this->client->post(
62
                'v2/devices/' . $identifier,
63
                [
64
                    'headers' => [
65
                        'Content-Type' => 'application/json'
66
                    ],
67
                    'body' => $updatePayload
68
                ]
69
            );
70
71
            $json = \GuzzleHttp\json_decode($response->getBody(), true);
72
73
            return isset($json['success']) ? ($json['success'] === true) : false;
74
        } catch (ClientException $e) {
75
            throw $this->createApiException($e);
76
        }
77
    }
78
}
79