PaymentPanel   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 38
c 1
b 0
f 0
dl 0
loc 76
rs 10
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A updatedAmount() 0 3 2
A mount() 0 5 2
A update() 0 19 2
A store() 0 18 2
A render() 0 5 1
A setEdit() 0 4 1
1
<?php
2
3
namespace Adminetic\Website\Http\Livewire\Admin\Payment;
4
5
use Adminetic\Website\Models\Admin\Payment;
6
use Illuminate\Support\Facades\Auth;
7
use Livewire\Component;
8
9
class PaymentPanel extends Component
10
{
11
    public $toggle_modal = false;
12
13
    public $model;
14
    public $type;
15
16
    public $amount;
17
    public $particular;
18
19
    public $payment_id;
20
21
    public function mount($model, $type)
22
    {
23
        $this->model = $model;
24
        $this->type = $type;
25
        $this->particular = ('An '.($this->type ? 'income' : 'expense').' of '.currency().$this->amount.' is registered under '.class_basename($this->model).' : '.$this->model->track_id);
26
    }
27
28
    public function updatedAmount()
29
    {
30
        $this->particular = ('An '.($this->type ? 'income' : 'expense').' of '.currency().$this->amount.' is registered under '.class_basename($this->model).' : '.$this->model->track_id);
31
    }
32
33
    public function store()
34
    {
35
        $this->validate([
36
            'amount' => 'required|numeric',
37
        ]);
38
39
        $particular = $this->particular ?? ('An '.($this->type ? 'income' : 'expense').' of '.currency().$this->amount.' is registered under '.class_basename($this->model).' : '.$this->model->track_id);
40
41
        $this->model->payments()->create([
42
            'user_id' => 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...
43
            'type' => $this->type,
44
            'amount' => $this->amount,
45
            'particular' => $particular,
46
        ]);
47
        $this->amount = null;
48
49
        $this->model->refresh();
50
        $this->emitSelf('payment_success', $particular);
51
    }
52
53
    public function update()
54
    {
55
        $this->validate([
56
            'amount' => 'required|numeric',
57
        ]);
58
59
        $particular = $this->particular ?? ('An '.($this->type ? 'income' : 'expense').' of '.currency().$this->amount.' is registered under '.class_basename($this->model).' : '.$this->model->track_id.'(Updated)');
60
61
        Payment::find($this->payment_id)->update([
62
            'user_id' => 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...
63
            'type' => $this->type,
64
            'amount' => $this->amount,
65
            'particular' => $particular,
66
        ]);
67
        $this->amount = null;
68
        $this->payment_id = null;
69
70
        $this->model->refresh();
71
        $this->emitSelf('payment_success', $particular);
72
    }
73
74
    public function setEdit(Payment $payment)
75
    {
76
        $this->payment_id = $payment->id;
77
        $this->amount = $payment->amount;
0 ignored issues
show
Bug introduced by
The property amount does not seem to exist on Adminetic\Website\Models\Admin\Payment.
Loading history...
78
    }
79
80
    public function render()
81
    {
82
        $payments = $this->model->payments;
83
84
        return view('website::livewire.admin.payment.payment-panel', compact('payments'));
85
    }
86
}
87