Service::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace PHPSC\PagSeguro;
3
4
use PHPSC\PagSeguro\Client\Client;
5
use SimpleXMLElement;
6
7
/**
8
 * @author Luís Otávio Cobucci Oblonczyk <[email protected]>
9
 */
10
abstract class Service
11
{
12
    /**
13
     * @var Credentials
14
     */
15
    protected $credentials;
16
17
    /**
18
     * @var Client
19
     */
20
    private $client;
21
22
    /**
23
     * @param Credentials $credentials
24
     * @param Client $client
25
     */
26 15
    public function __construct(Credentials $credentials, Client $client = null)
27
    {
28 15
        $this->credentials = $credentials;
29 15
        $this->client = $client ?: new Client();
30 15
    }
31
32
    /**
33
     * @param string $resource
34
     * @param array $params
35
     *
36
     * @return SimpleXMLElement
37
     */
38 5
    protected function get($resource, array $params = [])
39
    {
40 5
        return $this->client->get($this->credentials->getWsUrl($resource, $params));
41
    }
42
43
    /**
44
     * @param string $resource
45
     * @param SimpleXMLElement $request
46
     *
47
     * @return SimpleXMLElement
48
     */
49 2
    protected function post($resource, SimpleXMLElement $request)
50
    {
51 2
        return $this->client->post($this->credentials->getWsUrl($resource), $request);
52
    }
53
}
54