Test Failed
Pull Request — master (#83)
by Бабичев
13:48 queued 09:03
created

Bring::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 12
ccs 0
cts 12
cp 0
crap 2
rs 9.9332
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
    public function __construct()
49
    {
50
        $this->uuid = Uuid::uuid4()->toString();
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getStatus(): string
57
    {
58
        return $this->status;
59
    }
60
61
    /**
62
     * @param string $status
63
     * @return static
64
     */
65
    public function setStatus(string $status): self
66
    {
67
        $this->status = $status;
68
        return $this;
69
    }
70
71
    /**
72
     * @return Wallet
73
     */
74
    public function getFrom(): Wallet
75
    {
76
        return $this->from;
77
    }
78
79
    /**
80
     * @param Wallet $from
81
     * @return static
82
     */
83
    public function setFrom(Wallet $from): self
84
    {
85
        $this->from = $from;
86
        return $this;
87
    }
88
89
    /**
90
     * @return Wallet
91
     */
92
    public function getTo(): Wallet
93
    {
94
        return $this->to;
95
    }
96
97
    /**
98
     * @param Wallet $to
99
     * @return static
100
     */
101
    public function setTo(Wallet $to): self
102
    {
103
        $this->to = $to;
104
        return $this;
105
    }
106
107
    /**
108
     * @return Transaction
109
     */
110
    public function getDeposit(): Transaction
111
    {
112
        return $this->deposit;
113
    }
114
115
    /**
116
     * @param Transaction $deposit
117
     * @return static
118
     */
119
    public function setDeposit(Transaction $deposit): self
120
    {
121
        $this->deposit = $deposit;
122
        return $this;
123
    }
124
125
    /**
126
     * @return Transaction
127
     */
128
    public function getWithdraw(): Transaction
129
    {
130
        return $this->withdraw;
131
    }
132
133
    /**
134
     * @param Transaction $withdraw
135
     * @return static
136
     */
137
    public function setWithdraw(Transaction $withdraw): self
138
    {
139
        $this->withdraw = $withdraw;
140
        return $this;
141
    }
142
143
    /**
144
     * @return string
145
     */
146
    public function getUuid(): string
147
    {
148
        return $this->uuid;
149
    }
150
151
    /**
152
     * @return Transfer
153
     * @throws
154
     */
155
    public function create(): Transfer
156
    {
157
        return app(Transfer::class)
158
            ->create($this->toArray());
159
    }
160
161
    /**
162
     * @return array
163
     * @throws
164
     */
165
    public function toArray(): array
166
    {
167
        return [
168
            'status' => $this->getStatus(),
169
            'deposit_id' => $this->getDeposit()->getKey(),
170
            'withdraw_id' => $this->getWithdraw()->getKey(),
171
            '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
            '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
            'to_type' => $this->getTo()->getMorphClass(),
174
            'to_id' => $this->getTo()->getKey(),
175
            'fee' => abs($this->getWithdraw()->amount) - abs($this->getDeposit()->amount),
176
            'uuid' => $this->getUuid(),
177
        ];
178
    }
179
180
}
181