1 | <?php |
||
17 | class Guzzle6Promise implements Promise |
||
18 | { |
||
19 | /** |
||
20 | * @var PromiseInterface |
||
21 | */ |
||
22 | private $promise; |
||
23 | |||
24 | /** |
||
25 | * @var string State of the promise |
||
26 | */ |
||
27 | private $state; |
||
28 | |||
29 | /** |
||
30 | * @var ResponseInterface |
||
31 | */ |
||
32 | private $response; |
||
33 | |||
34 | /** |
||
35 | * @var HttplugException |
||
36 | */ |
||
37 | private $exception; |
||
38 | |||
39 | /** |
||
40 | * @var RequestInterface |
||
41 | */ |
||
42 | private $request; |
||
43 | |||
44 | /** |
||
45 | * @param PromiseInterface $promise |
||
46 | * @param RequestInterface $request |
||
47 | */ |
||
48 | 326 | public function __construct(PromiseInterface $promise, RequestInterface $request) |
|
49 | { |
||
50 | 326 | $this->request = $request; |
|
51 | 326 | $this->state = self::PENDING; |
|
52 | $this->promise = $promise->then(function ($response) { |
||
53 | 315 | $this->response = $response; |
|
54 | 315 | $this->state = self::FULFILLED; |
|
55 | |||
56 | 315 | return $response; |
|
57 | 326 | }, function ($reason) use ($request) { |
|
58 | 10 | $this->state = self::REJECTED; |
|
59 | |||
60 | 10 | if ($reason instanceof HttplugException) { |
|
61 | 6 | $this->exception = $reason; |
|
62 | 10 | } elseif ($reason instanceof GuzzleExceptions\GuzzleException) { |
|
63 | 9 | $this->exception = $this->handleException($reason, $request); |
|
64 | 10 | } elseif ($reason instanceof \Exception) { |
|
65 | 1 | $this->exception = new \RuntimeException('Invalid exception returned from Guzzle6', 0, $reason); |
|
|
|||
66 | 1 | } else { |
|
67 | $this->exception = new \UnexpectedValueException('Reason returned from Guzzle6 must be an Exception', 0, $reason); |
||
68 | } |
||
69 | |||
70 | 10 | throw $this->exception; |
|
71 | 326 | }); |
|
72 | 326 | } |
|
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | 165 | public function then(callable $onFulfilled = null, callable $onRejected = null) |
|
81 | |||
82 | /** |
||
83 | * {@inheritdoc} |
||
84 | */ |
||
85 | 316 | public function getState() |
|
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | 325 | public function wait($unwrap = true) |
|
105 | |||
106 | /** |
||
107 | * Converts a Guzzle exception into an Httplug exception. |
||
108 | * |
||
109 | * @param GuzzleExceptions\GuzzleException $exception |
||
110 | * @param RequestInterface $request |
||
111 | * |
||
112 | * @return HttplugException |
||
113 | */ |
||
114 | 10 | private function handleException(GuzzleExceptions\GuzzleException $exception, RequestInterface $request) |
|
140 | } |
||
141 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..