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 ( eabd30...25a381 )
by sunsky
02:14
created

Response::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 *
4
 * @author  [email protected] [email protected]
5
 * Date: 2017/6/19
6
 * Time: 10:55
7
 * @version $Id: $
8
 * @since 1.0
9
 * @copyright Sina Corp.
10
 */
11
12
namespace MultiHttp;
13
14
15
16
class Response
17
{
18
    public
19
        $code,
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
Coding Style introduced by
The visibility should be declared for property $code.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
20
        $errorCode,
21
        $error,
22
        $header,
23
        $body,
24
        /**
25
         * @var Request
26
         */
27
        $request,
28
        $contentType,
29
        $charset,
30
        $duration,
31
        $info;
32
    protected function __construct()
33
    {
34
    }
35
36
    public static function create(Request $request, $body, $info, $errorCode, $error){
37
        $self = new self;
38
        $self->request = $request;
39
        $self->body = $body;
40
        $self->info = $info;
41
        $self->errorCode = $errorCode;
42 2
        $self->error = $error;
43
        $self->parse();
44 2
        $self->check();
45
        return $self;
46
    }
47
    public function check(){
48
49
    }
50
    public function parse(){
51
        //has header
52
        if($this->request->getIni('header')){
53
            $headers = rtrim(substr($this->body, 0, $this->info['header_size']));
54 2
            $this->body = substr($this->body, $this->info['header_size']);
55
            $headers = explode(PHP_EOL, $headers);
56 2
            array_shift($headers); // HTTP HEADER
57 2
            foreach($headers as $h) {
58 2
                if(false !== strpos($h, ':'))
59 2
                    list($k, $v) = explode(':', $h, 2);
60 2
                else
61 2
                    list($k, $v) = array($h,'');
62 2
63
                $this->header[trim($k)] = trim($v);
64
            }
65
        }
66
        $this->code = $this->info['http_code'];
67 2
        $this->duration = $this->info['total_time'];
68
        $this->contentType = $this->info['content_type'];
69
        $content_type = isset($this->info['content_type']) ? $this->info['content_type'] : '';
70 2
        $content_type = explode(';', $content_type);
71 2
        $this->contentType = $content_type[0];
72 2
        if (count($content_type) == 2 && strpos($content_type[1], '=') !== false) {
73 2
            list( , $this->charset) = explode('=', $content_type[1]);
74 2
        }
75 2
    }
76 2
77
    /**
78 1
     * Status Code Definitions
79
     *
80 2
     * Informational 1xx
81 2
     * Successful    2xx
82
     * Redirection   3xx
83 2
     * Client Error  4xx
84 2
     * Server Error  5xx
85 2
     *
86 2
     * http://pretty-rfc.herokuapp.com/RFC2616#status.codes
87 2
     *
88 2
     * @return bool Did we receive a 4xx or 5xx?
89 2
     */
90 2
    public function hasErrors()
91 2
    {
92
        return $this->code == 0 || $this->code >= 400;
93 2
    }
94
95
}