Passed
Pull Request — master (#40)
by Бабичев
05:26
created

Bring::setDeposit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Bavix\Wallet\Objects;
4
5
use Bavix\Wallet\Interfaces\Wallet;
6
use Bavix\Wallet\Models\Transaction;
7
use Bavix\Wallet\Models\Transfer;
8
use Ramsey\Uuid\Uuid;
9
use function abs;
10
11
class Bring
12
{
13
14
    /**
15
     * @var string
16
     */
17
    protected $status;
18
19
    /**
20
     * @var Wallet
21
     */
22
    protected $from;
23
24
    /**
25
     * @var Wallet
26
     */
27
    protected $to;
28
29
    /**
30
     * @var Transaction
31
     */
32
    protected $deposit;
33
34
    /**
35
     * @var Transaction
36
     */
37
    protected $withdraw;
38
39
    /**
40
     * @var string
41
     */
42
    protected $uuid;
43
44
    /**
45
     * Bring constructor.
46
     * @throws
47
     */
48 20
    public function __construct()
49
    {
50 20
        $this->uuid = Uuid::uuid4()->toString();
51 20
    }
52
53
    /**
54
     * @return string
55
     */
56 20
    public function getStatus(): string
57
    {
58 20
        return $this->status;
59
    }
60
61
    /**
62
     * @param string $status
63
     * @return static
64
     */
65 20
    public function setStatus(string $status): self
66
    {
67 20
        $this->status = $status;
68 20
        return $this;
69
    }
70
71
    /**
72
     * @return Wallet
73
     */
74 20
    public function getFrom(): Wallet
75
    {
76 20
        return $this->from;
77
    }
78
79
    /**
80
     * @param Wallet $from
81
     * @return static
82
     */
83 20
    public function setFrom(Wallet $from): self
84
    {
85 20
        $this->from = $from;
86 20
        return $this;
87
    }
88
89
    /**
90
     * @return Wallet
91
     */
92 20
    public function getTo(): Wallet
93
    {
94 20
        return $this->to;
95
    }
96
97
    /**
98
     * @param Wallet $to
99
     * @return static
100
     */
101 20
    public function setTo(Wallet $to): self
102
    {
103 20
        $this->to = $to;
104 20
        return $this;
105
    }
106
107
    /**
108
     * @return Transaction
109
     */
110 20
    public function getDeposit(): Transaction
111
    {
112 20
        return $this->deposit;
113
    }
114
115
    /**
116
     * @param Transaction $deposit
117
     * @return static
118
     */
119 20
    public function setDeposit(Transaction $deposit): self
120
    {
121 20
        $this->deposit = $deposit;
122 20
        return $this;
123
    }
124
125
    /**
126
     * @return Transaction
127
     */
128 20
    public function getWithdraw(): Transaction
129
    {
130 20
        return $this->withdraw;
131
    }
132
133
    /**
134
     * @param Transaction $withdraw
135
     * @return static
136
     */
137 20
    public function setWithdraw(Transaction $withdraw): self
138
    {
139 20
        $this->withdraw = $withdraw;
140 20
        return $this;
141
    }
142
143
    /**
144
     * @return string
145
     */
146 20
    public function getUuid(): string
147
    {
148 20
        return $this->uuid;
149
    }
150
151
    /**
152
     * @return Transfer
153
     * @throws
154
     */
155 20
    public function create(): Transfer
156
    {
157 20
        return app(Transfer::class)
158 20
            ->create($this->toArray());
159
    }
160
161
    /**
162
     * @return array
163
     * @throws
164
     */
165 20
    public function toArray(): array
166
    {
167
        return [
168 20
            'status' => $this->getStatus(),
169 20
            'deposit_id' => $this->getDeposit()->getKey(),
170 20
            'withdraw_id' => $this->getWithdraw()->getKey(),
171 20
            'from_type' => $this->getFrom()->getMorphClass(),
0 ignored issues
show
Bug introduced by
The method getMorphClass() does not exist on Bavix\Wallet\Interfaces\Wallet. It seems like you code against a sub-type of said class. However, the method does not exist in Bavix\Wallet\Interfaces\Customer or Bavix\Wallet\Interfaces\Product. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

171
            'from_type' => $this->getFrom()->/** @scrutinizer ignore-call */ getMorphClass(),
Loading history...
172 20
            'from_id' => $this->getFrom()->getKey(),
0 ignored issues
show
Bug introduced by
The method getKey() does not exist on Bavix\Wallet\Interfaces\Wallet. It seems like you code against a sub-type of said class. However, the method does not exist in Bavix\Wallet\Interfaces\Customer or Bavix\Wallet\Interfaces\Product. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

172
            'from_id' => $this->getFrom()->/** @scrutinizer ignore-call */ getKey(),
Loading history...
173 20
            'to_type' => $this->getTo()->getMorphClass(),
174 20
            'to_id' => $this->getTo()->getKey(),
175 20
            'fee' => abs($this->getWithdraw()->amount) - abs($this->getDeposit()->amount),
176 20
            'uuid' => $this->getUuid(),
177
        ];
178
    }
179
180
}
181