Passed
Pull Request — main (#57)
by Thierry
15:28 queued 13s
created

Settlement::showTotal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 0
loc 21
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
namespace App\Ajax\Web\Meeting\Charge\Libre;
4
5
use App\Ajax\CallableChargeClass;
6
use App\Ajax\Web\Meeting\Charge\LibreFee as Charge;
7
8
use function Jaxon\jq;
9
use function trim;
10
11
class Settlement extends CallableChargeClass
12
{
13
    /**
14
     * @param int $chargeId
15
     *
16
     * @return mixed
17
     */
18
    public function home(int $chargeId)
19
    {
20
        $this->bag('meeting')->set('charge.id', $chargeId);
21
        $this->bag('meeting')->set('settlement.libre.search', '');
22
        $this->bag('meeting')->set('settlement.libre.filter', null);
23
24
        $html = $this->render('pages.meeting.settlement.home', [
25
            'type' => 'libre',
26
            'charge' => $this->charge,
27
        ]);
28
        $this->response->html('meeting-fees-libre', $html);
0 ignored issues
show
Bug introduced by
It seems like $html can also be of type null; however, parameter $sData of Jaxon\Response\Response::html() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

28
        $this->response->html('meeting-fees-libre', /** @scrutinizer ignore-type */ $html);
Loading history...
29
        $this->jq('#btn-fee-libre-settlements-back')->click($this->rq(Charge::class)->home());
30
        $this->jq('#btn-fee-libre-settlements-filter')->click($this->rq()->toggleFilter());
31
32
        return $this->page(1);
33
    }
34
35
    private function showTotal()
0 ignored issues
show
Unused Code introduced by
The method showTotal() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
36
    {
37
        $settlement = $this->settlementService->getSettlementCount($this->charge, $this->session);
0 ignored issues
show
Bug introduced by
It seems like $this->session can also be of type null; however, parameter $session of Siak\Tontine\Service\Mee...e::getSettlementCount() does only seem to accept Siak\Tontine\Model\Session, maybe add an additional type check? ( Ignorable by Annotation )

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

37
        $settlement = $this->settlementService->getSettlementCount($this->charge, /** @scrutinizer ignore-type */ $this->session);
Loading history...
Bug introduced by
It seems like $this->charge can also be of type null; however, parameter $charge of Siak\Tontine\Service\Mee...e::getSettlementCount() does only seem to accept Siak\Tontine\Model\Charge, maybe add an additional type check? ( Ignorable by Annotation )

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

37
        $settlement = $this->settlementService->getSettlementCount(/** @scrutinizer ignore-type */ $this->charge, $this->session);
Loading history...
38
        $settlementCount = $settlement->total ?? 0;
0 ignored issues
show
Bug introduced by
The property total does not seem to exist on Siak\Tontine\Model\Bill. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
39
        $settlementAmount = $settlement->amount ?? 0;
40
41
        $billCount = $this->billService->getBillCount($this->charge, $this->session);
0 ignored issues
show
Bug introduced by
It seems like $this->charge can also be of type null; however, parameter $charge of Siak\Tontine\Service\Mee...Service::getBillCount() does only seem to accept Siak\Tontine\Model\Charge, maybe add an additional type check? ( Ignorable by Annotation )

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

41
        $billCount = $this->billService->getBillCount(/** @scrutinizer ignore-type */ $this->charge, $this->session);
Loading history...
Bug introduced by
It seems like $this->session can also be of type null; however, parameter $session of Siak\Tontine\Service\Mee...Service::getBillCount() does only seem to accept Siak\Tontine\Model\Session, maybe add an additional type check? ( Ignorable by Annotation )

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

41
        $billCount = $this->billService->getBillCount($this->charge, /** @scrutinizer ignore-type */ $this->session);
Loading history...
42
        $html = $this->render('pages.meeting.settlement.total', [
43
            'billCount' => $billCount,
44
            'settlementCount' => $settlementCount,
45
            'settlementAmount' => $settlementAmount,
46
        ]);
47
        $this->response->html('meeting-settlements-total', $html);
0 ignored issues
show
Bug introduced by
It seems like $html can also be of type null; however, parameter $sData of Jaxon\Response\Response::html() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

47
        $this->response->html('meeting-settlements-total', /** @scrutinizer ignore-type */ $html);
Loading history...
48
49
        $html = $this->render('pages.meeting.settlement.action', [
50
            'session' => $this->session,
51
            'charge' => $this->charge,
52
            'billCount' => $billCount,
53
            'settlementCount' => $settlementCount,
54
        ]);
55
        $this->response->html('meeting-settlements-action', $html);
56
    }
57
58
    /**
59
     * @param int $pageNumber
60
     *
61
     * @return mixed
62
     */
63
    public function page(int $pageNumber = 0)
64
    {
65
        $search = trim($this->bag('meeting')->get('settlement.libre.search', ''));
66
        $onlyUnpaid = $this->bag('meeting')->get('settlement.libre.filter', null);
67
        $billCount = $this->billService->getBillCount($this->charge,
0 ignored issues
show
Bug introduced by
It seems like $this->charge can also be of type null; however, parameter $charge of Siak\Tontine\Service\Mee...Service::getBillCount() does only seem to accept Siak\Tontine\Model\Charge, maybe add an additional type check? ( Ignorable by Annotation )

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

67
        $billCount = $this->billService->getBillCount(/** @scrutinizer ignore-type */ $this->charge,
Loading history...
68
            $this->session, $search, $onlyUnpaid);
0 ignored issues
show
Bug introduced by
It seems like $this->session can also be of type null; however, parameter $session of Siak\Tontine\Service\Mee...Service::getBillCount() does only seem to accept Siak\Tontine\Model\Session, maybe add an additional type check? ( Ignorable by Annotation )

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

68
            /** @scrutinizer ignore-type */ $this->session, $search, $onlyUnpaid);
Loading history...
69
        [$pageNumber, $perPage] = $this->pageNumber($pageNumber,
70
            $billCount, 'meeting', 'settlement.page');
71
        $bills = $this->billService->getBills($this->charge, $this->session,
0 ignored issues
show
Bug introduced by
It seems like $this->charge can also be of type null; however, parameter $charge of Siak\Tontine\Service\Mee...BillService::getBills() does only seem to accept Siak\Tontine\Model\Charge, maybe add an additional type check? ( Ignorable by Annotation )

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

71
        $bills = $this->billService->getBills(/** @scrutinizer ignore-type */ $this->charge, $this->session,
Loading history...
Bug introduced by
It seems like $this->session can also be of type null; however, parameter $session of Siak\Tontine\Service\Mee...BillService::getBills() does only seem to accept Siak\Tontine\Model\Session, maybe add an additional type check? ( Ignorable by Annotation )

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

71
        $bills = $this->billService->getBills($this->charge, /** @scrutinizer ignore-type */ $this->session,
Loading history...
72
            $search, $onlyUnpaid, $pageNumber);
73
        $pagination = $this->rq()->page()->paginate($pageNumber, $perPage, $billCount);
74
75
        $html = $this->render('pages.meeting.settlement.page', [
76
            'session' => $this->session,
77
            'charge' => $this->charge,
78
            'bills' => $bills,
79
            'pagination' => $pagination,
80
        ]);
81
        $this->response->html('meeting-fee-libre-bills', $html);
0 ignored issues
show
Bug introduced by
It seems like $html can also be of type null; however, parameter $sData of Jaxon\Response\Response::html() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

81
        $this->response->html('meeting-fee-libre-bills', /** @scrutinizer ignore-type */ $html);
Loading history...
82
        $this->response->call('makeTableResponsive', 'meeting-fee-libre-bills');
83
84
        $billId = jq()->parent()->attr('data-bill-id')->toInt();
85
        $this->jq('.btn-add-settlement', '#meeting-fee-libre-bills')
86
            ->click($this->rq()->addSettlement($billId));
87
        $this->jq('.btn-del-settlement', '#meeting-fee-libre-bills')
88
            ->click($this->rq()->delSettlement($billId));
89
        $this->jq('.btn-edit-notes', '#meeting-fee-libre-bills')
90
            ->click($this->rq()->editNotes($billId));
91
92
        return $this->response;
93
    }
94
95
    public function toggleFilter()
96
    {
97
        $onlyUnpaid = $this->bag('meeting')->get('settlement.libre.filter', null);
98
        // Switch between null, true and false
99
        $onlyUnpaid = $onlyUnpaid === null ? true : ($onlyUnpaid === true ? false : null);
100
        $this->bag('meeting')->set('settlement.libre.filter', $onlyUnpaid);
101
102
        return $this->page();
103
    }
104
105
    /**
106
     * @before checkChargeEdit
107
     * @after showBalanceAmounts
108
     * @param int $billId
109
     *
110
     * @return mixed
111
     */
112
    public function addSettlement(int $billId)
113
    {
114
        $this->settlementService->createSettlement($this->charge, $this->session, $billId);
0 ignored issues
show
Bug introduced by
It seems like $this->session can also be of type null; however, parameter $session of Siak\Tontine\Service\Mee...ice::createSettlement() does only seem to accept Siak\Tontine\Model\Session, maybe add an additional type check? ( Ignorable by Annotation )

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

114
        $this->settlementService->createSettlement($this->charge, /** @scrutinizer ignore-type */ $this->session, $billId);
Loading history...
Bug introduced by
It seems like $this->charge can also be of type null; however, parameter $charge of Siak\Tontine\Service\Mee...ice::createSettlement() does only seem to accept Siak\Tontine\Model\Charge, maybe add an additional type check? ( Ignorable by Annotation )

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

114
        $this->settlementService->createSettlement(/** @scrutinizer ignore-type */ $this->charge, $this->session, $billId);
Loading history...
115
116
        return $this->page();
117
    }
118
119
    /**
120
     * @before checkChargeEdit
121
     * @after showBalanceAmounts
122
     * @param int $billId
123
     *
124
     * @return mixed
125
     */
126
    public function delSettlement(int $billId)
127
    {
128
        $this->settlementService->deleteSettlement($this->charge, $this->session, $billId);
0 ignored issues
show
Bug introduced by
It seems like $this->charge can also be of type null; however, parameter $charge of Siak\Tontine\Service\Mee...ice::deleteSettlement() does only seem to accept Siak\Tontine\Model\Charge, maybe add an additional type check? ( Ignorable by Annotation )

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

128
        $this->settlementService->deleteSettlement(/** @scrutinizer ignore-type */ $this->charge, $this->session, $billId);
Loading history...
Bug introduced by
It seems like $this->session can also be of type null; however, parameter $session of Siak\Tontine\Service\Mee...ice::deleteSettlement() does only seem to accept Siak\Tontine\Model\Session, maybe add an additional type check? ( Ignorable by Annotation )

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

128
        $this->settlementService->deleteSettlement($this->charge, /** @scrutinizer ignore-type */ $this->session, $billId);
Loading history...
129
130
        return $this->page();
131
    }
132
}
133