PluginProbe
Metricool – Social media and site statistics / 2.1.1
Metricool – Social media and site statistics v2.1.1
2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
metricool / vendor / _scoped / guzzlehttp / guzzle / src / TransferStats.php

TransferStats.php in Metricool – Social media and site statistics 2.1.1, at vendor/_scoped/guzzlehttp/guzzle/src/TransferStats.php

115 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Metricool\Vendor\GuzzleHttp;
4
5 use Metricool\Vendor\Psr\Http\Message\RequestInterface;
6 use Metricool\Vendor\Psr\Http\Message\ResponseInterface;
7 use Metricool\Vendor\Psr\Http\Message\UriInterface;
8 /**
9 * Represents data at the point after it was transferred either successfully
10 * or after a network error.
11 */
12 final class TransferStats
13 {
14 /**
15 * @var RequestInterface
16 */
17 private $request;
18 /**
19 * @var ResponseInterface|null
20 */
21 private $response;
22 /**
23 * @var float|null
24 */
25 private $transferTime;
26 /**
27 * @var array
28 */
29 private $handlerStats;
30 /**
31 * @var mixed|null
32 */
33 private $handlerErrorData;
34 /**
35 * @param RequestInterface $request Request that was sent.
36 * @param ResponseInterface|null $response Response received (if any)
37 * @param float|null $transferTime Total handler transfer time.
38 * @param mixed $handlerErrorData Handler error data.
39 * @param array $handlerStats Handler specific stats.
40 */
41 public function __construct(RequestInterface $request, ?ResponseInterface $response = null, ?float $transferTime = null, $handlerErrorData = null, array $handlerStats = [])
42 {
43 $this->request = $request;
44 $this->response = $response;
45 $this->transferTime = $transferTime;
46 $this->handlerErrorData = $handlerErrorData;
47 $this->handlerStats = $handlerStats;
48 }
49 public function getRequest(): RequestInterface
50 {
51 return $this->request;
52 }
53 /**
54 * Returns the response that was received (if any).
55 */
56 public function getResponse(): ?ResponseInterface
57 {
58 return $this->response;
59 }
60 /**
61 * Returns true if a response was received.
62 */
63 public function hasResponse(): bool
64 {
65 return $this->response !== null;
66 }
67 /**
68 * Gets handler specific error data.
69 *
70 * This might be an exception, a integer representing an error code, or
71 * anything else. Relying on this value assumes that you know what handler
72 * you are using.
73 *
74 * @return mixed
75 */
76 public function getHandlerErrorData()
77 {
78 return $this->handlerErrorData;
79 }
80 /**
81 * Get the effective URI the request was sent to.
82 */
83 public function getEffectiveUri(): UriInterface
84 {
85 return $this->request->getUri();
86 }
87 /**
88 * Get the estimated time the request was being transferred by the handler.
89 *
90 * @return float|null Time in seconds.
91 */
92 public function getTransferTime(): ?float
93 {
94 return $this->transferTime;
95 }
96 /**
97 * Gets an array of all of the handler specific transfer data.
98 */
99 public function getHandlerStats(): array
100 {
101 return $this->handlerStats;
102 }
103 /**
104 * Get a specific handler statistic from the handler by name.
105 *
106 * @param string $stat Handler specific transfer stat to retrieve.
107 *
108 * @return mixed|null
109 */
110 public function getHandlerStat(string $stat)
111 {
112 return $this->handlerStats[$stat] ?? null;
113 }
114 }
115