Passed
Push — master ( 91fe13...12bba4 )
by Shahrad
10:04
created

generateUpToDateMimeArray()   B

Complexity

Conditions 8
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 11
rs 8.4444
cc 8
nc 4
nop 1
1
<?php
2
3
function generateUpToDateMimeArray(string $url): array
4
{
5
    $s = array();
6
    foreach (@explode("\n", @file_get_contents($url)) as $x) {
0 ignored issues
show
Bug introduced by
It seems like @file_get_contents($url) can also be of type false; however, parameter $string of explode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

6
    foreach (@explode("\n", /** @scrutinizer ignore-type */ @file_get_contents($url)) as $x) {
Loading history...
7
        if (isset($x[0]) && $x[0] !== '#' && preg_match_all('#([^\s]+)#', $x, $out) && isset($out[1]) && ($c = count($out[1])) > 1) {
8
            for ($i = 1; $i < $c; $i++) {
9
                $s[$out[1][$i]] = $out[1][0];
10
            }
11
        }
12
    }
13
    return $s;
14
}
15
16
$data = generateUpToDateMimeArray('https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types');
17
echo '<pre>' . json_encode($data, JSON_PRETTY_PRINT) . '</pre>';