EditAccount::resetInputFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Pratiksh\Adminetic\Http\Livewire\Admin\Profile;
4
5
use App\Models\User;
0 ignored issues
show
Bug introduced by
The type App\Models\User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Support\Facades\Hash;
7
use Livewire\Component;
8
9
class EditAccount extends Component
10
{
11
    public $name;
12
    public $email;
13
    public $password;
14
    public $password_confirmation;
15
    public $user;
16
17
    public function mount(User $user)
18
    {
19
        $this->user = $user;
20
        $this->name = $user->name;
21
        $this->email = $user->email;
22
    }
23
24
    private function resetInputFields()
0 ignored issues
show
Unused Code introduced by
The method resetInputFields() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
25
    {
26
        $this->name = '';
27
        $this->email = '';
28
        $this->password = '';
29
    }
30
31
    public function submit()
32
    {
33
        $user = $this->user;
34
        $this->validate([
35
            'name' => 'required|min:6',
36
            'email' => 'required|email|unique:users,email,'.$user->id,
37
            'password' => 'nullable|confirmed|min:8|max:30',
38
        ]);
39
        if (isset($this->password)) {
40
            $user->update([
41
                'name' => $this->name,
42
                'email' => $this->email,
43
                'password' => Hash::make($this->password),
44
            ]);
45
        } else {
46
            $user->update([
47
                'name' => $this->name,
48
                'email' => $this->email,
49
                'password' => $user->password,
50
            ]);
51
        }
52
        $this->emit('account_updated');
53
    }
54
55
    public function render()
56
    {
57
        return view('adminetic::livewire.admin.profile.edit-account');
58
    }
59
}
60