Conditions | 8 |
Paths | 1 |
Total Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
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': |
||
|
|||
37 | $type = 'date'; |
||
38 | break; |
||
39 | case 'text': |
||
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 |
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.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.