Config::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Radowoj\Yaah;
4
5
use InvalidArgumentException;
6
7
class Config
8
{
9
    /**
10
     * Allegro WebAPI key
11
     * @var string
12
     */
13
    protected $apiKey = null;
14
15
    /**
16
     * Allegro login
17
     * @var string
18
     */
19
    protected $login = null;
20
21
    /**
22
     * Allegro password hash (base64 of sha-256 of plaintext password)
23
     * @var string
24
     */
25
    protected $passwordHash = null;
26
27
    /**
28
     * Whether to use sandbox
29
     * @var boolean
30
     */
31
    protected $isSandbox = null;
32
33
    /**
34
     * @var string country code required by WebAPI for certain operations
35
     */
36
    /**
37
     * [$countryCode description]
38
     * @var [type]
39
     */
40
    protected $countryCode = null;
41
42
    /**
43
     * Plain text password
44
     * Useful for those moments when sandbox refuses to work with hashed password
45
     * ("wrong username or password" exception despite using correct credentials).
46
     * It is not recommended to use it otherwise, always keep hashed, not plaintext
47
     * password in your config for safety reasons.
48
     * @var string
49
     */
50
    protected $passwordPlain = null;
51
52
53 13
    public function __construct(array $params)
54
    {
55 13
        $requiredParams = ['apiKey', 'login', 'passwordHash', 'isSandbox', 'countryCode'];
56
57 13
        foreach ($requiredParams as $property) {
58 13
            if (!array_key_exists($property, $params)) {
59 5
                throw new InvalidArgumentException("{$property} is required in params array");
60
            }
61
62 12
            $this->{$property} = $params[$property];
63 12
        }
64 8
    }
65
66
67 7
    public function getApiKey()
68
    {
69 7
        return $this->apiKey;
70
    }
71
72
73 8
    public function getLogin()
74
    {
75 8
        return $this->login;
76
    }
77
78
79 8
    public function getPasswordHash()
80
    {
81 8
        return $this->passwordHash;
82
    }
83
84
85 1
    public function getIsSandbox()
86
    {
87 1
        return $this->isSandbox;
88
    }
89
90
91 8
    public function getCountryCode()
92
    {
93 8
        return $this->countryCode;
94
    }
95
96
97 3
    public function getPasswordPlain()
98
    {
99 3
        return $this->passwordPlain;
100
    }
101
102
103 2
    public function setPasswordPlain($passwordPlain)
104
    {
105 2
        $this->passwordPlain = $passwordPlain;
106 2
    }
107
108
109
}
110