Completed
Pull Request — develop (#45)
by
unknown
04:10
created

Client::post()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 6
Bugs 0 Features 0
Metric Value
c 6
b 0
f 0
dl 0
loc 10
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 2
crap 2
1
<?php
2
namespace PHPSC\PagSeguro\Client;
3
4
use GuzzleHttp\Client as HttpClient;
5
use GuzzleHttp\Exception\RequestException;
6
use SimpleXMLElement;
7
8
/**
9
 * @author Luís Otávio Cobucci Oblonczyk <[email protected]>
10
 * @author Paulo Peixoto Filho <[email protected]>
11
 */
12
13
class Client {
14
	/**
15
	 * @var HttpClient
16
	 */
17
	private $client;
18
19
	/**
20
	 * @param HttpClient $client
21
	 */
22 6
	public function __construct(HttpClient $client = null) {
23
		$this->client = $client ?: new HttpClient();
24 6
	}
25 6
26 6
	/**
27
	 * @param string $url
28
	 * @param SimpleXMLElement $body
29
	 *
30
	 * @return SimpleXMLElement
31
	 */
32
	public function post($url, SimpleXMLElement $body) {
33 2
34
		try {
35 2
			$response = $this->client->post($url, ['headers' => ['Content-Type' => 'application/xml; charset=UTF-8'], 'body' => $body->asXML(), 'verify' => false]);
36 1
		} catch (RequestException $e) {
37
			throw PagSeguroException::create($e->getResponse());
0 ignored issues
show
Compatibility introduced by
$e->getResponse() of type object<Psr\Http\Message\ResponseInterface> is not a sub-type of object<GuzzleHttp\Psr7\Response>. It seems like you assume a concrete implementation of the interface Psr\Http\Message\ResponseInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
38
		}
39 1
40
		return new SimpleXMLElement((string) $response->getBody());
41
	}
42
43
	/**
44
	 * @param string $url
45
	 *
46
	 * @return SimpleXMLElement
47
	 */
48 1
	public function get($url) {
49
		try {
50 1
			$response = $this->client->get($url, ['verify' => false]);
51 1
		} catch (RequestException $e) {
52
			throw PagSeguroException::create($e->getResponse());
0 ignored issues
show
Compatibility introduced by
$e->getResponse() of type object<Psr\Http\Message\ResponseInterface> is not a sub-type of object<GuzzleHttp\Psr7\Response>. It seems like you assume a concrete implementation of the interface Psr\Http\Message\ResponseInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
53 1
		}
54 1
55
		return new SimpleXMLElement((string) $response->getBody());
56 1
	}
57
}
58