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

Transaction::setType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
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 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 28
    public function __construct()
41
    {
42 28
        $this->uuid = Uuid::uuid4()->toString();
43 28
    }
44
45
    /**
46
     * @return string
47
     */
48 28
    public function getType(): string
49
    {
50 28
        return $this->type;
51
    }
52
53
    /**
54
     * @return string
55
     */
56 28
    public function getUuid(): string
57
    {
58 28
        return $this->uuid;
59
    }
60
61
    /**
62
     * @return int
63
     */
64 28
    public function getAmount(): int
65
    {
66 28
        return $this->amount;
67
    }
68
69
    /**
70
     * @return array|null
71
     */
72 28
    public function getMeta(): ?array
73
    {
74 28
        return $this->meta;
75
    }
76
77
    /**
78
     * @return bool
79
     */
80 28
    public function isConfirmed(): bool
81
    {
82 28
        return $this->confirmed;
83
    }
84
85
    /**
86
     * @param string $type
87
     * @return static
88
     */
89 28
    public function setType(string $type): self
90
    {
91 28
        $this->type = $type;
92 28
        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 28
    public function setAmount(int $amount): self
110
    {
111 28
        $this->amount = $amount;
112 28
        return $this;
113
    }
114
115
    /**
116
     * @param array|null $meta
117
     * @return static
118
     */
119 28
    public function setMeta(?array $meta): self
120
    {
121 28
        $this->meta = $meta;
122 28
        return $this;
123
    }
124
125
    /**
126
     * @param bool $confirmed
127
     * @return static
128
     */
129 28
    public function setConfirmed(bool $confirmed): self
130
    {
131 28
        $this->confirmed = $confirmed;
132 28
        return $this;
133
    }
134
135
    /**
136
     * @param Wallet $wallet
137
     * @return \Bavix\Wallet\Models\Transaction
138
     */
139 28
    public function create(Wallet $wallet): \Bavix\Wallet\Models\Transaction
140
    {
141
        /**
142
         * @var \Bavix\Wallet\Models\Transaction $model
143
         */
144 28
        $model = $wallet->transactions()->create([
145 28
            'type' => $this->getType(),
146 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

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