Client   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 0
loc 86
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getParameter() 0 4 2
A setParameter() 0 6 1
B loadParameters() 0 25 7
1
<?php
2
3
namespace PayGo;
4
5
6
use PayGo\Transactions\Constants\PayGoTransactionParameterConst;
7
8
/**
9
 * Class Client
10
 * @package PayGo
11
 */
12
class Client
13
{
14
15
    /**
16
     * Timeout padrão
17
     *
18
     * @var integer
19
     */
20
    const PAYGO_TRANSACTIONS_TIMEOUT_DEFAULT = 10;
21
22
    /**
23
     * Parâmetros, pré inicializado com valores padrão
24
     *
25
     * @var array
26
     */
27
    private $params = [
28
        PayGoTransactionParameterConst::PAYGO_TRANSACTIONS_TIMEOUT => self::PAYGO_TRANSACTIONS_TIMEOUT_DEFAULT,
29
    ];
30
31
    /**
32
     * Client constructor.
33
     *
34
     * @param array|null $params
35
     * @throws \Exception
36
     */
37
    public function __construct(array $params = null)
38
    {
39
        $this->loadParameters($params);
40
    }
41
42
    /**
43
     * Obter parâmetro
44
     *
45
     * @param $key
46
     * @return mixed
47
     */
48
    public function getParameter($key)
49
    {
50
        return isset($this->params[$key]) ? $this->params[$key] : null;
51
    }
52
53
    /**
54
     * @param $key
55
     * @param $value
56
     * @return $this
57
     * @throws \Exception
58
     */
59
    public function setParameter($key, $value)
60
    {
61
        $this->params[$key] = $value;
62
        $this->loadParameters($this->params);
63
        return $this;
64
    }
65
66
    /**
67
     * @param $params
68
     * @throws \Exception
69
     */
70
    private function loadParameters($params)
71
    {
72
        $this->params[PayGoTransactionParameterConst::PAYGO_TRANSACTIONS_HOST] =
73
            getenv('PAYGO_TRANSACTIONS_HOST');
74
        $this->params[PayGoTransactionParameterConst::PAYGO_TRANSACTIONS_TIMEOUT] =
75
            getenv('PAYGO_TRANSACTIONS_TIMEOUT');
76
        $this->params[PayGoTransactionParameterConst::PAYGO_TRANSACTIONS_TOKEN] =
77
            getenv('PAYGO_TRANSACTIONS_TOKEN');
78
79
        if(!is_null($params))
80
            foreach ($params as $key => $param)
81
            {
82
                if(!in_array($key, [
83
                    PayGoTransactionParameterConst::PAYGO_TRANSACTIONS_HOST,
84
                    PayGoTransactionParameterConst::PAYGO_TRANSACTIONS_TIMEOUT,
85
                    PayGoTransactionParameterConst::PAYGO_TRANSACTIONS_TOKEN,
86
                ]))
87
                    throw new \Exception(sprintf("Parâmetro %s inválido", $key));
88
            }
89
90
        if(!is_null($params) && is_array($params)){
91
            foreach ($params as $key => $value)
92
                $this->params[$key] = $value;
93
        }
94
    }
95
96
97
}
98
99
100
101
102
103
104
105