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 ( 48dce0...2aae7b )
by Dragos
14:22
created

Device   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 40 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 7
c 2
b 0
f 1
lcom 1
cbo 4
dl 28
loc 70
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getBeacon() 14 14 2
A getBeacons() 14 14 2
A updateBeacon() 0 20 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Speicher210\Estimote\Resource;
4
5
use GuzzleHttp\Exception\ClientException;
6
use Speicher210\Estimote\AbstractResource;
7
use Speicher210\Estimote\Model\Beacon as BeaconModel;
8
use Speicher210\Estimote\Model\Beacon\Update as BeaconUpdate;
9
10
class Device extends AbstractResource
11
{
12
    /**
13
     * Get one beacon.
14
     *
15
     * @return BeaconModel
16
     */
17 View Code Duplication
    public function getBeacon($mac)
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...
18
    {
19
        try {
20
            $response = $this->client->get('beacons/'.$mac);
21
22
            return $this->serializer->deserialize(
23
                $response->getBody(),
24
                BeaconModel::class,
25
                'json'
26
            );
27
        } catch (ClientException $e) {
28
            throw $this->createApiException($e);
29
        }
30
    }
31
32
    /**
33
     * Get the list of beacons.
34
     *
35
     * @return BeaconModel[]
36
     */
37 View Code Duplication
    public function getBeacons()
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...
38
    {
39
        try {
40
            $response = $this->client->get('beacons');
41
42
            return $this->serializer->deserialize(
43
                $response->getBody(),
44
                'array<Speicher210\Estimote\Model\Beacon>',
45
                'json'
46
            );
47
        } catch (ClientException $e) {
48
            throw $this->createApiException($e);
49
        }
50
    }
51
52
    /**
53
     * Update one beacon.
54
     *
55
     * @param string $beaconMac The beacon MAC address.
56
     * @param BeaconUpdate $data The data to send.
57
     * @return boolean
58
     */
59
    public function updateBeacon($beaconMac, BeaconUpdate $data)
60
    {
61
        try {
62
            $response = $this->client->post(
63
                'beacons/'.$beaconMac.'/pending_settings',
64
                [
65
                    'headers' => [
66
                        'Content-Type' => 'application/json',
67
                    ],
68
                    'body' => $this->serializer->serialize($data, 'json'),
69
                ]
70
            );
71
72
            $json = \GuzzleHttp\json_decode($response->getBody(), true);
73
74
            return isset($json['status']) ? ($json['status'] === 'ok') : false;
75
        } catch (ClientException $e) {
76
            throw $this->createApiException($e);
77
        }
78
    }
79
}
80