Completed
Push — master ( d2116f...60eecd )
by Dmitry
02:40
created

Transaction   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 15
lcom 1
cbo 0
dl 0
loc 127
rs 10
c 1
b 0
f 0
ccs 0
cts 56
cp 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getMerchant() 0 4 1
A isCompleted() 0 4 1
A cancel() 0 5 1
A isConfirmed() 0 4 1
A getId() 0 4 1
A getParameters() 0 4 1
A setParameters() 0 4 1
A addParameter() 0 8 2
A toArray() 0 9 1
A getParameter() 0 4 2
A complete() 0 4 1
A getSuccess() 0 4 1
1
<?php
2
3
namespace hiqdev\yii2\merchant\transactions;
4
5
class Transaction
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $id;
11
12
    /**
13
     * @var array
14
     */
15
    protected $parameters;
16
17
    /**
18
     * @var boolean
19
     */
20
    protected $success;
21
22
    /**
23
     * @var string
24
     */
25
    protected $merchant;
26
27
    /**
28
     * Transaction constructor.
29
     * @param string $id
30
     * @param $merchant
31
     */
32
    public function __construct($id, $merchant)
33
    {
34
        $this->id = $id;
35
        $this->merchant = $merchant;
36
    }
37
38
    public function getMerchant()
39
    {
40
        return $this->merchant;
41
    }
42
43
    /**
44
     * @return bool
45
     */
46
    public function isCompleted()
47
    {
48
        return $this->success !== null;
49
    }
50
51
    public function complete()
52
    {
53
        $this->success = true;
54
    }
55
56
    public function cancel($error = null)
57
    {
58
        $this->success = false;
59
        $this->addParameter('error', $error);
60
    }
61
62
    public function isConfirmed()
63
    {
64
        return $this->success === true;
65
    }
66
67
    /**
68
     * @return bool
69
     */
70
    public function getSuccess()
71
    {
72
        return $this->success;
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    public function getId()
79
    {
80
        return $this->id;
81
    }
82
83
    /**
84
     * @return array
85
     */
86
    public function getParameters()
87
    {
88
        return $this->parameters;
89
    }
90
91
    /**
92
     * @param array $parameters
93
     */
94
    public function setParameters($parameters)
95
    {
96
        $this->parameters = $parameters;
97
    }
98
99
    /**
100
     * Adds parameter $parameter with value $value to the parameters
101
     *
102
     * @param string $parameter
103
     * @param mixed $value
104
     */
105
    public function addParameter($parameter, $value)
106
    {
107
        if (isset($this->parameters[$parameter])) {
108
            return;
109
        }
110
111
        $this->parameters[$parameter] = $value;
112
    }
113
114
    /**
115
     * @return array
116
     */
117
    public function toArray()
118
    {
119
        return [
120
            'id' => $this->getId(),
121
            'merchant' => $this->getMerchant(),
122
            'parameters' => $this->getParameters(),
123
            'success' => $this->getSuccess()
124
        ];
125
    }
126
127
    public function getParameter($parameter)
128
    {
129
        return isset($this->parameters[$parameter]) ? $this->parameters[$parameter] : null;
130
    }
131
}
132