Completed
Push — master ( 9a6ffd...2310bd )
by Tim
03:30 queued 21s
created

ProfileController::updateProfile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 2
eloc 12
nc 2
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\User;
6
use Faker\Provider\Image;
7
use Illuminate\Http\Request;
8
9
use App\Http\Requests;
10
use Illuminate\Support\Facades\Input;
11
12
class ProfileController extends Controller
13
{
14
    /**
15
     * ProfileController constructor.
16
     */
17
    public function __construct()
18
    {
19
        $this->middleware('auth');
20
        $this->middleware('lang');
21
    }
22
23
    /**
24
     * Update the profile information.
25
     *
26
     * @param  Requests\ProfileValidator $input
27
     * @return \Illuminate\Http\RedirectResponse
28
     */
29
    public function updateProfile(Requests\ProfileValidator $input)
30
    {
31
        // User information
32
        User::find(auth()->user()->id)->update($input->except(['_token', 'avatar']));
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
34
        // User image information.
35
        if (Input::file()) {
36
            $image    = Input::file('avatar');
37
            $filename = time() . '.' . $image->getClientOriginalExtension();
38
            $path     = public_path('profilepics/' . $filename);
39
            
40
            Image::make($image->getRealPath())->resize(80, 80)->save($path);
0 ignored issues
show
Bug introduced by
The method make() does not seem to exist on object<Faker\Provider\Image>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
42
            $avatar         = User::find(auth()->user()->id);
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
            $avatar->avatar = $filename;
44
            $avatar->save();
45
        }
46
47
        session()->flash('message', 'Your profile information has been updated.');
48
        return redirect()->back(302);
49
    }
50
51
    /**
52
     * Update your password.
53
     *
54
     * @param  Requests\PasswordValidation $input
55
     * @return \Illuminate\Http\RedirectResponse
56
     */
57
    public function updateSecurity(Requests\PasswordValidation $input)
58
    {
59
        $data['password'] = bcrypt($input->password);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
60
61
        User::find(auth()->user()->id)->update($data);
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
62
        session()->flash('message', 'Your password has been updated.');
63
64
        return redirect()->back(302);
65
    }
66
}
67