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

Operation   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 146
Duplicated Lines 0 %

Test Coverage

Coverage 91.89%

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 146
ccs 34
cts 37
cp 0.9189
rs 10
c 0
b 0
f 0
wmc 12

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A create() 0 15 1
A getAmount() 0 3 1
A getMeta() 0 3 1
A setMeta() 0 4 1
A setConfirmed() 0 4 1
A getUuid() 0 3 1
A setAmount() 0 4 1
A isConfirmed() 0 3 1
A getType() 0 3 1
A setUuid() 0 4 1
A setType() 0 4 1
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 29
    public function __construct()
42
    {
43 29
        $this->uuid = Uuid::uuid4()->toString();
44 29
    }
45
46
    /**
47
     * @return string
48
     */
49 29
    public function getType(): string
50
    {
51 29
        return $this->type;
52
    }
53
54
    /**
55
     * @return string
56
     */
57 29
    public function getUuid(): string
58
    {
59 29
        return $this->uuid;
60
    }
61
62
    /**
63
     * @return int
64
     */
65 29
    public function getAmount(): int
66
    {
67 29
        return $this->amount;
68
    }
69
70
    /**
71
     * @return array|null
72
     */
73 29
    public function getMeta(): ?array
74
    {
75 29
        return $this->meta;
76
    }
77
78
    /**
79
     * @return bool
80
     */
81 29
    public function isConfirmed(): bool
82
    {
83 29
        return $this->confirmed;
84
    }
85
86
    /**
87
     * @param string $type
88
     * @return static
89
     */
90 29
    public function setType(string $type): self
91
    {
92 29
        $this->type = $type;
93 29
        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 29
    public function setAmount(int $amount): self
111
    {
112 29
        $this->amount = $amount;
113 29
        return $this;
114
    }
115
116
    /**
117
     * @param array|null $meta
118
     * @return static
119
     */
120 29
    public function setMeta(?array $meta): self
121
    {
122 29
        $this->meta = $meta;
123 29
        return $this;
124
    }
125
126
    /**
127
     * @param bool $confirmed
128
     * @return static
129
     */
130 29
    public function setConfirmed(bool $confirmed): self
131
    {
132 29
        $this->confirmed = $confirmed;
133 29
        return $this;
134
    }
135
136
    /**
137
     * @param Wallet $wallet
138
     * @return Transaction
139
     */
140 29
    public function create(Wallet $wallet): Transaction
141
    {
142
        /**
143
         * @var Transaction $model
144
         */
145 29
        $model = $wallet->transactions()->create([
146 29
            'type' => $this->getType(),
147 29
            '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 29
            'uuid' => $this->getUuid(),
149 29
            'confirmed' => $this->isConfirmed(),
150 29
            'amount' => $this->getAmount(),
151 29
            'meta' => $this->getMeta(),
152
        ]);
153
154 29
        return $model;
155
    }
156
157
}
158