BotSettingTrait::settingMarkup()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 34
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 34
c 0
b 0
f 0
rs 9.6
cc 3
nc 1
nop 0
1
<?php
2
3
namespace CSlant\TelegramGitNotifier\Trait;
4
5
use CSlant\TelegramGitNotifier\Constants\SettingConstant;
6
7
trait BotSettingTrait
8
{
9
    public function updateSetting(?string $settingFile = null): void
10
    {
11
        if ($this->setting->getSettingFile()) {
12
            return;
13
        }
14
        $settingFile = $settingFile ?? config('telegram-git-notifier.data_file.setting');
15
        $this->setting->setSettingFile($settingFile);
16
        $this->setting->setSettingConfig();
17
    }
18
19
    public function setMyCommands(
20
        array $menuCommand,
21
        ?string $view = null
22
    ): void {
23
        $this->telegram->setMyCommands([
24
            'commands' => json_encode($menuCommand),
25
        ]);
26
        $this->sendMessage(
0 ignored issues
show
Bug introduced by
It seems like sendMessage() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
        $this->/** @scrutinizer ignore-call */ 
27
               sendMessage(
Loading history...
27
            tgn_view(
28
                $view ??
29
                config('telegram-git-notifier.view.tools.set_menu_cmd')
30
            )
31
        );
32
    }
33
34
    public function settingHandle(?string $view = null): void
35
    {
36
        $this->sendMessage(
37
            tgn_view($view ?? config('telegram-git-notifier.view.tools.settings')),
38
            ['reply_markup' => $this->settingMarkup()]
39
        );
40
    }
41
42
    public function settingMarkup(): array
43
    {
44
        $markup = [
45
            [
46
                $this->telegram->buildInlineKeyBoardButton(
47
                    $this->setting->getSettings()[SettingConstant::T_IS_NOTIFIED]
48
                        ? '✅ Allow notifications'
49
                        : 'Allow notifications',
50
                    '',
51
                    SettingConstant::SETTING_IS_NOTIFIED
52
                ),
53
            ],
54
            [
55
                $this->telegram->buildInlineKeyBoardButton(
56
                    $this->setting->getSettings()[SettingConstant::T_ALL_EVENTS_NOTIFICATION]
57
                        ? '✅ Enable All Events Notify'
58
                        : 'Enable All Events Notify',
59
                    '',
60
                    SettingConstant::SETTING_ALL_EVENTS_NOTIFY
61
                ),
62
            ],
63
        ];
64
65
        $markup = $this->customEventMarkup($markup);
66
67
        $markup[] = [
68
            $this->telegram->buildInlineKeyBoardButton(
69
                '🔙 Back to menu',
70
                '',
71
                SettingConstant::SETTING_BACK . 'menu'
72
            ),
73
        ];
74
75
        return $markup;
76
    }
77
78
    public function customEventMarkup(array $markup): array
79
    {
80
        if (!$this->setting->getSettings()[SettingConstant::T_ALL_EVENTS_NOTIFICATION]) {
81
            $markup[] = [
82
                $this->telegram->buildInlineKeyBoardButton(
83
                    '🦑 Custom github events',
84
                    '',
85
                    SettingConstant::SETTING_GITHUB_EVENTS
86
                ),
87
                $this->telegram->buildInlineKeyBoardButton(
88
                    '🦊 Custom gitlab events',
89
                    '',
90
                    SettingConstant::SETTING_GITLAB_EVENTS
91
                ),
92
            ];
93
        }
94
95
        return $markup;
96
    }
97
}
98