Test Failed
Push — master ( f21b2a...0b0868 )
by Burak
06:41 queued 29s
created

DeleteContactForm   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 34
ccs 0
cts 17
cp 0
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteContact() 0 9 1
A render() 0 3 1
A confirmContactDeletion() 0 9 1
A mount() 0 3 1
1
<?php
2
3
namespace App\Http\Livewire\Contact;
4
5
use App\Models\Contact;
6
use Livewire\Component;
7
8
class DeleteContactForm extends Component
9
{
10
    public Contact $contact;
11
12
    public function mount($contact)
13
    {
14
        $this->contact = $contact;
15
    }
16
17
    public function confirmContactDeletion()
18
    {
19
        $this->resetErrorBag();
20
21
        $this->password = '';
0 ignored issues
show
Bug Best Practice introduced by
The property password does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
22
23
        $this->dispatchBrowserEvent('confirming-delete-contact');
24
25
        $this->confirmingContactDeletion = true;
0 ignored issues
show
Bug Best Practice introduced by
The property confirmingContactDeletion does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
26
    }
27
28
    public function deleteContact(string $id)
29
    {
30
        $contact = Contact::findOrFail($id);
31
        $name = $contact->name;
32
        $contact->delete();
33
34
        session()->flash('message', __(':name is no longer your contacts.', compact('name')));
35
36
        return redirect()->to(route('contact.index'));
37
    }
38
39
    public function render()
40
    {
41
        return view('livewire.contact.delete-contact-form', ['contact' => $this->contact]);
42
    }
43
}
44