Passed
Push — develop ( b4818b...dcecff )
by Septianata
16:14
created

AbstractRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 1
b 0
f 0
dl 0
loc 49
ccs 0
cts 10
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getBranchFromRequest() 0 3 1
A getAttributes() 0 6 1
A getScheduleDate() 0 3 1
A getUserFromRequest() 0 3 1
1
<?php
2
3
namespace App\Http\Requests\OrderStatus;
4
5
use App\Infrastructure\Foundation\Http\FormRequest;
6
use App\Models\Branch;
7
use App\Models\User;
8
use Illuminate\Support\Carbon;
9
use Illuminate\Support\Facades\Auth;
10
11
abstract class AbstractRequest extends FormRequest
12
{
13
    /**
14
     * {@inheritDoc}
15
     */
16
    public static function getAttributes()
17
    {
18
        return [
19
            'branch_id' => trans('admin-lang.branch'),
20
            'schedule_date' => trans('Schedule Date'),
21
            'order_status.note' => trans('Note'),
22
        ];
23
    }
24
25
    /**
26
     * Return branch model instance from the request.
27
     *
28
     * @param  string  $key
29
     * @return \App\Models\Branch
30
     *
31
     * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
32
     */
33
    public function getBranchFromRequest(string $key = 'branch_id'): Branch
34
    {
35
        return Branch::findOrFail($this->input($key));
36
    }
37
38
    /**
39
     * Return user model instance from the request.
40
     *
41
     * @param  string  $key
42
     * @return \App\Models\User
43
     *
44
     * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
45
     */
46
    public function getUserFromRequest(string $key = 'user_id'): User
47
    {
48
        return User::find($this->input($key)) ?? Auth::user();
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\User::...rt\Facades\Auth::user() could return the type null which is incompatible with the type-hinted return App\Models\User. Consider adding an additional type-check to rule them out.
Loading history...
49
    }
50
51
    /**
52
     * Return "schedule_date" value from the request.
53
     *
54
     * @param  string  $key
55
     * @return \Illuminate\Support\Carbon
56
     */
57
    public function getScheduleDate(string $key = 'schedule_date'): Carbon
58
    {
59
        return Carbon::parse($this->input($key, 'now'));
60
    }
61
}
62