Passed
Pull Request — main (#49)
by Thierry
14:14
created

LibreFee::show()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace App\Ajax\Web\Meeting\Charge;
4
5
use App\Ajax\CallableClass;
6
use Siak\Tontine\Service\LocaleService;
7
use Siak\Tontine\Service\Meeting\Charge\LibreFeeService;
8
use Siak\Tontine\Model\Session as SessionModel;
9
10
use function Jaxon\jq;
11
12
/**
13
 * @databag meeting
14
 * @before getSession
15
 */
16
class LibreFee extends CallableClass
17
{
18
    /**
19
     * @di
20
     * @var LocaleService
21
     */
22
    protected LocaleService $localeService;
23
24
    /**
25
     * @var LibreFeeService
26
     */
27
    protected LibreFeeService $feeService;
28
29
    /**
30
     * @var SessionModel|null
31
     */
32
    protected ?SessionModel $session;
33
34
    /**
35
     * The constructor
36
     *
37
     * @param LibreFeeService $feeService
38
     */
39
    public function __construct(LibreFeeService $feeService)
40
    {
41
        $this->feeService = $feeService;
42
    }
43
44
    /**
45
     * @return void
46
     */
47
    protected function getSession()
48
    {
49
        $sessionId = $this->bag('meeting')->get('session.id');
50
        $this->session = $this->feeService->getSession($sessionId);
0 ignored issues
show
Bug introduced by
It seems like $sessionId can also be of type null; however, parameter $sessionId of Siak\Tontine\Service\Mee...eeService::getSession() does only seem to accept integer, 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

50
        $this->session = $this->feeService->getSession(/** @scrutinizer ignore-type */ $sessionId);
Loading history...
51
    }
52
53
    /**
54
     * @exclude
55
     */
56
    public function show(SessionModel $session)
57
    {
58
        $this->session = $session;
59
60
        return $this->home();
61
    }
62
63
    public function home()
64
    {
65
        $html = $this->view()->render('tontine.pages.meeting.charge.libre.home')
66
            ->with('session', $this->session);
67
        $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

67
        $this->response->html('meeting-fees-libre', /** @scrutinizer ignore-type */ $html);
Loading history...
68
        $this->jq('#btn-fees-libre-refresh')->click($this->rq()->home());
69
70
        return $this->page(1);
71
    }
72
73
    public function page(int $pageNumber)
74
    {
75
        $chargeCount = $this->feeService->getFeeCount();
76
        [$pageNumber, $perPage] = $this->pageNumber($pageNumber, $chargeCount,
77
            'meeting', 'fee.libre.page');
78
        $charges = $this->feeService->getFees($pageNumber);
79
        $pagination = $this->rq()->page()->paginate($pageNumber, $perPage, $chargeCount);
80
        // Bill and settlement counts and amounts
81
        $bills = $this->feeService->getBills($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...eFeeService::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

81
        $bills = $this->feeService->getBills(/** @scrutinizer ignore-type */ $this->session);
Loading history...
82
        $settlements = $this->feeService->getSettlements($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...rvice::getSettlements() 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

82
        $settlements = $this->feeService->getSettlements(/** @scrutinizer ignore-type */ $this->session);
Loading history...
83
84
        $html = $this->view()->render('tontine.pages.meeting.charge.libre.page')
85
            ->with('session', $this->session)
86
            ->with('charges', $charges)
87
            ->with('bills', $bills)
88
            ->with('settlements', $settlements)
89
            ->with('pagination', $pagination);
90
        $this->response->html('meeting-fees-libre-page', $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

90
        $this->response->html('meeting-fees-libre-page', /** @scrutinizer ignore-type */ $html);
Loading history...
91
92
        $chargeId = jq()->parent()->attr('data-charge-id')->toInt();
93
        $this->jq('.btn-fee-libre-add')
94
            ->click($this->cl(Libre\Member::class)->rq()->home($chargeId));
95
        $this->jq('.btn-fee-libre-settlements')
96
            ->click($this->cl(Libre\Settlement::class)->rq()->home($chargeId));
97
98
        return $this->response;
99
    }
100
}
101