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 ( 1c87f7...9aea1c )
by sunsky
03:22
created

MultiRequest::import()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
rs 9.4285
nc 2
cc 2
eloc 5
nop 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
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
74
		while (($multiFlg = curl_multi_exec(self::$multiHandler, $active)) == CURLM_CALL_MULTI_PERFORM);
75
76
		while ($active && $multiFlg == CURLM_OK) {
77
			// Wait for activity on any curl-connection
78
			while (curl_multi_exec(self::$multiHandler, $active) === CURLM_CALL_MULTI_PERFORM);
79
			// bug in PHP 5.3.18+ where curl_multi_select can return -1
80
			// https://bugs.php.net/bug.php?id=63411
81
			if (curl_multi_select(self::$multiHandler) == -1) {
82
				usleep($sleepTime);
83
			}
84
85
			usleep($sleepTime);
86
		}
87
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
88
        do{
89
            curl_multi_exec(self::$multiHandler, $active);
90
            if (curl_multi_select(self::$multiHandler) === -1) {
91
                usleep($sleepTime);
92
            }
93
            usleep($sleepTime);
94
        }while($active);
95
        */
96
97
        $return = array();
98
		foreach (self::$requestPool as $request) {
99
			$response = $request->makeResponse(true);
100
            $func = $response->request->endCallback();
101
			if (isset($func)) {
102
				$func($response);
103
			}
104
			$return[] = $response;
105
            curl_multi_remove_handle(self::$multiHandler, $request->curlHandle);
106
            curl_close($request->curlHandle);
107
		}
108
		curl_multi_close(self::$multiHandler);
109
		return $return;
110
	}
111
112
}
113