ToggleFavoriteContact   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 32
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 3 1
A favoriteToggle() 0 11 2
A mount() 0 4 1
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