Skip to content

Commit 3950679

Browse files
committed
Improve documentation
1 parent 437a2e1 commit 3950679

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/BatchResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Psr\Http\Message\ResponseInterface;
77

88
/**
9-
* Successful responses and exceptions returned from parallel request execution
9+
* Successful responses returned from parallel request execution
1010
*
1111
* @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
1212
*/

src/Exception/BatchException.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
use Psr\Http\Message\RequestInterface;
88

99
/**
10-
* @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
10+
* This exception is thrown when a batch of requests led to at least one failure.
11+
*
12+
* It holds the response/exception pairs and gives access to a BatchResult with the successful responses.
13+
*
14+
*@author Márk Sági-Kazár <mark.sagikazar@gmail.com>
1115
*/
1216
final class BatchException extends RuntimeException
1317
{
@@ -27,12 +31,18 @@ public function __construct()
2731
}
2832

2933
/**
30-
* Returns a list BatchResult which contains succesful responses
34+
* Returns the BatchResult that contains those responses that where successful.
35+
*
36+
* Note that the BatchResult may contains 0 responses if all requests failed.
3137
*
3238
* @return BatchResult
3339
*/
3440
public function getResult()
3541
{
42+
if (!isset($this->result)) {
43+
$this->result = new BatchResult();
44+
}
45+
3646
return $this->result;
3747
}
3848

@@ -41,10 +51,16 @@ public function getResult()
4151
*
4252
* @param BatchResult $result
4353
*
54+
* @throws InvalidArgumentException If the BatchResult is already set
55+
*
4456
* @internal
4557
*/
4658
public function setResult(BatchResult $result)
4759
{
60+
if (isset($this->result)) {
61+
throw new InvalidArgumentException('BatchResult is already set');
62+
}
63+
4864
$this->result = $result;
4965
}
5066

@@ -57,7 +73,7 @@ public function setResult(BatchResult $result)
5773
*/
5874
public function isSuccessful(RequestInterface $request)
5975
{
60-
return isset($this->result) && $this->result->hasResponseFor($request);
76+
return $this->getResult()->hasResponseFor($request);
6177
}
6278

6379
/**

src/HttpPsrClient.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ public function sendRequest(RequestInterface $request, array $options = []);
2828
/**
2929
* Sends PSR requests
3030
*
31+
* If one or more requests led to an exception, the BatchException is thrown.
32+
* The BatchException also gives access to the BatchResult for the successful responses.
33+
*
3134
* @param RequestInterface[] $requests
3235
* @param array $options
3336
*
34-
* @return BatchResult
37+
* @return BatchResult If all requests where successful.
3538
*
3639
* @throws Exception
3740
* @throws BatchException

0 commit comments

Comments
 (0)