Create   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 18 6
1
<?php
2
3
namespace App\Http\Controllers\Company;
4
5
use App\Forms\Builders\Company;
6
use Illuminate\Routing\Controller;
7
8
class Create extends Controller
9
{
10
    public function __invoke(Company $form)
11
    {
12
        $role = \Auth::user()->role_id;
0 ignored issues
show
Bug introduced by
Accessing role_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
13
        $companies = \Auth::user()->person->companies()->count();
0 ignored issues
show
Bug introduced by
Accessing person on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
14
15
        if (in_array($role, [1, 2, 9, 10])) {
16
            return ['form' => $form->create()];
17
        }
18
        if (in_array($role, [4, 5, 6]) && $companies < 1) {
19
            return ['form' => $form->create(), 'c' => $companies];
20
        }
21
//        && $companies < 1
22
23
        if (in_array($role, [7, 8]) && $companies < 10) {
24
            return ['form' => $form->create()];
25
        }
26
27
        return ['error' => __('Unauthorized')];
28
    }
29
}
30