1 | <?php |
||
23 | final class HttpClient implements ClientInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var Client |
||
27 | */ |
||
28 | private $httpClient; |
||
29 | |||
30 | /** |
||
31 | * @param string $baseUri |
||
32 | * @param UserCredentials $credentials |
||
33 | * @param float $connectTimeout |
||
34 | * @param array $httpClientOptions |
||
35 | */ |
||
36 | public function __construct( |
||
37 | string $baseUri, |
||
38 | UserCredentials $credentials, |
||
39 | float $connectTimeout = 3, |
||
40 | array $httpClientOptions = [] |
||
41 | ) { |
||
42 | $options = array_merge( |
||
43 | $httpClientOptions, |
||
44 | [ |
||
45 | 'base_uri' => $baseUri, |
||
46 | 'allow_redirects' => false, |
||
47 | 'connect_timeout' => $connectTimeout, |
||
48 | 'auth' => [$credentials->getLogin(), $credentials->getPassword()], |
||
49 | 'http_errors' => false, // Let the client handle the status codes for now. |
||
50 | ] |
||
51 | ); |
||
52 | $this->httpClient = new Client($options); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param string $streamId |
||
57 | * @param int $expectedVersion |
||
58 | * @param array $events |
||
59 | */ |
||
60 | public function appendToStream(string $streamId, int $expectedVersion, array $events) |
||
61 | { |
||
62 | $events = EventDataCollection::fromArray($events); |
||
63 | if (0 === $events->count()) { |
||
64 | throw new \InvalidArgumentException('No events provided.'); |
||
65 | } |
||
66 | |||
67 | $streamId = new StreamId($streamId); |
||
68 | if ($streamId->isSystem()) { |
||
69 | throw new \InvalidArgumentException(sprintf('Can not append to system stream %s', $streamId)); |
||
70 | } |
||
71 | |||
72 | $expectedVersion = new ExpectedVersion($expectedVersion); |
||
73 | |||
74 | $request = new AppendToStreamRequestFactory($streamId, $expectedVersion, $events); |
||
75 | |||
76 | $this->send($request->buildRequest(), new AppendToStreamResponseInspector()); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @param RequestInterface $request |
||
81 | * @param ResponseInspector $inspector |
||
82 | * |
||
83 | * @return ResponseInterface |
||
84 | * |
||
85 | * @internal |
||
86 | */ |
||
87 | public function send(RequestInterface $request, ResponseInspector $inspector): ResponseInterface |
||
99 | |||
100 | /** |
||
101 | * @param $e |
||
102 | */ |
||
103 | private function handleTransferException(TransferException $e) |
||
107 | |||
108 | /** |
||
109 | * @param string $streamId |
||
110 | */ |
||
111 | public function deleteStream(string $streamId) |
||
123 | |||
124 | /** |
||
125 | * With great power comes great responsibility. |
||
126 | * |
||
127 | * @return EventRecordCollection |
||
128 | */ |
||
129 | public function readAllEvents(): EventRecordCollection |
||
135 | |||
136 | /** |
||
137 | * @param string $streamId |
||
138 | * |
||
139 | * @return EventRecordCollection |
||
140 | */ |
||
141 | public function readAllEventsFromStream(string $streamId): EventRecordCollection |
||
154 | |||
155 | /** |
||
156 | * Retrieves events recorded since a given version of the stream. |
||
157 | * Does not include the event with number corresponding to the given version. |
||
158 | * |
||
159 | * @param string $streamId |
||
160 | * @param int $version |
||
161 | * |
||
162 | * @return EventRecordCollection |
||
163 | */ |
||
164 | public function readStreamUpToVersion(string $streamId, int $version): EventRecordCollection |
||
197 | |||
198 | /** |
||
199 | * @param string $streamId |
||
200 | * @param string $groupName |
||
201 | * @param PersistentSubscriptionSettings $settings |
||
202 | */ |
||
203 | public function createPersistentSubscription( |
||
212 | |||
213 | /** |
||
214 | * @param string $streamId |
||
215 | * @param string $groupName |
||
216 | * @param PersistentSubscriptionSettings $settings |
||
217 | */ |
||
218 | public function updatePersistentSubscription(string $streamId, string $groupName, PersistentSubscriptionSettings $settings) |
||
224 | |||
225 | /** |
||
226 | * @param string $streamId |
||
227 | * @param string $groupName |
||
228 | */ |
||
229 | public function deletePersistentSubscription(string $streamId, string $groupName) |
||
235 | |||
236 | /** |
||
237 | * @param string $streamId |
||
238 | * @param string $groupName |
||
239 | * @param callable $messageHandler |
||
240 | * @param int $batchSize |
||
241 | * @param bool $autoAck |
||
242 | */ |
||
243 | public function readStreamViaPersistentSubscription( |
||
266 | |||
267 | /** |
||
268 | * @param string $streamId |
||
269 | * @param string $groupName |
||
270 | * |
||
271 | * @return PersistentSubscriptionInfo |
||
272 | */ |
||
273 | public function getPersistentSubscriptionInfo(string $streamId, string $groupName): PersistentSubscriptionInfo |
||
282 | } |
||
283 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.