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

Transaction::setConfirmed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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

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