Completed
Push — master ( 1aae4d...e6b406 )
by ARCANEDEV
03:59
created

ProfileController::getAuthenticatedUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php namespace Arcanesoft\Auth\Http\Controllers\Foundation;
2
3
use Arcanesoft\Auth\Http\Requests\Backend\Profile\UpdatePasswordRequest;
4
use Arcanesoft\Contracts\Auth\Models\User;
5
use Log;
6
7
/**
8
 * Class     ProfileController
9
 *
10
 * @package  Arcanesoft\Auth\Http\Controllers\Foundation
11
 * @author   ARCANEDEV <[email protected]>
12
 *
13
 * @todo: Adding the authorization checks
14
 */
15
class ProfileController extends Controller
16
{
17
    /* ------------------------------------------------------------------------------------------------
18
     |  Properties
19
     | ------------------------------------------------------------------------------------------------
20
     */
21
    /**
22
     * The authenticated user.
23
     *
24
     * @var \Arcanesoft\Contracts\Auth\Models\User
25
     */
26
    protected $user;
27
28
    /* ------------------------------------------------------------------------------------------------
29
     |  Constructor
30
     | ------------------------------------------------------------------------------------------------
31
     */
32
    /**
33
     * ProfileController constructor.
34
     */
35
    public function __construct()
36
    {
37
        parent::__construct();
38
39
        $this->setCurrentPage('auth-profile');
40
    }
41
42
    /* ------------------------------------------------------------------------------------------------
43
     |  Main Functions
44
     | ------------------------------------------------------------------------------------------------
45
     */
46
    public function index()
47
    {
48
        $user = $this->getAuthenticatedUser();
49
50
        $this->setTitle($title = 'Profile - ' . $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...
51
        $this->addBreadcrumbRoute($title, 'auth::foundation.profile.index');
52
53
        return $this->view('foundation.profile.index', compact('user'));
54
    }
55
56
    public function updatePassword(UpdatePasswordRequest $request, User $user)
57
    {
58
        $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...
59
        $user->save();
60
61
        $message = 'The password was updated successfully !';
62
        Log::info($message, $user->toArray());
0 ignored issues
show
Bug introduced by
The method toArray() does not seem to exist on object<Arcanesoft\Contracts\Auth\Models\User>.

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...
63
        $this->notifySuccess($message, 'Password Updated !');
64
65
        return redirect()->route('auth::foundation.profile.index');
66
    }
67
68
    /* ------------------------------------------------------------------------------------------------
69
     |  Other Functions
70
     | ------------------------------------------------------------------------------------------------
71
     */
72
    /**
73
     * Get the authenticated user.
74
     *
75
     * @return \Arcanesoft\Contracts\Auth\Models\User
76
     */
77
    private function getAuthenticatedUser()
78
    {
79
        return auth()->user();
80
    }
81
}
82