Passed
Push — master ( bdfaa4...00ab5d )
by Radosław
02:20
created

Config::__construct()   A

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 7
    public function __construct(array $params)
54
    {
55 7
        $requiredParams = ['apiKey', 'login', 'passwordHash', 'isSandbox', 'countryCode'];
56
57 7
        foreach ($requiredParams as $property) {
58 7
            if (!array_key_exists($property, $params)) {
59 5
                throw new InvalidArgumentException("{$property} is required in params array");
60
            }
61
62 6
            $this->{$property} = $params[$property];
63 6
        }
64 2
    }
65
66
67 1
    public function getApiKey()
68
    {
69 1
        return $this->apiKey;
70
    }
71
72
73 1
    public function getLogin()
74
    {
75 1
        return $this->login;
76
    }
77
78
79 1
    public function getPasswordHash()
80
    {
81 1
        return $this->passwordHash;
82
    }
83
84
85 1
    public function getIsSandbox()
86
    {
87 1
        return $this->isSandbox;
88
    }
89
90
91 1
    public function getCountryCode()
92
    {
93 1
        return $this->countryCode;
94
    }
95
96
97 1
    public function getPasswordPlain()
98
    {
99 1
        return $this->passwordPlain;
100
    }
101
102
103 1
    public function setPasswordPlain($passwordPlain)
104
    {
105 1
        $this->passwordPlain = $passwordPlain;
106 1
    }
107
108
109
}
110