Passed
Push — master ( 78b0a8...f52bee )
by Zoilo
01:54
created

Http::response()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace ZoiloMora\ElasticAPM\Events\Span\Context;
4
5
use ZoiloMora\ElasticAPM\Events\Common\Context\Response;
6
use ZoiloMora\ElasticAPM\Events\Common\HttpResponse;
7
use ZoiloMora\ElasticAPM\Helper\Encoding;
8
9
/**
10
 * An object containing contextual data of the related http request.
11
 */
12
final class Http implements \JsonSerializable
13
{
14
    /**
15
     * The raw url of the correlating http request.
16
     *
17
     * @var string|null
18
     */
19
    private $url;
20
21
    /**
22
     * Deprecated: Use span.context.http.response.status_code instead.
23
     *
24
     * @deprecated
25
     * @var int|null
26
     */
27
    private $statusCode;
28
29
    /**
30
     * The method of the http request.
31
     *
32
     * @var string|null
33
     */
34
    private $method;
35
36
    /**
37
     * @var HttpResponse|null
38
     */
39
    private $response;
40
41
    /**
42
     * @param string|null $url
43
     * @param int|null $statusCode
44
     * @param string|null $method
45
     * @param Response|null $response
46
     */
47 3
    public function __construct(
48
        $url = null,
49
        $statusCode = null,
50
        $method = null,
51
        $response = null
52
    ) {
53 3
        $this->url = $url;
54 3
        $this->statusCode = $statusCode;
0 ignored issues
show
Deprecated Code introduced by
The property ZoiloMora\ElasticAPM\Eve...ntext\Http::$statusCode has been deprecated. ( Ignorable by Annotation )

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

54
        /** @scrutinizer ignore-deprecated */ $this->statusCode = $statusCode;
Loading history...
55 3
        $this->method = $method;
56 3
        $this->response = $response;
57 3
    }
58
59
    /**
60
     * @return string|null
61
     */
62 1
    public function url()
63
    {
64 1
        return $this->url;
65
    }
66
67
    /**
68
     * @deprecated
69
     * @return int|null
70
     */
71
    public function statusCode()
72
    {
73
        return $this->statusCode;
0 ignored issues
show
Deprecated Code introduced by
The property ZoiloMora\ElasticAPM\Eve...ntext\Http::$statusCode has been deprecated. ( Ignorable by Annotation )

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

73
        return /** @scrutinizer ignore-deprecated */ $this->statusCode;
Loading history...
74
    }
75
76
    /**
77
     * @return string|null
78
     */
79 1
    public function method()
80
    {
81 1
        return $this->method;
82
    }
83
84
    /**
85
     * @return HttpResponse|null
86
     */
87 1
    public function response()
88
    {
89 1
        return $this->response;
90
    }
91
92
    /**
93
     * @return array
94
     */
95 1
    public function jsonSerialize()
96
    {
97
        return [
98 1
            'url' => $this->url,
99 1
            'status_code' => $this->statusCode,
0 ignored issues
show
Deprecated Code introduced by
The property ZoiloMora\ElasticAPM\Eve...ntext\Http::$statusCode has been deprecated. ( Ignorable by Annotation )

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

99
            'status_code' => /** @scrutinizer ignore-deprecated */ $this->statusCode,
Loading history...
100 1
            'method' => Encoding::keywordField($this->method),
101 1
            'response' => $this->response,
102 1
        ];
103
    }
104
}
105