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

Options::editOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 17
nc 1
nop 0
dl 0
loc 25
rs 9.7
c 0
b 0
f 0
1
<?php
2
3
namespace App\Ajax\Web\Tontine;
4
5
use App\Ajax\CallableClass;
6
use Siak\Tontine\Service\Tontine\TontineService;
7
use Siak\Tontine\Validation\Tontine\OptionsValidator;
8
9
use function Jaxon\pm;
10
use function trans;
11
12
class Options extends CallableClass
13
{
14
    /**
15
     * @var OptionsValidator
16
     */
17
    protected OptionsValidator $validator;
18
19
    public function __construct(private TontineService $tontineService)
20
    {}
21
22
    /**
23
     * @after hideMenuOnMobile
24
     */
25
    public function home()
26
    {
27
        $this->response->html('section-title', trans('tontine.menus.tontine'));
28
        $this->response->html('content-home', $this->render('pages.tontine.options'));
0 ignored issues
show
Bug introduced by
It seems like $this->render('pages.tontine.options') 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('content-home', /** @scrutinizer ignore-type */ $this->render('pages.tontine.options'));
Loading history...
29
30
        $this->cl(Fund::class)->home();
31
        $this->cl(Category::class)->home();
32
        $this->cl(Charge::class)->home();
33
    }
34
35
    public function editOptions()
36
    {
37
        $options = $this->tontineService->getTontineOptions();
38
        $template = $options['reports']['template'] ?? 'default';
39
        $title = trans('tontine.options.titles.edit');
40
        $content = $this->render('pages.tontine.options.edit', [
41
            'template' => $template,
42
            'templates' => [
43
                'default' => trans('tontine.options.labels.default'),
44
                'raptor' => 'Raptor',
45
            ],
46
        ]);
47
        $buttons = [[
48
            'title' => trans('common.actions.cancel'),
49
            'class' => 'btn btn-tertiary',
50
            'click' => 'close',
51
        ],[
52
            'title' => trans('common.actions.save'),
53
            'class' => 'btn btn-primary',
54
            'click' => $this->rq()->saveOptions(pm()->form('options-form')),
55
        ]];
56
57
        $this->dialog->show($title, $content, $buttons);
0 ignored issues
show
Bug introduced by
It seems like $content can also be of type null; however, parameter $sContent of Jaxon\App\Dialog\ModalInterface::show() 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

57
        $this->dialog->show($title, /** @scrutinizer ignore-type */ $content, $buttons);
Loading history...
58
59
        return $this->response;
60
    }
61
62
    /**
63
     * @di $validator
64
     */
65
    public function saveOptions(array $formValues)
66
    {
67
        // Validation
68
        $options = $this->validator->validateItem($formValues);
69
        $this->tontineService->saveTontineOptions($options);
70
71
        $this->dialog->hide();
72
        $this->notify->success(trans('tontine.options.messages.saved'));
73
74
        return $this->response;
75
    }
76
}
77