UserProfileController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 44
rs 10
c 1
b 0
f 0
wmc 7
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 13 4
A show() 0 7 2
A checkAuthorizationToSeeOtherUsersProfile() 0 4 1
1
<?php
2
3
namespace Acacha\Users\Http\Controllers;
4
use App\User;
5
use Auth;
6
7
/**
8
 * Class UserProfileController.
9
 *
10
 * @package Acacha\Users\Http\Controllers
11
 */
12
class UserProfileController
13
{
14
    /**
15
     * Show user profile.
16
     *
17
     * @param User $user
18
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
19
     */
20
    public function index(User $user)
21
    {
22
        $data = [];
23
        if ($user->id) {
24
            //Requesting another user profile
25
            if ( $user->identifiableName() === Auth::user()->id || Auth::user()->can('see-other-users-profile')) {
26
                $data = $user->toArray();
27
            } else {
28
                abort(403);
29
            }
30
        }
31
        return view('acacha_users::profile', $data);
32
    }
33
34
    /**
35
     * Show user profile info by api.
36
     *
37
     * @param User $user
38
     * @return User|null
39
     */
40
    public function show(User $user)
41
    {
42
        if ($user->id) {
43
            return $user;
44
        }
45
        return Auth::user();
46
    }
47
48
    /**
49
     * Check authorization to see other users profile.
50
     */
51
    private function checkAuthorizationToSeeOtherUsersProfile()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
52
    {
53
54
    }
55
}