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.
Test Failed
Push — master ( eabd30...25a381 )
by sunsky
02:14
created

MultiRequest::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 9
Ratio 90 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 9
loc 10
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 8
nc 1
nop 4
crap 1
1
<?php
2
3
namespace MultiHttp;
4
5
use MultiHttp\Exception\InvalidArgumentException;
6
7
/**
8
 *
9
 * @author  [email protected] [email protected]
10
 * Date: 2017/6/9
11
 * Time: 15:09
12
 * @version $Id: $
13
 * @since 1.0
14
 * @copyright Sina Corp.
15
 */
16
class MultiRequest
17
{
18
    protected static $requestPool = array();
19
    protected static $multiHandler;
20
    private static $instance;
21
22
    protected function __construct()
23
    {
24
    }
25
26
    public static function create()
27
    {
28
        if (!(self::$instance instanceof self)) {
29 1
            self::$instance = new self;
30
        }
31 1
        self::prepare();
32
        return self::$instance;
33
    }
34
35
    protected static function prepare()
36 1
    {
37
        self::$multiHandler = curl_multi_init();
38 1
    }
39 1
40 1 View Code Duplication
    public function add($method, $uri, $payload, array $options = 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...
41 1
    {
42 1
        $options = array(
43
                'method' => $method,
44
                'url' => $uri,
45
                'data' => $payload,
46
            ) + $options;
47
        $this->addOptions(array($options));
48
        return $this;
49 1
    }
50 1
51 1
    /**
52
     * @param array $URLOptions
53 1
     * example: array(array('url'=>'http://localhost:9999/','timeout'=>1, 'method'=>'POST', 'data'=>'aa=bb&c=d'))
54
     * @return $this
55 1
     */
56 1
    public function addOptions(array $URLOptions)
57
    {
58
        foreach ($URLOptions as $options) {
59
            $request = Request::create()->addOptions($options)->applyOptions();
60
            if (isset($options['callback'])) {
61
                $request->onEnd($options['callback']);
62
            }
63
            $this->import($request);
64
        }
65 1
        return $this;
66
    }
67
68 1
    public function import(Request $request)
69 1
    {
70 1
        if (!is_resource($request->curlHandle)) {
71 1
            throw new InvalidArgumentException('Request curl handle is not initialized');
72 1
        }
73 1
        curl_multi_add_handle(self::$multiHandler, $request->curlHandle);
74
        self::$requestPool[] = $request;
75
        return $this;
76
    }
77
78
    /**
79
     * @return array(Response)
0 ignored issues
show
Documentation introduced by
The doc-type array(Response) could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
80
     */
81 1
    public function execute()
82
    {
83 1
        $sleepTime = 1000;//microsecond, prevent  CPU 100%
84 1
        do {
85 1
            curl_multi_exec(self::$multiHandler, $active);
86 1
            // bug in PHP 5.3.18+ where curl_multi_select can return -1
87 1
            // https://bugs.php.net/bug.php?id=63411
88 1
            if (curl_multi_select(self::$multiHandler) == -1) {
89 1
                usleep($sleepTime);
90 1
            }
91 1
            usleep($sleepTime);
92
        } while ($active);
93
        $return = array();
94
        foreach (self::$requestPool as $request) {
95
            $response = $request->makeResponse(true);
96
            $func = $response->request->endCallback();
97
            if (isset($func)) {
98 1
                $func($response);
99
            }
100 1
            $return[] = $response;
101
            curl_multi_remove_handle(self::$multiHandler, $request->curlHandle);
102
            curl_close($request->curlHandle);
103 1
        }
104 1
        curl_multi_close(self::$multiHandler);
105 1
        self::$requestPool = null;
0 ignored issues
show
Documentation Bug introduced by
It seems like null of type null is incompatible with the declared type array of property $requestPool.

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...
106
        return $return;
107
    }
108
109
}
110