1 | <?php |
||
12 | class Client |
||
13 | { |
||
14 | private $client; |
||
15 | |||
16 | /** |
||
17 | * @param ClientInterface $client |
||
18 | */ |
||
19 | 3 | public function __construct(ClientInterface $client = null) |
|
23 | |||
24 | /** |
||
25 | * @param string $url |
||
26 | * @param SimpleXMLElement $body |
||
27 | * |
||
28 | * @return SimpleXMLElement |
||
29 | */ |
||
30 | 1 | public function post($url, SimpleXMLElement $body) |
|
31 | { |
||
32 | try { |
||
33 | 1 | $response = $this->client->request( |
|
34 | 1 | 'POST', |
|
35 | $url, |
||
36 | [ |
||
37 | 1 | 'headers' => ['Content-Type' => 'application/xml; charset=UTF-8'], |
|
38 | 1 | 'body' => $body->asXML(), |
|
39 | 'verify' => false |
||
40 | ] |
||
41 | ); |
||
42 | |||
43 | 1 | return new SimpleXMLElement($response->getBody()); |
|
44 | } catch (RequestException $e) { |
||
45 | throw PagSeguroException::create($e->getResponse(), $e); |
||
|
|||
46 | } |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param string $url |
||
51 | * |
||
52 | * @return SimpleXMLElement |
||
53 | */ |
||
54 | 1 | public function get($url) |
|
64 | } |
||
65 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: