Edit   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 14 4
1
<?php
2
3
namespace App\Http\Controllers\Company;
4
5
use App\Forms\Builders\Company as Form;
6
use App\Models\Company;
7
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
8
use Illuminate\Routing\Controller;
9
10
class Edit extends Controller
11
{
12
    use AuthorizesRequests;
13
14
    public function __invoke(Company $company, Form $form)
15
    {
16
        $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...
17
        $user_id = \Auth::user()->id;
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
18
        if ($company->email === \Auth::user()->email) {
0 ignored issues
show
Bug Best Practice introduced by
The property email does not exist on App\Models\Company. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
Accessing email on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
19
            if (in_array($role, [1, 2])) {
20
                return ['form' => $form->edit($company)];
21
            }
22
            if ($user_id === $company->created_by) {
23
                return ['form' => $form->edit($company)];
24
            }
25
        }
26
27
        return ['error' => __('Unauthorized')];
28
    }
29
}
30