Completed
Push — master ( 57033f...9d0e59 )
by
unknown
29s queued 12s
created

RequestOptions   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 19
dl 0
loc 56
rs 10
c 1
b 0
f 1
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCurlOpt() 0 16 5
A __construct() 0 10 1
1
<?php
2
3
namespace Qiniu\Http;
4
5
final class RequestOptions
6
{
7
8
    /**
9
     * @var int|null
10
     * http 请求的超时时间,单位:秒,默认:0,不超时
11
     */
12
    public $connection_timeout;
13
14
    /**
15
     * @var int|null
16
     * http 请求的超时时间,单位:毫秒,默认:0,不超时
17
     */
18
    public $connection_timeout_ms;
19
20
    /**
21
     * @var int|null
22
     * http 请求的超时时间,单位:秒,默认:0,不超时
23
     */
24
    public $timeout;
25
26
27
    /**
28
     * @var int|null
29
     * http 请求的超时时间,单位:毫秒,默认:0,不超时
30
     */
31
    public $timeout_ms;
32
33
    public function __construct(
34
        $connection_timeout = null,
35
        $connection_timeout_ms = null,
36
        $timeout = null,
37
        $timeout_ms = null
38
    ) {
39
        $this->connection_timeout = $connection_timeout;
40
        $this->connection_timeout_ms = $connection_timeout_ms;
41
        $this->timeout = $timeout;
42
        $this->timeout_ms = $timeout_ms;
43
    }
44
45
    public function getCurlOpt()
46
    {
47
        $result = array();
48
        if ($this->connection_timeout != null) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $this->connection_timeout of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison !== instead.
Loading history...
49
            $result[CURLOPT_CONNECTTIMEOUT] = $this->connection_timeout;
50
        }
51
        if ($this->connection_timeout_ms != null) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $this->connection_timeout_ms of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison !== instead.
Loading history...
52
            $result[CURLOPT_CONNECTTIMEOUT_MS] = $this->connection_timeout_ms;
53
        }
54
        if ($this->timeout != null) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $this->timeout of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison !== instead.
Loading history...
55
            $result[CURLOPT_TIMEOUT] = $this->timeout;
56
        }
57
        if ($this->timeout_ms != null) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $this->timeout_ms of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison !== instead.
Loading history...
58
            $result[CURLOPT_TIMEOUT_MS] = $this->timeout_ms;
59
        }
60
        return $result;
61
    }
62
}
63