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 ( a9ce78...3cd954 )
by Sho
8s
created

ShippoClientV2::setRequestOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
dl 6
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace ShippoClient;
4
5
use ShippoClient\Http\Request\MockCollection;
6
use ShippoClient\Http\RequestV2;
7
8 View Code Duplication
class ShippoClientV2
0 ignored issues
show
Duplication introduced by
This class 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...
9
{
10
    /**
11
     * @var RequestV2
12
     */
13
    private $request;
14
15
    /**
16
     * @var string
17
     */
18
    private $accessToken;
19
20
    /**
21
     * @var static|null
22
     */
23
    private static $instance = null;
24
25
    private function __construct(RequestV2 $request)
26
    {
27
        $this->request = $request;
28
    }
29
30
    public function addresses()
31
    {
32
        return new Addresses($this->request);
33
    }
34
35
    public function parcels()
36
    {
37
        return new Parcels($this->request);
38
    }
39
40
    public function shipments()
41
    {
42
        return new Shipments($this->request);
43
    }
44
45
    public function rates()
46
    {
47
        return new Rates($this->request);
48
    }
49
50
    public function transactions()
51
    {
52
        return new Transactions($this->request);
53
    }
54
55
    public function refunds()
56
    {
57
        return new Refunds($this->request);
58
    }
59
60
    public function tracks()
61
    {
62
        return new Tracks($this->request);
63
    }
64
65
    public function getAccessToken()
66
    {
67
        return $this->accessToken;
68
    }
69
70
    public function setRequestOption($keyOrPath, $value)
71
    {
72
        $this->request->setDefaultOption($keyOrPath, $value);
73
74
        return $this;
75
    }
76
77
    /**
78
     * @param string $accessToken
79
     * @param null|string $apiVersion
80
     * @return static
81
     */
82
    public static function provider($accessToken, $apiVersion = null)
83
    {
84
        if (static::$instance !== null && static::$instance->getAccessToken() === $accessToken) {
0 ignored issues
show
Bug introduced by
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $instance to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
85
            return static::$instance;
0 ignored issues
show
Bug introduced by
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $instance to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
86
        }
87
88
        static::$instance = new static(new RequestV2($accessToken, $apiVersion));
0 ignored issues
show
Bug introduced by
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $instance to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
Bug introduced by
It seems like $apiVersion defined by parameter $apiVersion on line 82 can also be of type string; however, ShippoClient\Http\RequestV2::__construct() does only seem to accept null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
89
90
        return static::$instance;
0 ignored issues
show
Bug introduced by
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $instance to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
91
    }
92
93
    public static function mock()
94
    {
95
        return MockCollection::getInstance();
96
    }
97
}
98