Credentials   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 63
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A getUrl() 0 4 1
A getWsUrl() 0 8 2
A getEnvironment() 0 4 1
A getApiKey() 0 4 1
1
<?php
2
3
namespace WSW\SiftScience;
4
5
use WSW\SiftScience\Environments\Environment;
6
use WSW\SiftScience\Environments\Production;
7
8
/**
9
 * Class Credentials
10
 *
11
 * @package WSW\SiftScience
12
 * @author Ronaldo Matos Rodrigues <[email protected]>
13
 */
14
class Credentials
15
{
16
    /**
17
     * @var string
18
     */
19
    private $apiKey;
20
21
    /**
22
     * @var Environment
23
     */
24
    private $environment;
25
26
    /**
27
     * @param string $apiKey
28
     * @param Environment $environment
29
     */
30 15
    public function __construct($apiKey, Environment $environment = null)
31
    {
32 15
        $this->apiKey = substr($apiKey, 0, 16);
33 15
        $this->environment = $environment ?: new Production();
34 15
    }
35
36
    /**
37
     * @param string $resource
38
     *
39
     * @return string
40
     */
41 1
    public function getUrl($resource)
42
    {
43 1
        return $this->environment->getUrl($resource);
44
    }
45
46
    /**
47
     * @param string $resource
48
     * @param array $params
49
     *
50
     * @return string
51
     */
52 9
    public function getWsUrl($resource, array $params = [])
53
    {
54 9
        if (empty($params)) {
55 8
            return $this->environment->getWsUrl($resource);
56
        }
57
58 1
        return sprintf('%s?%s', $this->environment->getWsUrl($resource), http_build_query($params));
59
    }
60
61
    /**
62
     * @return Environment
63
     */
64 1
    public function getEnvironment()
65
    {
66 1
        return $this->environment;
67
    }
68
69
    /**
70
     * @return string
71
     */
72 8
    public function getApiKey()
73
    {
74 8
        return $this->apiKey;
75
    }
76
}
77