UserController::updateAvatar()   B
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.6845
c 0
b 0
f 0
cc 4
eloc 15
nc 3
nop 1
1
<?php
2
3
namespace LearnParty\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use LearnParty\Http\Requests;
7
use LearnParty\User;
8
use Auth;
9
10
class UserController extends Controller
11
{
12
    /**
13
     * Return the user's profile page.
14
     *
15
     * @return view
16
     */
17
    public function profile()
18
    {
19
        return view('dashboard.profile');
20
    }
21
22
    /**
23
     * update the user's record.
24
     *
25
     * @param  Request $request User request
26
     * @return
27
     */
28
    public function update(Request $request)
29
    {
30
        $this->validate($request, [
31
            'username' => 'required|max:255|unique:users,username,'.Auth::user()->id,
32
            'name' => 'required|max:255',
33
            'email' => 'required|email|max:255|unique:users,email,'.Auth::user()->id,
34
            'about' => 'required|min:5',
35
        ]);
36
37
        $this->userRepository->updateUserInfo($request->all());
38
39
        $request->session()->flash('status', 'success');
40
        $request->session()->flash('message', 'Profile successfully updated.');
41
42
        return redirect('profile');
43
    }
44
45
    /**
46
     * upload an avatar to cloudinary and return url.
47
     *
48
     * @param  Request $request Request from user
49
     * @return Object           redirect to profile page
50
     */
51
    public function updateAvatar(Request $request)
52
    {
53
        $this->validate($request, [
54
            'avatar' => 'required|image|max:10240',
55
        ]);
56
57
        if ($request->file('avatar')->isValid()) {
58
            $url = $this->userRepository->uploadAvatar($request);
0 ignored issues
show
Documentation introduced by
$request is of type object<Illuminate\Http\Request>, but the function expects a object<LearnParty\Http\Repositories\Request>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
59
60
            if (filter_var($url, FILTER_VALIDATE_URL) && $this->userRepository->updateUserInfo(['avatar' => $url])) {
61
                $request->session()->flash('status', 'success');
62
                $request->session()->flash('message', 'Avatar successfully updated.');
63
            } else {
64
                $request->session()->flash('status', 'error');
65
                $request->session()->flash('message', 'Error Uploading avatar.');
66
            }
67
68
        } else {
69
            $request->session()->flash('status', 'error');
70
            $request->session()->flash('message', 'Invalid file upload');
71
        }
72
73
        return redirect('profile');
74
    }
75
76
    /**
77
     * Get all videos that belong to a user.
78
     *
79
     * @param  Intger $user the user id
80
     * @return Video
81
     */
82
    public function userVideos($user)
83
    {
84
        $user = User::find($user);
85
        $videos = $user->videos()->paginate(7);
86
        $headline = $user->videos()->first();
87
88
        return view('user_videos', compact('user', 'videos', 'headline'));
89
    }
90
}
91