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 ( ae1d49...bb54dc )
by sunsky
02:18
created

MultiRequest::execute()   B

Complexity

Conditions 6
Paths 12

Size

Total Lines 41
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 8.439
c 0
b 0
f 0
cc 6
eloc 20
nc 12
nop 0
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
17
class MultiRequest {
18
	protected static $requestPool;
19
	protected static $multiHandler;
20
21
	protected function __construct() {
22
		self::$multiHandler = curl_multi_init();
23
	}
24
25
	private static $instance;
26
27
	public static function create() {
28
		if (!(self::$instance instanceof self)) {
29
			self::$instance = new self;
30
		}
31
		return self::$instance;
32
	}
33
34
	/**
35
	 * @param array $URLOptions
36
	 * example: array(array('url'=>'http://localhost:9999/','timeout'=>1, 'method'=>'POST', 'data'=>'aa=bb&c=d'))
37
	 * @return $this
38
	 */
39
	public function addOptions(array $URLOptions) {
40
		foreach ($URLOptions as $options) {
41
			$request = Request::create()->addOptions($options)->applyOptions();
42
			if (isset($options['callback'])) {
43
				$request->onEnd($options['callback']);
44
			}
45
			$this->import($request);
46
		}
47
		return $this;
48
	}
49
50
	public function add($method, $uri, array $payload = array(), array $options = array()) {
51
		$options = array(
52
			'method' => $method,
53
			'url'    => $uri,
54
			'data'   => $payload,
55
		)+$options;
56
		$this->addOptions(array($options));
57
		return $this;
58
	}
59
60
	public function import(Request $request) {
61
		if (!is_resource($request->curlHandle)) {throw new InvalidArgumentException('Request curl handle is not initialized');
62
		}
63
		curl_multi_add_handle(self::$multiHandler, $request->curlHandle);
64
		self::$requestPool[] = $request;
65
		return $this;
66
	}
67
68
	/**
69
	 * @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...
70
	 */
71
	public function execute() {
72
		$sleepTime = 1000;//microsecond, prevent  CPU 100%
73
        //prepare conf
74
		while (($multiFlg = curl_multi_exec(self::$multiHandler, $active)) == CURLM_CALL_MULTI_PERFORM);
75
        //fetch data
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
76
//        while ($active && $multiFlg == CURLM_OK) {
77
//            if (curl_multi_select(self::$multiHandler) != -1) {
78
//                while (curl_multi_exec(self::$multiHandler, $active) === CURLM_CALL_MULTI_PERFORM);
79
//
80
//                do {
81
//                    $multiFlg = curl_multi_exec(self::$multiHandler, $active);
82
//                } while ($multiFlg == CURLM_CALL_MULTI_PERFORM);
83
//            }
84
//        }
85
86
87
        do{
88
            curl_multi_exec(self::$multiHandler, $active);
89
            // bug in PHP 5.3.18+ where curl_multi_select can return -1
90
			// https://bugs.php.net/bug.php?id=63411
91
            if (curl_multi_select(self::$multiHandler) === -1) {
92
                usleep($sleepTime);
93
            }
94
            usleep($sleepTime);
95
        }while($active);
96
97
98
        $return = array();
99
		foreach (self::$requestPool as $request) {
100
			$response = $request->makeResponse(true);
101
            $func = $response->request->endCallback();
102
			if (isset($func)) {
103
				$func($response);
104
			}
105
			$return[] = $response;
106
            curl_multi_remove_handle(self::$multiHandler, $request->curlHandle);
107
            curl_close($request->curlHandle);
108
		}
109
		curl_multi_close(self::$multiHandler);
110
		return $return;
111
	}
112
113
}
114