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.

MultiRequest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 81
rs 10
c 2
b 0
f 0
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 31 6
A validate() 0 7 2
A __construct() 0 3 1
1
<?php
2
/**
3
 * This file is part of the O2System Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Curl;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Spl\Patterns\Structural\Provider\AbstractProvider;
19
use O2System\Spl\Patterns\Structural\Provider\ValidationInterface;
20
21
/**
22
 * Class MultiRequest
23
 *
24
 * @package O2System\Curl
25
 */
26
class MultiRequest extends AbstractProvider implements ValidationInterface
27
{
28
    /**
29
     * MultiRequest::$curlHandle
30
     *
31
     * Multi request curl handle.
32
     *
33
     * @var resource
34
     */
35
    protected $curlHandle;
36
37
    // ------------------------------------------------------------------------
38
39
    /**
40
     * MultiRequest::__construct
41
     */
42
    public function __construct()
43
    {
44
        $this->curlHandle = curl_multi_init();
45
    }
46
47
    // ------------------------------------------------------------------------
48
49
    /**
50
     * MultiRequest::getResponse
51
     *
52
     * Get response from multiple curl request.
53
     *
54
     * @return array
55
     */
56
    public function get()
57
    {
58
        $responses = [];
59
        $handle = curl_multi_init();
60
61
        foreach ($this as $request) {
62
            if ($request instanceof Request) {
63
                curl_multi_add_handle($handle, $curlHandles[] = $request->getHandle());
64
            }
65
        }
66
67
        if ( ! empty($curlHandles)) {
68
            // execute the handles
69
            $running = null;
70
            do {
71
                curl_multi_exec($handle, $running);
72
            } while ($running > 0);
73
74
75
            // get content and remove handles
76
            foreach ($curlHandles as $curlHandle) {
77
                $responses[] = curl_multi_getcontent($curlHandle);
78
                curl_multi_remove_handle($handle, $curlHandle);
79
            }
80
81
        }
82
83
        // all done
84
        curl_multi_close($handle);
85
86
        return $responses;
87
    }
88
89
    // ------------------------------------------------------------------------
90
91
    /**
92
     * MultiRequest::validate
93
     *
94
     * Checks if the object is a valid instance.
95
     *
96
     * @param object $object The object to be validated.
97
     *
98
     * @return bool Returns TRUE on valid or FALSE on failure.
99
     */
100
    public function validate($object)
101
    {
102
        if ($object instanceof Request) {
103
            return true;
104
        }
105
106
        return false;
107
    }
108
}