Completed
Push — develop ( bdab7e...1a91b0 )
by Abdelrahman
02:23
created

AdminAttributesFormRequest::withValidator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Auth\Http\Requests\Adminarea;
6
7
use Rinvex\Support\Traits\Escaper;
8
use Illuminate\Foundation\Http\FormRequest;
9
10
class AdminAttributesFormRequest extends FormRequest
11
{
12
    use Escaper;
13
14
    /**
15
     * Determine if the user is authorized to make this request.
16
     *
17
     * @return bool
18
     */
19
    public function authorize(): bool
20
    {
21
        return true;
22
    }
23
24
    /**
25
     * Get the validation rules that apply to the request.
26
     *
27
     * @return array
28
     */
29
    public function rules(): array
30
    {
31
        $admin = $this->route('admin') ?? app('cortex.auth.admin');
32
33
        // Attach attribute rules
34
        $admin->getEntityAttributes()->each(function ($attribute, $attributeName) use (&$rules) {
35
            switch ($attribute->type) {
36
                case 'datetime':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
37
                    $type = 'date';
38
                    break;
39
                case 'text':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
40
                case 'check':
41
                case 'select':
42
                case 'varchar':
43
                    $type = 'string';
44
                    break;
45
                default:
46
                    $type = $attribute->type;
47
                    break;
48
            }
49
50
            $rule = ($attribute->is_required ? 'required|' : 'nullable|').$type;
51
            $rules[$attributeName.($attribute->is_collection ? '.*' : '')] = $rule;
52
        });
53
54
        return $rules ?? [];
55
    }
56
}
57