Completed
Push — develop ( 5abd4c...dae2aa )
by Abdelrahman
09:07
created

ManagerAttributesFormRequest::rules()   B

Complexity

Conditions 6
Paths 1

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.439
c 0
b 0
f 0
cc 6
eloc 17
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Auth\Http\Requests\Adminarea;
6
7
use Illuminate\Foundation\Http\FormRequest;
8
9
class ManagerAttributesFormRequest extends FormRequest
10
{
11
    /**
12
     * Determine if the user is authorized to make this request.
13
     *
14
     * @return bool
15
     */
16
    public function authorize(): bool
17
    {
18
        return true;
19
    }
20
21
    /**
22
     * Get the validation rules that apply to the request.
23
     *
24
     * @return array
25
     */
26
    public function rules(): array
27
    {
28
        $manager = $this->route('manager') ?? app('cortex.auth.manager');
29
30
        // Attach attribute rules
31
        $manager->getEntityAttributes()->each(function ($attribute, $attributeSlug) use (&$rules) {
32
            switch ($attribute->type) {
33
                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...
34
                    $type = 'date';
35
                    break;
36
                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...
37
                case 'varchar':
38
                    $type = 'string';
39
                    break;
40
                default:
41
                    $type = $attribute->type;
42
                    break;
43
            }
44
45
            $rule = ($attribute->is_required ? 'required|' : 'nullable|').$type;
46
            $rules[$attributeSlug.($attribute->is_collection ? '.*' : '')] = $rule;
47
        });
48
49
        return $rules ?? [];
50
    }
51
}
52