ProfileController::show()   A
last analyzed

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
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace App\Http\Controllers\API;
4
5
use App\Http\Requests\API\ProfileUpdateRequest;
6
use Illuminate\Contracts\Hashing\Hasher as Hash;
7
use Illuminate\Http\JsonResponse;
8
use Illuminate\Http\Request;
9
use RuntimeException;
10
11
/**
12
 * @group 7. User management
13
 */
14
class ProfileController extends Controller
15
{
16
    private $hash;
17
18 2
    public function __construct(Hash $hash)
19
    {
20 2
        $this->hash = $hash;
21 2
    }
22
23
    /**
24
     * Get current user's profile.
25
     *
26
     * @response {
27
     *   "id": 42,
28
     *   "name": "John Doe",
29
     *   "email": "[email protected]"
30
     * }
31
     *
32
     * @return JsonResponse
33
     */
34
    public function show(Request $request)
35
    {
36
        return response()->json($request->user());
37
    }
38
39
    /**
40
     * Update current user's profile.
41
     *
42
     * @bodyParam name string required New name. Example: Johny Doe
43
     * @bodyParam email string required New email. Example: [email protected]
44
     * @bodyParam password string New password (null/blank for no change)
45
     *
46
     * @response []
47
     *
48
     * @throws RuntimeException
49
     *
50
     * @return JsonResponse
51
     */
52 2
    public function update(ProfileUpdateRequest $request)
53
    {
54 2
        if (config('koel.misc.demo')) {
55
            return response()->json();
56
        }
57
58 2
        $data = $request->only('name', 'email');
59
60 2
        if ($request->password) {
61 1
            $data['password'] = $this->hash->make($request->password);
62
        }
63
64 2
        return response()->json($request->user()->update($data));
65
    }
66
}
67