Passed
Push — main ( 1a087d...8eeb21 )
by Thierry
17:35 queued 13:18
created

Summary::home()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 27
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 17
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 27
rs 9.7
1
<?php
2
3
namespace App\Ajax\App\Meeting\Summary;
4
5
use App\Ajax\CallableClass;
6
use Siak\Tontine\Service\Meeting\Summary\MemberService as MemberSummaryService;
7
use Siak\Tontine\Service\Meeting\Summary\SessionService as SessionSummaryService;
8
use Siak\Tontine\Service\Meeting\SessionService;
9
10
use function compact;
11
use function Jaxon\pm;
12
13
class Summary extends CallableClass
14
{
15
    /**
16
     * @di
17
     * @var SessionService
18
     */
19
    protected SessionService $sessionService;
20
21
    /**
22
     * @di
23
     * @var MemberSummaryService
24
     */
25
    protected MemberSummaryService $memberSummaryService;
26
27
    /**
28
     * @di
29
     * @var SessionSummaryService
30
     */
31
    protected SessionSummaryService $sessionSummaryService;
32
33
    public function home()
34
    {
35
        // Don't show the page if there is no session or no member.
36
        $sessions = $this->sessionService->getSessions();
37
        if($sessions->count() === 0)
38
        {
39
            return $this->response;
40
        }
41
        $members = $this->sessionService->getMembers();
42
        if($members->count() === 0)
43
        {
44
            return $this->response;
45
        }
46
        $members->prepend('', 0);
47
48
        $tontine = $this->sessionService->getTontine();
49
        $this->response->html('section-title', trans('tontine.menus.meeting'));
0 ignored issues
show
Bug introduced by
It seems like trans('tontine.menus.meeting') can also be of type array and array; 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

49
        $this->response->html('section-title', /** @scrutinizer ignore-type */ trans('tontine.menus.meeting'));
Loading history...
50
        $html = $this->view()->render('tontine.pages.meeting.summary.home',
51
            compact('sessions', 'members', 'tontine'));
52
        $this->response->html('content-home', $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

52
        $this->response->html('content-home', /** @scrutinizer ignore-type */ $html);
Loading history...
53
54
        $this->jq('#btn-members-refresh')->click($this->rq()->home());
55
        $sessionId = pm()->select('select-session')->toInt();
56
        $memberId = pm()->select('select-member')->toInt();
57
        $this->jq('#btn-member-select')->click($this->rq()->show($sessionId, $memberId));
58
59
        return $this->show($sessions->keys()->first(), $members->keys()->first());
60
    }
61
62
    public function show(int $sessionId, int $memberId)
63
    {
64
        $tontine = $this->sessionService->getTontine();
65
        $session = $this->sessionService->getSession($sessionId);
66
        if($memberId === 0)
67
        {
68
            return $this->cl(Session::class)->show($session, $tontine->is_financial, $this->sessionSummaryService);
69
        }
70
71
        $member = $this->sessionService->getMember($memberId);
72
        return $this->cl(Member::class)->show($session, $member, $tontine->is_financial, $this->memberSummaryService);
73
    }
74
}
75