Completed
Pull Request — master (#56)
by
unknown
07:46
created

Credentials   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 59
ccs 15
cts 15
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getUrl() 0 4 1
A __construct() 0 6 2
A getWsUrl() 0 13 1
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