Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
HttpClientInformation | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
6 | |
100.00% |
1 / 1 |
__construct | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
create | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
getHttpStatus | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getEffectiveUrl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getHeaderSize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getRedirectCount | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\Core\Http\Client; |
6 | |
7 | use CurlHandle; |
8 | use PeServer\Core\Http\Client\HttpClientRequest; |
9 | use PeServer\Core\Http\HttpStatus; |
10 | use PeServer\Core\Web\Url; |
11 | use PeServer\Core\Web\UrlEncoding; |
12 | |
13 | /** */ |
14 | class HttpClientInformation |
15 | { |
16 | /** |
17 | * 生成。 |
18 | * |
19 | * @param UrlEncoding $urlEncoding |
20 | * @param HttpClientRequest $request |
21 | * @param array<string,mixed> $rawItems |
22 | * @codeCoverageIgnore |
23 | */ |
24 | public function __construct( |
25 | readonly protected UrlEncoding $urlEncoding, |
26 | readonly protected HttpClientRequest $request, |
27 | readonly public array $rawItems |
28 | ) { |
29 | } |
30 | |
31 | #region |
32 | |
33 | public static function create(UrlEncoding $urlEncoding, HttpClientRequest $request, CurlHandle $curlHandle): self |
34 | { |
35 | $items = curl_getinfo($curlHandle); |
36 | |
37 | return new self( |
38 | $urlEncoding, |
39 | $request, |
40 | $items |
41 | ); |
42 | } |
43 | |
44 | public function getHttpStatus(): HttpStatus |
45 | { |
46 | return HttpStatus::from($this->rawItems['http_code']); |
47 | } |
48 | |
49 | public function getEffectiveUrl(): Url |
50 | { |
51 | return Url::parse($this->rawItems['url'], $this->urlEncoding); |
52 | } |
53 | |
54 | public function getHeaderSize(): int |
55 | { |
56 | return $this->rawItems['header_size']; |
57 | } |
58 | |
59 | public function getRedirectCount(): int |
60 | { |
61 | return $this->rawItems['redirect_count']; |
62 | } |
63 | |
64 | #endregion |
65 | } |