Credentials::getEnvironment()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 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