Passed
Pull Request — main (#22)
by Seth
02:50
created

DynamicSettingStoreRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 20
c 1
b 0
f 0
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 3 1
A rules() 0 6 1
A getRelatedModel() 0 4 1
1
<?php
2
3
namespace SaasReady\Http\Requests\DynamicSetting;
4
5
use Illuminate\Database\Eloquent\Model;
6
use SaasReady\Http\Requests\BaseFormRequest;
7
8
class DynamicSettingStoreRequest extends BaseFormRequest
9
{
10
    public function authorize(): bool
11
    {
12
        return true;
13
    }
14
15
    public function rules(): array
16
    {
17
        return [
18
            'source_type' => 'required|string',
19
            'source_id' => 'required|int',
20
            'settings' => 'required|array',
21
        ];
22
    }
23
24
    public function getRelatedModel(): ?Model
25
    {
26
        return $this->source
27
            ??= $this->input('source_type')::find($this->input('source_id'));
28
    }
29
}
30