1 | <?php |
||
23 | class Client implements HttpClient |
||
24 | { |
||
25 | /** |
||
26 | * @var ClientInterface |
||
27 | */ |
||
28 | private $client; |
||
29 | |||
30 | /** |
||
31 | * @var MessageFactory |
||
32 | */ |
||
33 | private $messageFactory; |
||
34 | |||
35 | /** |
||
36 | * @param ClientInterface|Browser|null $client |
||
37 | * @param MessageFactory|null $messageFactory |
||
38 | */ |
||
39 | 214 | public function __construct($client = null, MessageFactory $messageFactory = null) |
|
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | */ |
||
65 | public function sendRequest(RequestInterface $request) |
||
66 | { |
||
67 | $this->assertRequestHasValidBody($request); |
||
68 | |||
69 | $buzzRequest = $this->createRequest($request); |
||
70 | |||
71 | try { |
||
72 | $buzzResponse = new BuzzResponse(); |
||
73 | $this->client->send($buzzRequest, $buzzResponse); |
||
74 | } catch (BuzzException\ClientException $e) { |
||
75 | throw new HttplugException\TransferException($e->getMessage(), 0, $e); |
||
76 | } |
||
77 | |||
78 | return $this->createResponse($buzzResponse); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Converts a PSR request into a BuzzRequest request. |
||
83 | * |
||
84 | * @param RequestInterface $request |
||
85 | * |
||
86 | * @return BuzzRequest |
||
87 | */ |
||
88 | private function createRequest(RequestInterface $request) |
||
100 | |||
101 | /** |
||
102 | * Converts a Buzz response into a PSR response. |
||
103 | * |
||
104 | * @param BuzzResponse $response |
||
105 | * |
||
106 | * @return ResponseInterface |
||
107 | */ |
||
108 | private function createResponse(BuzzResponse $response) |
||
120 | |||
121 | /** |
||
122 | * Apply headers on a Buzz request. |
||
123 | * |
||
124 | * @param RequestInterface $request |
||
125 | * @param BuzzRequest $buzzRequest |
||
126 | */ |
||
127 | private function addPsrHeadersToBuzzRequest(RequestInterface $request, BuzzRequest $buzzRequest) |
||
136 | |||
137 | /** |
||
138 | * Get headers from a Buzz response. |
||
139 | * |
||
140 | * @param BuzzResponse $response |
||
141 | * |
||
142 | * @return array |
||
143 | */ |
||
144 | private function getBuzzHeaders(BuzzResponse $response) |
||
156 | |||
157 | /** |
||
158 | * Assert that the request has a valid body based on the request method. |
||
159 | * |
||
160 | * @param RequestInterface $request |
||
161 | */ |
||
162 | private function assertRequestHasValidBody(RequestInterface $request) |
||
183 | } |
||
184 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.