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

Bring::getWithdraw()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
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
     * @return string
41
     */
42 18
    public function getStatus(): string
43
    {
44 18
        return $this->status;
45
    }
46
47
    /**
48
     * @param string $status
49
     * @return static
50
     */
51 18
    public function setStatus(string $status): self
52
    {
53 18
        $this->status = $status;
54 18
        return $this;
55
    }
56
57
    /**
58
     * @return Wallet
59
     */
60 18
    public function getFrom(): Wallet
61
    {
62 18
        return $this->from;
63
    }
64
65
    /**
66
     * @param Wallet $from
67
     * @return static
68
     */
69 18
    public function setFrom(Wallet $from): self
70
    {
71 18
        $this->from = $from;
72 18
        return $this;
73
    }
74
75
    /**
76
     * @return Wallet
77
     */
78 18
    public function getTo(): Wallet
79
    {
80 18
        return $this->to;
81
    }
82
83
    /**
84
     * @param Wallet $to
85
     * @return static
86
     */
87 18
    public function setTo(Wallet $to): self
88
    {
89 18
        $this->to = $to;
90 18
        return $this;
91
    }
92
93
    /**
94
     * @return Transaction
95
     */
96 18
    public function getDeposit(): Transaction
97
    {
98 18
        return $this->deposit;
99
    }
100
101
    /**
102
     * @param Transaction $deposit
103
     * @return static
104
     */
105 18
    public function setDeposit(Transaction $deposit): self
106
    {
107 18
        $this->deposit = $deposit;
108 18
        return $this;
109
    }
110
111
    /**
112
     * @return Transaction
113
     */
114 18
    public function getWithdraw(): Transaction
115
    {
116 18
        return $this->withdraw;
117
    }
118
119
    /**
120
     * @param Transaction $withdraw
121
     * @return static
122
     */
123 18
    public function setWithdraw(Transaction $withdraw): self
124
    {
125 18
        $this->withdraw = $withdraw;
126 18
        return $this;
127
    }
128
129
    /**
130
     * @return Transfer
131
     * @throws
132
     */
133 18
    public function create(): Transfer
134
    {
135 18
        return app(Transfer::class)->create([
136 18
            'status' => $this->getStatus(),
137 18
            'deposit_id' => $this->getDeposit()->getKey(),
138 18
            'withdraw_id' => $this->getWithdraw()->getKey(),
139 18
            '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

139
            'from_type' => $this->getFrom()->/** @scrutinizer ignore-call */ getMorphClass(),
Loading history...
140 18
            '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

140
            'from_id' => $this->getFrom()->/** @scrutinizer ignore-call */ getKey(),
Loading history...
141 18
            'to_type' => $this->getTo()->getMorphClass(),
142 18
            'to_id' => $this->getTo()->getKey(),
143 18
            'fee' => abs($this->getWithdraw()->amount) - abs($this->getDeposit()->amount),
144 18
            'uuid' => Uuid::uuid4()->toString(),
145
        ]);
146
    }
147
148
}
149