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

DynamicSettingUpdateRequest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 10 1
A authorize() 0 3 1
A getRelatedModel() 0 8 3
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 DynamicSettingUpdateRequest 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
                'nullable',
21
                'string',
22
                new ClassExistsRule(),
23
            ],
24
            'source_id' => 'nullable|int',
25
            'settings' => 'required|array',
26
        ];
27
    }
28
29
    public function getRelatedModel(): ?Model
30
    {
31
        if (!$this->filled('source_type') || !$this->filled('source_id')) {
32
            return null;
33
        }
34
35
        return $this->source
36
            ??= $this->input('source_type')::find($this->input('source_id'));
37
    }
38
}
39