Passed
Push — main ( 255c0f...66f102 )
by Yevhenii
02:14
created

Options::setConnectTimeout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SteamMarketProviders\ParserManager\Http;
6
7
class Options
8
{
9
    /**
10
     * @var float
11
     */
12
    private float $timeout = 6.00;
13
14
    /**
15
     * @var float
16
     */
17
    private float $connectTimeout = 6.00;
18
19
    /**
20
     * @var string|null
21
     */
22
    private null|string $proxy;
23
24
    /**
25
     * @param float $timeout
26
     * @return $this
27
     */
28
    public function setTimeout(float $timeout): Options
29
    {
30
        $this->timeout = $timeout;
31
32
        return $this;
33
    }
34
35
    /**
36
     * @return float
37
     */
38
    public function getTimeout(): float
39
    {
40
        return $this->timeout;
41
    }
42
43
    /**
44
     * @param $connectTimeout
45
     * @return $this
46
     */
47
    public function setConnectTimeout($connectTimeout): Options
48
    {
49
        $this->connectTimeout = $connectTimeout;
50
51
        return $this;
52
    }
53
54
    /**
55
     * @return float
56
     */
57
    public function getConnectTimeout(): float
58
    {
59
        return $this->connectTimeout;
60
    }
61
62
    /**
63
     * @param string $proxy
64
     * @return $this
65
     */
66
    public function setProxy(string $proxy): Options
67
    {
68
        $this->proxy = $proxy;
69
70
        return $this;
71
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function getProxy(): string
77
    {
78
        return $this->proxy;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->proxy could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
79
    }
80
81
82
    /**
83
     * @param Options $options
84
     * @return $this
85
     */
86
    public function setFromOptions(Options $options): Options
87
    {
88
        return $this->setTimeout($options->getTimeout())
89
            ->setConnectTimeout($options->getConnectTimeout())
90
            ->setProxy($options->getProxy());
91
    }
92
93
    /**
94
     * @return array
95
     */
96
    public function toArray(): array
97
    {
98
        $options = [];
99
100
        if ($this->getTimeout()) {
101
            $options['timeout'] = $this->getTimeout();
102
        }
103
104
        if ($this->getConnectTimeout()) {
105
            $options['connect_timeout'] = $this->getConnectTimeout();
106
        }
107
108
        if ($this->getProxy()) {
109
            $options['proxy'] = $this->getProxy();
110
        }
111
112
        return $options;
113
    }
114
}
115