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.
Passed
Pull Request — master (#81)
by Yong
04:48
created

MockTrait::hasMockQueue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace AlibabaCloud\Client\Traits;
4
5
use Exception;
6
use GuzzleHttp\Exception\RequestException;
7
use GuzzleHttp\Handler\MockHandler;
8
use GuzzleHttp\HandlerStack;
9
use GuzzleHttp\Psr7\Request;
10
use GuzzleHttp\Psr7\Response;
11
use Psr\Http\Message\RequestInterface;
12
use Psr\Http\Message\ResponseInterface;
13
14
/**
15
 * Class MockTrait
16
 *
17
 * @package AlibabaCloud\Client\Request\Traits
18
 * @mixin Request
19
 */
20
trait MockTrait
21
{
22
    /**
23
     * @var array
24
     */
25
    private static $mockQueue = [];
26
27
    /**
28
     * @var HandlerStack
29
     */
30
    private static $mock;
31
32
    /**
33
     * @param integer             $status
34
     * @param array               $headers
35
     * @param array|string|object $body
36
     */
37 17
    public static function mockResponse($status = 200, array $headers = [], $body = null)
38
    {
39 17
        if (is_array($body) || is_object($body)) {
40 6
            $body = json_encode($body);
41 6
        }
42
43 17
        self::$mockQueue[] = new Response($status, $headers, $body);
44 17
        self::createHandlerStack();
45 17
    }
46
47 18
    private static function createHandlerStack()
48
    {
49 18
        self::$mock = new MockHandler(self::$mockQueue);
0 ignored issues
show
Documentation Bug introduced by
It seems like new GuzzleHttp\Handler\M...andler(self::mockQueue) of type GuzzleHttp\Handler\MockHandler is incompatible with the declared type GuzzleHttp\HandlerStack of property $mock.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
50 18
    }
51
52
    /**
53
     * @param string                 $message
54
     * @param RequestInterface       $request
55
     * @param ResponseInterface|null $response
56
     * @param Exception|null         $previous
57
     * @param array                  $handlerContext
58
     */
59 1
    public static function mockRequestException(
60
        $message,
61
        RequestInterface $request,
62
        ResponseInterface $response = null,
63
        Exception $previous = null,
64
        array $handlerContext = []
65
    ) {
66 1
        self::$mockQueue[] = new RequestException(
67 1
            $message,
68 1
            $request,
69 1
            $response,
70 1
            $previous,
71
            $handlerContext
72 1
        );
73
74 1
        self::createHandlerStack();
75 1
    }
76
77 59
    public static function cancelMock()
78
    {
79 59
        self::$mockQueue = [];
80 59
        self::$mock      = null;
81 59
    }
82
83
    /**
84
     * @return bool
85
     */
86 66
    public static function hasMock()
87
    {
88 66
        return (bool)self::$mockQueue;
89
    }
90
91
    /**
92
     * @return HandlerStack
93
     */
94 16
    public static function getMock()
95
    {
96 16
        return self::$mock;
97
    }
98
}
99