ToggleFavoriteContact::favoriteToggle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 11
rs 10
1
<?php
2
3
namespace Adminetic\Contact\Http\Livewire\Admin\Contact;
4
5
use Livewire\Component;
0 ignored issues
show
Bug introduced by
The type Livewire\Component 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 Adminetic\Contact\Models\Admin\Contact;
7
8
class ToggleFavoriteContact extends Component
9
{
10
    public $contact;
11
12
    public $favorite = false;
13
14
    protected $listeners = ['favorite_toggle' => 'favoriteToggle'];
15
16
    public function mount(Contact $contact)
17
    {
18
        $this->contact = $contact;
19
        $this->favorite = $contact->favorite;
20
    }
21
22
23
    public function favoriteToggle($id)
24
    {
25
        $contact = Contact::find($id);
26
        if (isset($contact)) {
27
            $contact->update([
28
                'favorite' => !$contact->favorite
29
            ]);
30
31
            $this->favorite = $contact->favorite;
32
33
            $this->contact = $contact;
34
        }
35
    }
36
37
    public function render()
38
    {
39
        return view('contact::livewire.admin.contact.toggle-favorite-contact');
40
    }
41
}
42