Credentials::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 3
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace PHPSC\PagSeguro;
3
4
use PHPSC\PagSeguro\Environment;
5
use PHPSC\PagSeguro\Environments\Production;
6
7
/**
8
 * @author Luís Otávio Cobucci Oblonczyk <[email protected]>
9
 */
10
class Credentials
11
{
12
    /**
13
     * @var string
14
     */
15
    private $email;
16
17
    /**
18
     * @var string
19
     */
20
    private $token;
21
22
    /**
23
     * @var Environment
24
     */
25
    private $environment;
26
27
    /**
28
     * @param string $email
29
     * @param string $token
30
     * @param Environment $environment
31
     */
32 11
    public function __construct($email, $token, Environment $environment = null)
33
    {
34 11
        $this->email = substr($email, 0, 60);
35 11
        $this->token = substr($token, 0, 32);
36 11
        $this->environment = $environment ?: new Production();
37 11
    }
38
39
    /**
40
     * @param string $resource
41
     *
42
     * @return string
43
     */
44 2
    public function getUrl($resource)
45
    {
46 2
        return $this->environment->getUrl($resource);
47
    }
48
49
    /**
50
     * @param string $resource
51
     * @param array $params
52
     *
53
     * @return string
54
     */
55 4
    public function getWsUrl($resource, array $params = [])
56
    {
57 4
        $params = array_merge(
58 4
            $params,
59 4
            ['email' => $this->email, 'token' => $this->token]
60
        );
61
62 4
        return sprintf(
63 4
            '%s?%s',
64 4
            $this->environment->getWsUrl($resource),
65 4
            http_build_query($params)
66
        );
67
    }
68
}
69