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

DynamicSettingIndexRequest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 27
c 1
b 0
f 0
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getRelatedModel() 0 8 3
A authorize() 0 3 1
A rules() 0 7 1
1
<?php
2
3
namespace SaasReady\Http\Requests\DynamicSetting;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Foundation\Http\FormRequest;
7
8
class DynamicSettingIndexRequest extends FormRequest
9
{
10
    private ?Model $source = null;
11
12
    public function authorize(): bool
13
    {
14
        return true;
15
    }
16
17
    public function rules(): array
18
    {
19
        return [
20
            'limit' => 'required|int|max:100',
21
            'page' => 'required|int|min:1',
22
            'source_type' => 'nullable|string',
23
            'source_id' => 'nullable|int',
24
        ];
25
    }
26
27
    public function getRelatedModel(): ?Model
28
    {
29
        if (!$this->input('source_type') || !$this->input('source_id')) {
30
            return null;
31
        }
32
33
        return $this->source
34
            ??= $this->input('source_type')::find($this->input('source_id'));
35
    }
36
}
37