Completed
Push — master ( f40498...e3ae3a )
by ARCANEDEV
03:17
created

ProfileController::updatePassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 0
cts 9
cp 0
rs 9.4286
cc 1
eloc 7
nc 1
nop 2
crap 2
1
<?php namespace Arcanesoft\Auth\Http\Controllers\Foundation;
2
3
use Arcanesoft\Auth\Bases\FoundationController;
4
use Arcanesoft\Auth\Http\Requests\Backend\Profile\UpdatePasswordRequest;
5
use Arcanesoft\Contracts\Auth\Models\User;
6
use Log;
7
8
/**
9
 * Class     ProfileController
10
 *
11
 * @package  Arcanesoft\Auth\Http\Controllers\Foundation
12
 * @author   ARCANEDEV <[email protected]>
13
 *
14
 * @todo: Adding the authorization checks
15
 */
16
class ProfileController extends FoundationController
17
{
18
    /* ------------------------------------------------------------------------------------------------
19
     |  Properties
20
     | ------------------------------------------------------------------------------------------------
21
     */
22
    /**
23
     * The authenticated user.
24
     *
25
     * @var \Arcanesoft\Contracts\Auth\Models\User
26
     */
27
    protected $user;
28
29
    /* ------------------------------------------------------------------------------------------------
30
     |  Constructor
31
     | ------------------------------------------------------------------------------------------------
32
     */
33
    /**
34
     * ProfileController constructor.
35
     */
36
    public function __construct()
37
    {
38
        parent::__construct();
39
40
        $this->user = auth()->user();
0 ignored issues
show
Documentation Bug introduced by
It seems like auth()->user() can also be of type object<Illuminate\Contracts\Auth\Authenticatable>. However, the property $user is declared as type object<Arcanesoft\Contracts\Auth\Models\User>. Maybe add an additional type 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 mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
41
42
        $this->setCurrentPage('auth-profile');
43
    }
44
45
    /* ------------------------------------------------------------------------------------------------
46
     |  Main Functions
47
     | ------------------------------------------------------------------------------------------------
48
     */
49
    public function index()
50
    {
51
        $this->setData('user', $this->user);
52
53
        $title = 'Profile - ' . $this->user->full_name;
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Arcanesoft\Contracts\Auth\Models\User suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
54
        $this->setTitle($title);
55
        $this->addBreadcrumbRoute($title, 'auth::foundation.profile.index');
56
57
        return $this->view('foundation.profile.index');
58
    }
59
60
    public function updatePassword(UpdatePasswordRequest $request, User $user)
61
    {
62
        $user->password = $request->get('password');
0 ignored issues
show
Bug introduced by
Accessing password on the interface Arcanesoft\Contracts\Auth\Models\User suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
63
        $user->save();
64
65
        $message = "The password was updated successfully !";
66
        Log::info($message, $user->toArray());
67
        $this->notifySuccess($message, 'Password Updated !');
68
69
        return redirect()->route('auth::foundation.profile.index');
70
    }
71
}
72