RoleFormProcessRequest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A prepareForValidation() 0 20 5
A rules() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Auth\Http\Requests\Managerarea;
6
7
use Cortex\Auth\Models\Role;
8
9
class RoleFormProcessRequest extends RoleFormRequest
10
{
11
    /**
12
     * Prepare the data for validation.
13
     *
14
     * @return void
15
     */
16
    protected function prepareForValidation(): void
17
    {
18
        $data = $this->all();
19
20
        // Prepend tenant name to the role name
21
        starts_with(config('rinvex.tenants.active')->name.'_', $data['name']) || $data['name'] = str_start($data['name'], config('rinvex.tenants.active')->name.'_');
0 ignored issues
show
Deprecated Code introduced by
The function starts_with() has been deprecated with message: Str::startsWith() should be used directly instead. Will be removed in Laravel 6.0.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
Deprecated Code introduced by
The function str_start() has been deprecated with message: Str::start() should be used directly instead. Will be removed in Laravel 6.0.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
22
23
        // Set abilities
24
        if (! empty($data['abilities'])) {
25
            if ($this->user($this->route('guard'))->can('grant', \Cortex\Auth\Models\Ability::class)) {
26
                $abilities = array_map('intval', $this->get('abilities', []));
27
                $data['abilities'] = $this->user($this->route('guard'))->isA('superadmin') ? $abilities
28
                    : $this->user($this->route('guard'))->getAbilities()->pluck('id')->intersect($abilities)->toArray();
29
            } else {
30
                unset($data['abilities']);
31
            }
32
        }
33
34
        $this->replace($data);
35
    }
36
37
    /**
38
     * Get the validation rules that apply to the request.
39
     *
40
     * @return array
41
     */
42
    public function rules(): array
43
    {
44
        $user = $this->route('role') ?? new Role();
45
        $user->updateRulesUniques();
46
        $rules = $user->getRules();
47
        $rules['abilities'] = 'nullable|array';
48
49
        return $rules;
50
    }
51
}
52