Passed
Push — master ( 94f1bd...3747ce )
by Jonathan
02:16
created

Configuration   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Test Coverage

Coverage 93.02%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 35
c 1
b 0
f 0
dl 0
loc 120
ccs 40
cts 43
cp 0.9302
rs 10
wmc 16

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getCertificateVerify() 0 3 1
A setTransactionKey() 0 4 1
A getRequestMode() 0 3 1
A setSandbox() 0 4 1
A getSandbox() 0 3 1
A __construct() 0 21 6
A setRequestMode() 0 4 1
A getApiLogin() 0 3 1
A setCertificateVerify() 0 4 1
A setApiLogin() 0 4 1
A getTransactionKey() 0 3 1
1
<?php
2
3
namespace CommerceGuys\AuthNet;
4
5
class Configuration
6
{
7
    private $apiLogin;
8
    private $transactionKey;
9
    private $sandbox;
10
    private $requestMode = 'xml';
11
    private $certificateVerify;
12
13 23
    public function __construct(array $config)
14
    {
15 23
        foreach (['api_login', 'transaction_key', 'sandbox'] as $required_key) {
16 23
            if (!isset($config[$required_key])) {
17
                throw new \InvalidArgumentException("You must provide a value for $required_key");
18
            }
19 23
        }
20 23
        $this->apiLogin = $config['api_login'];
21 23
        $this->transactionKey = $config['transaction_key'];
22 23
        $this->sandbox = $config['sandbox'];
23
24 23
        if (isset($config['request_mode'])) {
25 19
            $this->requestMode = $config['request_mode'];
26 19
        }
27
28 23
        if (isset($config['certificate_verify'])) {
29 19
            $this->certificateVerify = $config['certificate_verify'];
30 23
        } elseif ($cert = ini_get('curl.cainfo')) {
31
            $this->certificateVerify = $cert;
32
        } else {
33 4
            $this->certificateVerify = __DIR__ . '/../resources/cert.pem';
34
        }
35 23
    }
36
37
    /**
38
     * @return mixed
39
     */
40 18
    public function getApiLogin()
41
    {
42 18
        return $this->apiLogin;
43
    }
44
45
    /**
46
     * @param mixed $apiLogin
47
     * @return Configuration
48
     */
49 1
    public function setApiLogin($apiLogin)
50
    {
51 1
        $this->apiLogin = $apiLogin;
52 1
        return $this;
53
    }
54
55
    /**
56
     * @return mixed
57
     */
58 18
    public function getTransactionKey()
59
    {
60 18
        return $this->transactionKey;
61
    }
62
63
    /**
64
     * @param mixed $transactionKey
65
     * @return Configuration
66
     */
67 1
    public function setTransactionKey($transactionKey)
68
    {
69 1
        $this->transactionKey = $transactionKey;
70 1
        return $this;
71
    }
72
73
    /**
74
     * @return mixed
75
     */
76 14
    public function getSandbox()
77
    {
78 14
        return $this->sandbox;
79
    }
80
81
    /**
82
     * @param mixed $sandbox
83
     * @return Configuration
84
     */
85 1
    public function setSandbox($sandbox)
86
    {
87 1
        $this->sandbox = $sandbox;
88 1
        return $this;
89
    }
90
91
    /**
92
     * @return mixed|string
93
     */
94 14
    public function getRequestMode()
95
    {
96 14
        return $this->requestMode;
97
    }
98
99
    /**
100
     * @param mixed|string $requestMode
101
     * @return Configuration
102
     */
103 1
    public function setRequestMode($requestMode)
104
    {
105 1
        $this->requestMode = $requestMode;
106 1
        return $this;
107
    }
108
109
    /**
110
     * @return mixed|string
111
     */
112 14
    public function getCertificateVerify()
113
    {
114 14
        return $this->certificateVerify;
115
    }
116
117
    /**
118
     * @param mixed|string $value
119
     * @return Configuration
120
     */
121 1
    public function setCertificateVerify($value)
122
    {
123 1
        $this->certificateVerify = $value;
124 1
        return $this;
125
    }
126
}
127