RequestContext::withoutLogging()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 15
ccs 9
cts 9
cp 1
rs 9.9666
cc 1
nc 1
nop 4
crap 1
1
<?php
2
3
/**
4
 * Abstraction over Http client implementations.
5
 *
6
 * @author  Maksim Masiukevich <[email protected]>
7
 * @license MIT
8
 * @license https://opensource.org/licenses/MIT
9
 */
10
11
declare(strict_types = 0);
12
13
namespace ServiceBus\HttpClient;
14
15
use function ServiceBus\Common\uuid;
0 ignored issues
show
introduced by
The function ServiceBus\Common\uuid was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
16
17
/**
18
 * Http request options
19
 */
20
final class RequestContext
21
{
22
    /**
23
     * @psalm-readonly
24
     *
25
     * @var int
26
     */
27
    public $tcpConnectTimeout;
28
29
    /**
30
     * @psalm-readonly
31
     *
32
     * @var int
33
     */
34
    public $tlsHandshakeTimeout;
35
36
    /**
37
     * @psalm-readonly
38
     *
39
     * @var int
40
     */
41
    public $transferTimeout;
42
43
    /**
44
     * @psalm-readonly
45
     *
46
     * @var int
47
     */
48 1
    public $inactivityTimeout;
49
50
    /**
51
     * @psalm-readonly
52
     *
53
     * @var bool
54 1
     */
55 1
    public $logRequest;
56
57
    /**
58
     * @psalm-readonly
59
     *
60 1
     * @var bool
61 1
     */
62
    public $logResponse;
63
64
    /**
65 4
     * @psalm-readonly
66
     *
67
     * @var string
68
     */
69
    public $traceId;
70
71
    /** @var string|null */
72
    public $protocolVersion;
73
74
    public static function withoutLogging(
75 4
        int $tcpConnectTimeout = 15000,
76 4
        int $tlsHandshakeTimeout = 15000,
77 4
        int $transferTimeout = 15000,
78 4
        int $inactivityTimeout = 15000
79 4
    ): self {
80 4
        return new self(
81 4
            traceId: null,
82 4
            tcpConnectTimeout: $tcpConnectTimeout,
83 4
            tlsHandshakeTimeout: $tlsHandshakeTimeout,
84
            transferTimeout: $transferTimeout,
85
            inactivityTimeout: $inactivityTimeout,
86
            logRequest: false,
87
            logResponse: false,
88
            protocolVersion: null
89
        );
90
    }
91
92
    public function __construct(
93
        ?string $traceId = null,
94
        int $tcpConnectTimeout = 15000,
95
        int $tlsHandshakeTimeout = 15000,
96
        int $transferTimeout = 15000,
97
        int $inactivityTimeout = 15000,
98
        bool $logRequest = true,
99
        bool $logResponse = true,
100
        ?string $protocolVersion = null
101
    ) {
102
        $this->traceId             = $traceId ?? uuid();
0 ignored issues
show
Bug introduced by
The function uuid was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

102
        $this->traceId             = $traceId ?? /** @scrutinizer ignore-call */ uuid();
Loading history...
103
        $this->tcpConnectTimeout   = $tcpConnectTimeout;
104
        $this->tlsHandshakeTimeout = $tlsHandshakeTimeout;
105
        $this->transferTimeout     = $transferTimeout;
106
        $this->logRequest          = $logRequest;
107
        $this->logResponse         = $logResponse;
108
        $this->protocolVersion     = $protocolVersion;
109
        $this->inactivityTimeout   = $inactivityTimeout;
110
    }
111
}
112