Passed
Pull Request — main (#54)
by Thierry
13:54
created

CallableClass::pageNumber()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 3
b 0
f 0
nc 8
nop 4
dl 0
loc 15
rs 10
1
<?php
2
3
namespace App\Ajax;
4
5
use App\Ajax\Web\Meeting\Session as MeetingSession;
6
use App\Ajax\Web\Planning\Pool;
7
use App\Ajax\Web\Planning\Session as PlanningSession;
8
use App\Ajax\Web\Planning\Subscription;
9
use App\Ajax\Web\Report\Round as RoundReport;
10
use App\Ajax\Web\Report\Session as SessionReport;
11
use App\Ajax\Web\Tontine\Member;
12
use App\Ajax\Web\Tontine\Options;
13
use App\Ajax\Web\Tontine\Round as TontineRound;
14
use Siak\Tontine\Model\Round;
15
use Siak\Tontine\Model\Tontine;
16
use Jaxon\App\CallableClass as JaxonCallableClass;
17
use Jaxon\App\Dialog\MessageInterface;
18
use Jaxon\App\Dialog\ModalInterface;
19
use Jaxon\App\View\Store;
20
21
use function floor;
22
23
class CallableClass extends JaxonCallableClass
24
{
25
    /**
26
     * @var ModalInterface
27
     */
28
    public $dialog;
29
30
    /**
31
     * @var MessageInterface
32
     */
33
    public $notify;
34
35
    /**
36
     * Get the page number to show
37
     *
38
     * @param int $pageNumber
39
     * @param int $itemCount
40
     * @param string $bagName
41
     * @param string $attrName
42
     *
43
     * @return array
44
     */
45
    protected function pageNumber(int $pageNumber, int $itemCount, string $bagName, string $attrName = 'page'): array
46
    {
47
        $perPage = 10;
48
        $pageCount = (int)floor($itemCount / $perPage) + ($itemCount % $perPage > 0 ? 1 : 0);
49
        if($pageNumber < 1)
50
        {
51
            $pageNumber = $this->bag($bagName)->get($attrName, 1);
52
        }
53
        if($pageNumber > $pageCount)
54
        {
55
            $pageNumber = $pageCount;
56
        }
57
        $this->bag($bagName)->set($attrName, $pageNumber);
58
59
        return [$pageNumber, 10];
60
    }
61
62
    /**
63
     * @param Tontine $tontine
64
     *
65
     * @return void
66
     */
67
    protected function selectTontine(Tontine $tontine)
68
    {
69
        $this->response->html('section-tontine-name', $tontine->name);
70
71
        // Set the tontine sidebar menu
72
        $this->response->html('sidebar-menu-tontine', $this->render('parts.sidebar.tontine'));
0 ignored issues
show
Bug introduced by
It seems like $this->render('parts.sidebar.tontine') 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

72
        $this->response->html('sidebar-menu-tontine', /** @scrutinizer ignore-type */ $this->render('parts.sidebar.tontine'));
Loading history...
73
        $this->jq('a', '#sidebar-menu-tontine')->css('color', '#6777ef');
74
75
        $this->jq('#tontine-menu-members')->click($this->cl(Member::class)->rq()->home());
76
        $this->jq('#tontine-menu-options')->click($this->cl(Options::class)->rq()->home());
77
        $this->jq('#tontine-menu-rounds')->click($this->cl(TontineRound::class)->rq()->home());
78
79
        // Reset the round sidebar menu
80
        $this->response->html('sidebar-menu-round', $this->render('parts.sidebar.round'));
81
    }
82
83
    /**
84
     * @param Round $round
85
     *
86
     * @return void
87
     */
88
    protected function selectRound(Round $round)
89
    {
90
        $this->response->html('section-tontine-name', $round->tontine->name . ' - ' . $round->title);
91
92
        // Set the round sidebar menu
93
        $this->response->html('sidebar-menu-round', $this->render('parts.sidebar.round'));
0 ignored issues
show
Bug introduced by
It seems like $this->render('parts.sidebar.round') 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

93
        $this->response->html('sidebar-menu-round', /** @scrutinizer ignore-type */ $this->render('parts.sidebar.round'));
Loading history...
94
        $this->jq('a', '#sidebar-menu-round')->css('color', '#6777ef');
95
96
        $this->jq('#planning-menu-sessions')->click($this->cl(PlanningSession::class)->rq()->home());
97
        $this->jq('#planning-menu-pools')->click($this->cl(Pool::class)->rq()->home());
98
        $this->jq('#planning-menu-subscriptions')->click($this->cl(Subscription::class)->rq()->home());
99
        $this->jq('#meeting-menu-sessions')->click($this->cl(MeetingSession::class)->rq()->home());
100
        $this->jq('#report-menu-session')->click($this->cl(SessionReport::class)->rq()->home());
101
        $this->jq('#report-menu-round')->click($this->cl(RoundReport::class)->rq()->home());
102
    }
103
104
    /**
105
     * @return void
106
     */
107
    protected function hideMenuOnMobile()
108
    {
109
        // The current template main menu doesn't hide automatically
110
        // after a click on mobile devices. We need to do that manually.
111
        $this->jq('body')->trigger('touchend');
112
    }
113
114
    /**
115
     * Render a view
116
     *
117
     * @param string $view
118
     * @param array $viewData
119
     *
120
     * @return null|Store
121
     */
122
    protected function render(string $view, array $viewData = []): ?Store
123
    {
124
        return $this->view()->render('tontine.app.default.' . $view, $viewData);
125
    }
126
}
127