Passed
Push — master ( 9234be...3143c1 )
by Arthur
20:30
created

UserController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Modules\User\Http\Controllers;
4
5
use Foundation\Abstracts\Controller\Controller;
6
use Illuminate\Http\JsonResponse;
7
use Illuminate\Http\Request;
8
use Modules\User\Contracts\UserServiceContract;
9
use Modules\User\Services\UserService;
10
use Modules\User\Transformers\UserTransformer;
11
12
class UserController extends Controller
13
{
14
    /**
15
     * @var UserService
16
     */
17
    protected $service;
18
19
    /**
20
     * UserController constructor.
21
     *
22
     * @param $service
23
     */
24
    public function __construct(UserServiceContract $service)
25
    {
26
        $this->service = $service;
0 ignored issues
show
Documentation Bug introduced by
$service is of type Modules\User\Contracts\UserServiceContract, but the property $service was declared to be of type Modules\User\Services\UserService. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
27
    }
28
29
    /**
30
     * Display a listing of the resource.
31
     *
32
     * @return
33
     */
34
    public function index()
35
    {
36
        return UserTransformer::collection($this->service->all()->load('roles'));
37
    }
38
39
    /**
40
     * Show the specified resource.
41
     *
42
     * @return UserTransformer
43
     */
44
    public function show()
45
    {
46
        return UserTransformer::resource(get_authenticated_user());
47
    }
48
49
    /**
50
     * Update the roles in storage.
51
     *
52
     * @param Request $request
53
     *
54
     * @return JsonResponse
55
     */
56
    public function update(Request $request, $id)
57
    {
58
        $this->service->setRoles($id, $request->roles);
59
60
        return \response()->json('success');
61
    }
62
}
63