Completed
Push — master ( 205513...bbd982 )
by ARCANEDEV
05:08
created

ProfileController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 113
ccs 0
cts 37
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A index() 0 9 1
A edit() 0 4 1
A update() 0 4 1
A updatePassword() 0 8 1
A getAuthenticatedUser() 0 4 1
A transNotification() 0 10 1
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 Arcanesoft\Core\Http\Controllers\AdminController;
6
use Arcanesoft\Core\Traits\Notifyable;
7
use Log;
8
9
/**
10
 * Class     ProfileController
11
 *
12
 * @package  Arcanesoft\Auth\Http\Controllers\Admin
13
 * @author   ARCANEDEV <[email protected]>
14
 *
15
 * @todo: Adding the authorization checks
16
 */
17
class ProfileController extends AdminController
18
{
19
    /* -----------------------------------------------------------------
20
     |  Traits
21
     | -----------------------------------------------------------------
22
     */
23
24
    use Notifyable;
25
26
    /* -----------------------------------------------------------------
27
     |  Properties
28
     | -----------------------------------------------------------------
29
     */
30
31
    /**
32
     * The authenticated user.
33
     *
34
     * @var \Arcanesoft\Contracts\Auth\Models\User
35
     */
36
    protected $user;
37
38
    /**
39
     * The view namespace.
40
     *
41
     * @var string
42
     */
43
    protected $viewNamespace = 'auth';
44
45
    /* -----------------------------------------------------------------
46
     |  Constructor
47
     | -----------------------------------------------------------------
48
     */
49
50
    /**
51
     * ProfileController constructor.
52
     */
53
    public function __construct()
54
    {
55
        parent::__construct();
56
57
        $this->addBreadcrumbRoute('Profile', 'admin::auth.profile.index');
58
        $this->setCurrentPage('auth-profile');
59
    }
60
61
    /* -----------------------------------------------------------------
62
     |  Main Methods
63
     | -----------------------------------------------------------------
64
     */
65
66
    public function index()
67
    {
68
        $user = $this->getAuthenticatedUser();
69
70
        $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...
71
        $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...
72
73
        return $this->view('admin.profile.index', compact('user'));
74
    }
75
76
    public function edit()
77
    {
78
        // TODO: complete the implementation
79
    }
80
81
    public function update()
82
    {
83
        // TODO: complete the implementation
84
    }
85
86
    public function updatePassword(UpdatePasswordRequest $request, User $user)
87
    {
88
        $user->update($request->only(['password']));
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...
89
90
        $this->transNotification('password-updated', [], $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...
91
92
        return redirect()->route('admin::auth.profile.index');
93
    }
94
95
    /* -----------------------------------------------------------------
96
     |  Other methods
97
     | -----------------------------------------------------------------
98
     */
99
100
    /**
101
     * Get the authenticated user.
102
     *
103
     * @return \Arcanesoft\Contracts\Auth\Models\User
104
     */
105
    private function getAuthenticatedUser()
106
    {
107
        return auth()->user();
108
    }
109
110
    /**
111
     * Notify with translation.
112
     *
113
     * @param  string  $action
114
     * @param  array   $replace
115
     * @param  array   $context
116
     *
117
     * @return string
118
     */
119
    protected function transNotification($action, array $replace = [], array $context = [])
120
    {
121
        $title   = trans("auth::profile.messages.{$action}.title");
122
        $message = trans("auth::profile.messages.{$action}.message", $replace);
123
124
        Log::info($message, $context);
125
        $this->notifySuccess($message, $title);
126
127
        return $message;
128
    }
129
}
130