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

Bring   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 134
ccs 36
cts 36
cp 1
rs 10
c 0
b 0
f 0
wmc 11

11 Methods

Rating   Name   Duplication   Size   Complexity  
A setTo() 0 4 1
A setFrom() 0 4 1
A setDeposit() 0 4 1
A getFrom() 0 3 1
A getDeposit() 0 3 1
A setStatus() 0 4 1
A getTo() 0 3 1
A create() 0 12 1
A getStatus() 0 3 1
A setWithdraw() 0 4 1
A getWithdraw() 0 3 1
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
10
class Bring
11
{
12
13
    /**
14
     * @var string
15
     */
16
    protected $status;
17
18
    /**
19
     * @var Wallet
20
     */
21
    protected $from;
22
23
    /**
24
     * @var Wallet
25
     */
26
    protected $to;
27
28
    /**
29
     * @var Transaction
30
     */
31
    protected $deposit;
32
33
    /**
34
     * @var Transaction
35
     */
36
    protected $withdraw;
37
38
    /**
39
     * @return string
40
     */
41 18
    public function getStatus(): string
42
    {
43 18
        return $this->status;
44
    }
45
46
    /**
47
     * @param string $status
48
     * @return static
49
     */
50 18
    public function setStatus(string $status): self
51
    {
52 18
        $this->status = $status;
53 18
        return $this;
54
    }
55
56
    /**
57
     * @return Wallet
58
     */
59 18
    public function getFrom(): Wallet
60
    {
61 18
        return $this->from;
62
    }
63
64
    /**
65
     * @param Wallet $from
66
     * @return static
67
     */
68 18
    public function setFrom(Wallet $from): self
69
    {
70 18
        $this->from = $from;
71 18
        return $this;
72
    }
73
74
    /**
75
     * @return Wallet
76
     */
77 18
    public function getTo(): Wallet
78
    {
79 18
        return $this->to;
80
    }
81
82
    /**
83
     * @param Wallet $to
84
     * @return static
85
     */
86 18
    public function setTo(Wallet $to): self
87
    {
88 18
        $this->to = $to;
89 18
        return $this;
90
    }
91
92
    /**
93
     * @return Transaction
94
     */
95 18
    public function getDeposit(): Transaction
96
    {
97 18
        return $this->deposit;
98
    }
99
100
    /**
101
     * @param Transaction $deposit
102
     * @return static
103
     */
104 18
    public function setDeposit(Transaction $deposit): self
105
    {
106 18
        $this->deposit = $deposit;
107 18
        return $this;
108
    }
109
110
    /**
111
     * @return Transaction
112
     */
113 18
    public function getWithdraw(): Transaction
114
    {
115 18
        return $this->withdraw;
116
    }
117
118
    /**
119
     * @param Transaction $withdraw
120
     * @return static
121
     */
122 18
    public function setWithdraw(Transaction $withdraw): self
123
    {
124 18
        $this->withdraw = $withdraw;
125 18
        return $this;
126
    }
127
128
    /**
129
     * @return Transfer
130
     * @throws
131
     */
132 18
    public function create(): Transfer
133
    {
134 18
        return app(Transfer::class)->create([
135 18
            'status' => $this->getStatus(),
136 18
            'deposit_id' => $this->getDeposit()->getKey(),
137 18
            'withdraw_id' => $this->getWithdraw()->getKey(),
138 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

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

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