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

Operation::getAmount()   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 Ramsey\Uuid\Uuid;
8
9
class Operation
10
{
11
12
    /**
13
     * @var string
14
     */
15
    protected $type;
16
17
    /**
18
     * @var string
19
     */
20
    protected $uuid;
21
22
    /**
23
     * @var int
24
     */
25
    protected $amount;
26
27
    /**
28
     * @var null|array
29
     */
30
    protected $meta;
31
32
    /**
33
     * @var bool
34
     */
35
    protected $confirmed;
36
37
    /**
38
     * Transaction constructor.
39
     * @throws
40
     */
41 28
    public function __construct()
42
    {
43 28
        $this->uuid = Uuid::uuid4()->toString();
44 28
    }
45
46
    /**
47
     * @return string
48
     */
49 28
    public function getType(): string
50
    {
51 28
        return $this->type;
52
    }
53
54
    /**
55
     * @return string
56
     */
57 28
    public function getUuid(): string
58
    {
59 28
        return $this->uuid;
60
    }
61
62
    /**
63
     * @return int
64
     */
65 28
    public function getAmount(): int
66
    {
67 28
        return $this->amount;
68
    }
69
70
    /**
71
     * @return array|null
72
     */
73 28
    public function getMeta(): ?array
74
    {
75 28
        return $this->meta;
76
    }
77
78
    /**
79
     * @return bool
80
     */
81 28
    public function isConfirmed(): bool
82
    {
83 28
        return $this->confirmed;
84
    }
85
86
    /**
87
     * @param string $type
88
     * @return static
89
     */
90 28
    public function setType(string $type): self
91
    {
92 28
        $this->type = $type;
93 28
        return $this;
94
    }
95
96
    /**
97
     * @param string $uuid
98
     * @return static
99
     */
100
    public function setUuid(string $uuid): self
101
    {
102
        $this->uuid = $uuid;
103
        return $this;
104
    }
105
106
    /**
107
     * @param int $amount
108
     * @return static
109
     */
110 28
    public function setAmount(int $amount): self
111
    {
112 28
        $this->amount = $amount;
113 28
        return $this;
114
    }
115
116
    /**
117
     * @param array|null $meta
118
     * @return static
119
     */
120 28
    public function setMeta(?array $meta): self
121
    {
122 28
        $this->meta = $meta;
123 28
        return $this;
124
    }
125
126
    /**
127
     * @param bool $confirmed
128
     * @return static
129
     */
130 28
    public function setConfirmed(bool $confirmed): self
131
    {
132 28
        $this->confirmed = $confirmed;
133 28
        return $this;
134
    }
135
136
    /**
137
     * @param Wallet $wallet
138
     * @return Transaction
139
     */
140 28
    public function create(Wallet $wallet): Transaction
141
    {
142
        /**
143
         * @var Transaction $model
144
         */
145 28
        $model = $wallet->transactions()->create([
146 28
            'type' => $this->getType(),
147 28
            'wallet_id' => $wallet->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

147
            'wallet_id' => $wallet->/** @scrutinizer ignore-call */ getKey(),
Loading history...
148 28
            'uuid' => $this->getUuid(),
149 28
            'confirmed' => $this->isConfirmed(),
150 28
            'amount' => $this->getAmount(),
151 28
            'meta' => $this->getMeta(),
152
        ]);
153
154 28
        return $model;
155
    }
156
157
}
158