Completed
Pull Request — develop (#45)
by
unknown
04:22
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
Documentation introduced by
$e->getResponse() is of type object<Psr\Http\Message\ResponseInterface>, but the function expects a object<GuzzleHttp\Message\Response>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
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
Documentation introduced by
$e->getResponse() is of type object<Psr\Http\Message\ResponseInterface>, but the function expects a object<GuzzleHttp\Message\Response>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
53 1
		}
54 1
55
		return new SimpleXMLElement((string) $response->getBody());
56 1
	}
57
}
58