Passed
Pull Request — master (#1124)
by
unknown
03:55 queued 01:03
created

HttpConfig::fromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Config;
6
7
class HttpConfig implements ConfigInterface
8
{
9
    public function __construct(
10
        public float $timeout = 5.0,
11
        public float $connect_timeout = 5.0,
12
        public array $options = [],
13
    ) {
14
    }
15
16
    public function toArray(): array
17
    {
18
        return array_merge(
19
            [
20
                'timeout' => $this->timeout,
21
                'connect_timeout' => $this->connect_timeout,
22
            ],
23
            $this->options
24
        );
25
    }
26
27
    public static function fromArray(array $config): self
28
    {
29
        $timeout = $config['timeout'] ?? 5.0;
30
        $connect_timeout = $config['connect_timeout'] ?? 5.0;
31
        unset($config['timeout'], $config['connect_timeout']);
32
33
        return new self(
34
            timeout: $timeout,
35
            connect_timeout: $connect_timeout,
36
            options: $config,
37
        );
38
    }
39
}
40