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

Client   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 6
c 6
b 0
f 0
lcom 1
cbo 3
dl 0
loc 45
ccs 15
cts 15
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 2
A post() 0 10 2
A get() 0 9 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