Passed
Push — main ( 7d21ad...5ef848 )
by Seth
03:42
created

DynamicSettingStoreRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 3 1
A rules() 0 10 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
use SaasReady\Rules\ClassExistsRule;
8
9
class DynamicSettingStoreRequest extends BaseFormRequest
10
{
11
    public function authorize(): bool
12
    {
13
        return true;
14
    }
15
16
    public function rules(): array
17
    {
18
        return [
19
            'source_type' => [
20
                'required',
21
                'string',
22
                new ClassExistsRule(),
23
            ],
24
            'source_id' => 'required|int',
25
            'settings' => 'required|array',
26
        ];
27
    }
28
29
    public function getRelatedModel(): ?Model
30
    {
31
        return $this->source
32
            ??= $this->input('source_type')::find($this->input('source_id'));
33
    }
34
}
35