Passed
Push — 5.0.0 ( f10804...44b42e )
by Fèvre
15:04 queued 07:40
created

UpdateAccount   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 48
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A mount() 0 9 1
A render() 0 3 1
A update() 0 14 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Livewire\User;
6
7
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
8
use Illuminate\Support\Facades\Auth;
9
use Livewire\Component;
10
use Livewire\WithFileUploads;
11
use Masmerise\Toaster\Toastable;
12
use Xetaravel\Livewire\Forms\AccountForm;
13
use Throwable;
14
use Xetaravel\Models\User;
15
16
class UpdateAccount extends Component
17
{
18
    use AuthorizesRequests;
19
    use Toastable;
20
    use WithFileUploads;
0 ignored issues
show
introduced by
The trait Livewire\WithFileUploads requires some properties which are not provided by Xetaravel\Livewire\User\UpdateAccount: $map, $timestamp
Loading history...
21
22
    /**
23
     * The form used to create/update a model.
24
     *
25
     * @var AccountForm
26
     */
27
    public AccountForm $form;
28
29
    public function mount(): void
30
    {
31
        $user = User::with('account')->find(Auth::user()->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
32
        $this->form->first_name = $user->first_name;
0 ignored issues
show
Bug introduced by
The property first_name does not seem to exist on Xetaravel\Models\User.
Loading history...
33
        $this->form->last_name = $user->last_name;
0 ignored issues
show
Bug introduced by
The property last_name does not seem to exist on Xetaravel\Models\User.
Loading history...
34
        $this->form->twitter = $user->twitter;
0 ignored issues
show
Bug introduced by
The property twitter does not seem to exist on Xetaravel\Models\User.
Loading history...
35
        $this->form->facebook = $user->facebook;
0 ignored issues
show
Bug introduced by
The property facebook does not seem to exist on Xetaravel\Models\User.
Loading history...
36
        $this->form->biography = $user->biography;
0 ignored issues
show
Bug introduced by
The property biography does not seem to exist on Xetaravel\Models\User.
Loading history...
37
        $this->form->signature = $user->signature;
0 ignored issues
show
Bug introduced by
The property signature does not seem to exist on Xetaravel\Models\User.
Loading history...
38
    }
39
40
    public function render()
41
    {
42
        return view('livewire.user.update-account');
43
    }
44
45
    /**
46
     * Update the post.
47
     *
48
     * @throws Throwable
49
     */
50
    public function update()
51
    {
52
        $this->validate([
53
            'form.first_name' => 'max:50',
54
            'form.last_name' => 'max:50',
55
            'form.facebook' => 'max:50',
56
            'form.twitter' => 'max:50'
57
        ]);
58
59
        $this->form->update();
60
61
        return redirect()
62
            ->route('user.account.index')
0 ignored issues
show
Bug introduced by
The method route() does not exist on Illuminate\Routing\Redirector. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

62
            ->/** @scrutinizer ignore-call */ route('user.account.index')

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
            ->success('Your account has been updated successfully !');
64
    }
65
}
66