Completed
Push — master ( 8ce3f9...e1543f )
by Adolfo
14s queued 11s
created

PlanFeature::getCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Sagitarius29\LaravelSubscriptions\Entities;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Sagitarius29\LaravelSubscriptions\Contracts\PlanFeatureContract;
7
8
class PlanFeature extends Model implements PlanFeatureContract
9
{
10
    protected $table = 'plan_features';
11
12
    protected $fillable = [
13
        'code', 'value', 'sort_order', 'is_consumable',
14
    ];
15
16
    public function plan()
17
    {
18
        return $this->belongsTo(config('subscriptions.entities.plan'));
19
    }
20
21
    public function isConsumable(): bool
22
    {
23
        return $this->is_consumable;
24
    }
25
26
    public function getValue()
27
    {
28
        return $this->value;
29
    }
30
31
    /**
32
     * @param  string  $code
33
     * @param  bool|int  $value
34
     * @param  int  $sortOrder
35
     * @param  bool  $isConsumable
36
     * @return Model
37
     */
38
    public static function make(
39
        string $code,
40
        $value,
41
        int $sortOrder,
42
        bool $isConsumable = null
43
    ): Model {
44
        $attributes = [
45
            'code'          => $code,
46
            'value'         => $value,
47
            'sort_order'    => $sortOrder,
48
        ];
49
50
        if (is_bool($value)) {
51
            $attributes['is_consumable'] = false;
52
        } else {
53
            $attributes['is_consumable'] = true;
54
        }
55
56
        if ($isConsumable != null) {
57
            $attributes['is_consumable'] = $isConsumable;
58
        }
59
60
        return new self($attributes);
61
    }
62
63
    public function getCode(): string
64
    {
65
        return $this->code;
66
    }
67
}
68