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

FixedFee   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 32
c 0
b 0
f 0
dl 0
loc 81
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A page() 0 24 1
A home() 0 8 1
A getSession() 0 4 1
A show() 0 5 1
A __construct() 0 3 1
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\FixedFeeService;
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 FixedFee extends CallableClass
17
{
18
    /**
19
     * @di
20
     * @var LocaleService
21
     */
22
    protected LocaleService $localeService;
23
24
    /**
25
     * @var FixedFeeService
26
     */
27
    protected FixedFeeService $feeService;
28
29
    /**
30
     * @var SessionModel|null
31
     */
32
    protected ?SessionModel $session;
33
34
    /**
35
     * The constructor
36
     *
37
     * @param FixedFeeService $feeService
38
     */
39
    public function __construct(FixedFeeService $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.fixed.home')
66
            ->with('session', $this->session);
67
        $this->response->html('meeting-fees-fixed', $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-fixed', /** @scrutinizer ignore-type */ $html);
Loading history...
68
        $this->jq('#btn-fees-fixed-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.fixed.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...dFeeService::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.fixed.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-fixed-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-fixed-page', /** @scrutinizer ignore-type */ $html);
Loading history...
91
92
        $chargeId = jq()->parent()->attr('data-charge-id')->toInt();
93
        $this->jq('.btn-fee-fixed-settlements')
94
            ->click($this->cl(Fixed\Settlement::class)->rq()->home($chargeId));
95
96
        return $this->response;
97
    }
98
}
99