Debian Codegraph @

lib/3rdParty/composer/aws/aws-sdk-php/src/S3/S3Transfer/Progress/TransferProgressSnapshot.php

raw symbols SCIP
1 <?php
2
3 namespace Aws\S3\S3Transfer\Progress;
4
5 use Throwable;
6
7 final class TransferProgressSnapshot
8 {
9 /** @var string */
10 private string $identifier;
11
12 /** @var int */
13 private int $transferredBytes;
14
15 /** @var int */
16 private int $totalBytes;
17
18 /** @var array|null */
19 private array|null $response;
20
21 /** @var Throwable|string|null */
22 private Throwable|string|null $reason;
23
24 /**
25 * @param string $identifier
26 * @param int $transferredBytes
27 * @param int $totalBytes
28 * @param array|null $response
29 * @param Throwable|string|null $reason
30 */
31 public function __construct(
32 string $identifier,
33 int $transferredBytes,
34 int $totalBytes,
35 ?array $response = null,
36 Throwable|string|null $reason = null,
37 ) {
38 $this->identifier = $identifier;
39 $this->transferredBytes = $transferredBytes;
40 $this->totalBytes = $totalBytes;
41 $this->response = $response;
42 $this->reason = $reason;
43 }
44
45 public function getIdentifier(): string
46 {
47 return $this->identifier;
48 }
49
50 /**
51 * @return int
52 */
53 public function getTransferredBytes(): int
54 {
55 return $this->transferredBytes;
56 }
57
58 /**
59 * @return int
60 */
61 public function getTotalBytes(): int
62 {
63 return $this->totalBytes;
64 }
65
66 /**
67 * @return array|null
68 */
69 public function getResponse(): array|null
70 {
71 return $this->response;
72 }
73
74 /**
75 * @return float
76 */
77 public function ratioTransferred(): float
78 {
79 if ($this->totalBytes === 0) {
80 // Unable to calculate ratio
81 return 0;
82 }
83
84 return $this->transferredBytes / $this->totalBytes;
85 }
86
87 /**
88 * @return Throwable|string|null
89 */
90 public function getReason(): Throwable|string|null
91 {
92 return $this->reason;
93 }
94
95 /**
96 * @return array
97 */
98 public function toArray(): array
99 {
100 return [
101 'identifier' => $this->identifier,
102 'transferredBytes' => $this->transferredBytes,
103 'totalBytes' => $this->totalBytes,
104 'reason' => $this->reason,
105 'response' => $this->response,
106 ];
107 }
108
109 /**
110 * @param array $response
111 *
112 * @return TransferProgressSnapshot
113 */
114 public function withResponse(array $response): TransferProgressSnapshot
115 {
116 return new self(
117 $this->identifier,
118 $this->transferredBytes,
119 $this->totalBytes,
120 $response,
121 );
122 }
123
124 /**
125 * @param array $data
126 *
127 * @return TransferProgressSnapshot
128 */
129 public static function fromArray(array $data): TransferProgressSnapshot
130 {
131 return new self(
132 $data['identifier'] ?? null,
133 $data['transferredBytes'] ?? 0,
134 $data['totalBytes'] ?? 0,
135 $data['response'] ?? null,
136 $data['reason'] ?? null
137 );
138 }
139 }