RecruitmentUserController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Requests\RecruitmentUserCreateRequest;
6
use App\Http\Resources\RecruitmentResource;
7
use App\Models\Recruitment;
8
use App\Services\TenantManager;
9
use Illuminate\Support\Facades\Auth;
10
11
class RecruitmentUserController extends Controller
12
{
13
    /**
14
     * Create a new controller instance.
15
     *
16
     * @param TenantManager $tenantManager
17
     *
18
     * @return void
19
     */
20
    public function __construct(TenantManager $tenantManager)
21
    {
22
        RecruitmentResource::setTenantManager($tenantManager); //workaround - not the best but it works well
23
    }
24
25
    public function list(Recruitment $recruitment)
26
    {
27
        return response()->json($recruitment->grantedUsers);
28
    }
29
30
    public function create(RecruitmentUserCreateRequest $request, Recruitment $recruitment)
31
    {
32
        //TODO logować kto kiedy dał komu dostęp bo relacje znikają z pivota
33
        $userId = $request->get('user_id');
0 ignored issues
show
Bug introduced by
The method get() does not exist on App\Http\Requests\RecruitmentUserCreateRequest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        /** @scrutinizer ignore-call */ 
34
        $userId = $request->get('user_id');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
        $recruitment->grantedUsers()->attach($userId, ['creator_id' => Auth::user()->id]);
35
36
        return response()->json($recruitment->grantedUsers);
37
    }
38
39
    public function delete(Recruitment $recruitment, $userId)
40
    {
41
        $recruitment->grantedUsers()->detach($userId);
42
43
        return response()->json($recruitment->grantedUsers);
44
    }
45
}
46