Passed
Push — develop ( 6dcea6...5ae9a6 )
by Septianata
16:24
created

AbstractRequest::getScheduleDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace App\Http\Requests\OrderStatus;
4
5
use App\Infrastructure\Foundation\Http\FormRequest;
6
use App\Models\Branch;
7
use Illuminate\Support\Carbon;
8
9
abstract class AbstractRequest extends FormRequest
10
{
11
    /**
12
     * {@inheritDoc}
13
     */
14
    public static function getAttributes()
15
    {
16
        return [
17
            'branch_id' => trans('admin-lang.branch'),
18
            'schedule_date' => trans('Schedule Date'),
19
            'order_status.note' => trans('Note'),
20
        ];
21
    }
22
23
    /**
24
     * Return branch model instance from the request.
25
     *
26
     * @param  string  $key
27
     * @return \App\Models\Branch
28
     *
29
     * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
30
     */
31
    public function getBranchFromRequest(string $key = 'branch_id'): Branch
32
    {
33
        return Branch::findOrFail($this->input($key));
34
    }
35
36
    /**
37
     * Return "schedule_date" value from the request.
38
     *
39
     * @param  string  $key
40
     * @return \Illuminate\Support\Carbon
41
     */
42
    public function getScheduleDate(string $key = 'schedule_date'): Carbon
43
    {
44
        return Carbon::parse($this->input($key, 'now'));
45
    }
46
}
47