Curl   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 24
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A fetchData() 0 21 4
1
<?php
2
namespace Oliver\Curl;
3
4
use Oliver\Curl\CurlInterface;
5
6
/**
7
 *
8
 */
9
class Curl implements CurlInterface
10
{
11
12 5
    public function fetchData(array $urls) : array
13
    {
14 5
        $curlHandles = [];
15 5
        $multiHandle = curl_multi_init();
16
17 5
        for ($i=0; $i < count($urls); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
18 5
            $curlHandles[$i] = curl_init($urls[$i]);
19 5
            curl_setopt($curlHandles[$i], CURLOPT_RETURNTRANSFER, true);
20 5
            curl_multi_add_handle($multiHandle, $curlHandles[$i]);
21
        }
22
23 5
        $running = null;
24
        do {
25 5
            curl_multi_exec($multiHandle, $running);
26 5
        } while ($running);
27
28 5
        $results = [];
29 5
        for ($i=0; $i < count($curlHandles); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
30 5
            $results[] = (json_decode(curl_multi_getcontent($curlHandles[$i]), true));
31
        }
32 5
        return $results;
33
    }
34
}
35