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

Item   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 34
c 0
b 0
f 0
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMetaProduct() 0 3 1
A canBuy() 0 3 2
A getAmountProduct() 0 3 1
1
<?php
2
3
namespace Bavix\Wallet\Test\Models;
4
5
use Bavix\Wallet\Interfaces\Customer;
6
use Bavix\Wallet\Interfaces\Product;
7
use Bavix\Wallet\Traits\HasWallet;
8
use Illuminate\Database\Eloquent\Model;
9
10
/**
11
 * Class Item
12
 *
13
 * @package Bavix\Wallet\Test\Models
14
 * @property string $name
15
 * @property int $quantity
16
 * @property int $price
17
 */
18
class Item extends Model implements Product
19
{
20
21
    use HasWallet;
0 ignored issues
show
Bug introduced by
The trait Bavix\Wallet\Traits\HasWallet requires the property $total which is not provided by Bavix\Wallet\Test\Models\Item.
Loading history...
22
23
    /**
24
     * @var array
25
     */
26
    protected $fillable = ['name', 'quantity', 'price'];
27
28
    /**
29
     * @param Customer $customer
30
     *
31
     * @return bool
32
     */
33
    public function canBuy(Customer $customer): bool
34
    {
35
        return $this->quantity > 0 && !$customer->paid($this);
36
    }
37
38
    /**
39
     * @return int
40
     */
41
    public function getAmountProduct(): int
42
    {
43
        return $this->price;
44
    }
45
46
    /**
47
     * @return array|null
48
     */
49
    public function getMetaProduct(): ?array
50
    {
51
        return null;
52
    }
53
54
}
55