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
Branch master (3a24ad)
by Chris
02:15
created

DigitalOceanAccessToken::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.9332
c 0
b 0
f 0
cc 3
nc 4
nop 1
crap 3
1
<?php
2
3
namespace ChrisHemmings\OAuth2\Client\Token;
4
5
use League\OAuth2\Client\Token\AccessToken;
6
7
class DigitalOceanAccessToken extends AccessToken
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $scope;
13
14
    /**
15
     * @var array
16
     */
17
    protected $info;
18
19
    /**
20
     * @inheritDoc
21
     */
22 6
    public function __construct(array $options = [])
23
    {
24 6
        if (!empty($options['scope'])) {
25 3
            $this->scope = $options['scope'];
26
        }
27 6
        if (!empty($options['info'])) {
28 3
            $this->info = $options['info'];
29
        }
30 6
        parent::__construct($options);
31 6
    }
32
33
    /**
34
     * @return string[]
35
     */
36 3
    public function getScopes()
37
    {
38 3
        if (empty($this->scope)) {
39
            return [];
40
        }
41 3
        return array_filter(explode(' ', $this->scope));
42
    }
43
44
    /**
45
     * @return array|null
46
     */
47 3
    public function getInfo()
48
    {
49 3
        return $this->info;
50
    }
51
52
    /**
53
     * @param string $scope
54
     * @return bool
55
     */
56 3
    public function hasScope($scope)
57
    {
58 3
        $scope = trim(strtolower($scope));
59 3
        foreach ($this->getScopes() as $candidate) {
60 3
            if ($scope === strtolower(trim($candidate))) {
61 3
                return true;
62
            }
63
        }
64 3
        return false;
65
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70
    public function jsonSerialize()
71
    {
72
        $parameters = parent::jsonSerialize();
73
74
        if ($this->scope) {
75
            $parameters['scope'] = $this->scope;
76
        }
77
78
        if ($this->info) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->info of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
79
            $parameters['info'] = $this->info;
80
        }
81
82
        return $parameters;
83
    }
84
}
85