Completed
Push — master ( 720025...0e57e6 )
by ARCANEDEV
04:07
created

ProfileController::edit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 1
nc 1
nop 0
crap 2
1
<?php namespace Arcanesoft\Auth\Http\Controllers\Admin;
2
3
use Arcanesoft\Auth\Http\Requests\Admin\Profile\UpdatePasswordRequest;
4
use Arcanesoft\Contracts\Auth\Models\User;
5
use Log;
6
7
/**
8
 * Class     ProfileController
9
 *
10
 * @package  Arcanesoft\Auth\Http\Controllers\Admin
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->addBreadcrumbRoute('Profile', 'admin::auth.profile.index');
40
        $this->setCurrentPage('auth-profile');
41
    }
42
43
    /* ------------------------------------------------------------------------------------------------
44
     |  Main Functions
45
     | ------------------------------------------------------------------------------------------------
46
     */
47
    public function index()
48
    {
49
        $user = $this->getAuthenticatedUser();
50
51
        $this->setTitle("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...
52
        $this->addBreadcrumbRoute($user->full_name, 'admin::auth.profile.index');
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...
53
54
        return $this->view('admin.profile.index', compact('user'));
55
    }
56
57
    public function edit()
58
    {
59
        // TODO: complete the implementation
60
    }
61
62
    public function update()
63
    {
64
        // TODO: complete the implementation
65
    }
66
67
    public function updatePassword(UpdatePasswordRequest $request, User $user)
68
    {
69
        $user->update([
0 ignored issues
show
Bug introduced by
The method update() 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...
70
            'password' => $request->get('password'),
71
        ]);
72
73
        Log::info($message = 'The password was updated successfully !', $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...
74
        $this->notifySuccess($message, 'Password Updated !');
75
76
        return redirect()->route('admin::auth.profile.index');
77
    }
78
79
    /* ------------------------------------------------------------------------------------------------
80
     |  Other Functions
81
     | ------------------------------------------------------------------------------------------------
82
     */
83
    /**
84
     * Get the authenticated user.
85
     *
86
     * @return \Arcanesoft\Contracts\Auth\Models\User
87
     */
88
    private function getAuthenticatedUser()
89
    {
90
        return auth()->user();
91
    }
92
}
93