Passed
Push — develop ( 16ae21...f7a059 )
by Septianata
04:44
created

Order::generateCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace App\Models;
4
5
use App\Infrastructure\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Factories\HasFactory;
7
use Illuminate\Support\Carbon;
8
use Illuminate\Support\Str;
9
10
class Order extends Model
11
{
12
    use HasFactory,
0 ignored issues
show
introduced by
The trait App\Models\Concerns\Order\Attribute requires some properties which are not provided by App\Models\Order: $bundle_quantity, $total, $sum
Loading history...
13
        Concerns\Order\Attribute,
14
        Concerns\Order\Event,
15
        Concerns\Order\Relation;
16
17
    /**
18
     * {@inheritDoc}
19
     */
20
    protected $fillable = [
21
        'schedule_date',
22
    ];
23
24
    /**
25
     * {@inheritDoc}
26
     */
27
    protected $casts = [
28
        'schedule_date' => 'datetime',
29
    ];
30
31
    /**
32
     * {@inheritDoc}
33
     */
34
    protected $appends = [
35
        'status',
36
        'item_total_bundle_quantity',
37
        'item_total',
38
    ];
39
40
    /**
41
     * Generate code for this model.
42
     *
43
     * @param  string  $prefix
44
     * @param  \Illuminate\Support\Carbon|null  $date
45
     * @return string
46
     */
47
    public function generateCode(string $prefix = 'BCA', Carbon $date = null): string
48
    {
49
        $date ??= Carbon::today();
50
51
        return $prefix . '-' . $date->format('Ymd') . '-' . Str::random(5);
52
    }
53
}
54