helpers.php ➔ dataRecodes()   C
last analyzed

Complexity

Conditions 7
Paths 12

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 18
nc 12
nop 3
dl 0
loc 27
rs 6.7272
c 0
b 0
f 0
1
<?php
2
if (!function_exists('dataRecodes')) {
3
    function dataRecodes($title, $data, $path)
4
    {
5
        $handler = fopen(dirname(dirname(__FILE__)) . '/logs/' . $path . '/oauth' . date('Y-m-d', time()) . '.log', 'a+');
6
        $content = "================" . $title . "===================\n";
7
        if (is_string($data) === true) {
8
            $content .= $data . "\n";
9
        }
10
        if (is_array($data) === true) {
11
            forEach ($data as $k => $v) {
12
                if (is_array($v)) {
13
                    $v = json_encode($v);
14
                }
15
                $content .= "key: " . $k . " value: " . $v . "\n";
16
            }
17
        }
18
        if (is_bool($data) === true) {
19
            if ($data) {
20
                $content .= "true\n";
21
            } else {
22
                $content .= "false\n";
23
            }
24
        }
25
        $flag = fwrite($handler, $content);
26
        fclose($handler);
27
28
        return $flag;
29
    }
30
}
31
32
/*
33
 * 解析头部信息;
34
 */
35
if (!function_exists('http_parse_headers')) {
36
    function http_parse_headers($raw_headers)
37
    {
38
        $headers = [];
39
        $key     = ''; // [+]
40
41
        foreach (explode("\n", $raw_headers) as $i => $h) {
42
            $h = explode(':', $h, 2);
43
44
            if (isset($h[1])) {
45
                if (!isset($headers[$h[0]])) {
46
                    $headers[$h[0]] = trim($h[1]);
47
                } elseif (is_array($headers[$h[0]])) {
48
                    // $tmp = array_merge($headers[$h[0]], array(trim($h[1]))); // [-]
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% 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...
49
                    // $headers[$h[0]] = $tmp; // [-]
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
50
                    $headers[$h[0]] = array_merge($headers[$h[0]], [trim($h[1])]); // [+]
51
                } else {
52
                    // $tmp = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [-]
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
53
                    // $headers[$h[0]] = $tmp; // [-]
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
54
                    $headers[$h[0]] = array_merge([$headers[$h[0]]], [trim($h[1])]); // [+]
55
                }
56
57
                $key = $h[0]; // [+]
58
            } else {
59
                // [+]
60
                // [+]
61
                if (substr($h[0], 0, 1) == "\t") {
62
                    // [+]
63
                    $headers[$key] .= "\r\n\t" . trim($h[0]);
64
                } // [+]
65
                elseif (!$key) {
66
                    // [+]
67
                    $headers[0] = trim($h[0]);
68
                }
69
                trim($h[0]); // [+]
70
            } // [+]
71
        }
72
73
        return $headers;
74
    }
75
}