Passed
Push — master ( 1dc943...5f0a93 )
by Arthur
08:24 queued 35s
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 0
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
11
class UserController extends Controller
12
{
13
    /**
14
     * @var UserService
15
     */
16
    protected $service;
17
18
    /**
19
     * UserController constructor.
20
     *
21
     * @param $service
22
     */
23
    public function __construct(UserServiceContract $service)
24
    {
25
        $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...
26
    }
27
28
    /**
29
     * Display a listing of the resource.
30
     *
31
     * @return JsonResponse
32
     */
33
    public function index()
34
    {
35
        return \response()->json($this->service->all());
36
    }
37
38
    /**
39
     * Show the specified resource.
40
     *
41
     * @return JsonResponse
42
     */
43
    public function show()
44
    {
45
        return \response()->json(get_authenticated_user()->toArray());
46
    }
47
48
    /**
49 1
     * Update the roles in storage.
50
     *
51 1
     * @param Request $request
52
     *
53 1
     * @return JsonResponse
54
     */
55
    public function update(Request $request, $id)
56
    {
57
        $this->service->assignRole($id, $request->roles);
58
59
        return \response()->json('success');
60
    }
61
}
62