Passed
Push — main ( aee526...df35b1 )
by Tan
13:15
created

Markup   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 6
Bugs 4 Features 1
Metric Value
eloc 15
dl 0
loc 50
rs 10
c 6
b 4
f 1
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createButtonRow() 0 3 1
A menuMarkup() 0 12 1
A trans() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CSlant\LaravelTelegramGitNotifier\Traits;
6
7
use Illuminate\Support\Facades\Config;
8
use Telegram as TelegramSDK;
9
10
/**
11
 * Trait Markup
12
 *
13
 * Provides common markup generation methods for Telegram bot interfaces.
14
 */
15
trait Markup
16
{
17
    private const CONFIG_AUTHOR_DISCUSSION = 'telegram-git-notifier.author.discussion';
18
    private const CONFIG_AUTHOR_SOURCE_CODE = 'telegram-git-notifier.author.source_code';
19
    private const TRANSLATION_PREFIX = 'tg-notifier::tools/menu.';
20
21
    /**
22
     * Generate menu markup with discussion and source code buttons.
23
     *
24
     * @param TelegramSDK $telegram The Telegram SDK instance
25
     * @return array<array<array<string, string>>> The generated inline keyboard markup
26
     */
27
    public function menuMarkup(TelegramSDK $telegram): array
28
    {
29
        return [
30
            $this->createButtonRow(
31
                $telegram,
32
                '🗨 ' . $this->trans('discussion'),
33
                Config::get(self::CONFIG_AUTHOR_DISCUSSION, '#')
0 ignored issues
show
Bug introduced by
The constant CSlant\LaravelTelegramGi...ONFIG_AUTHOR_DISCUSSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
34
            ),
35
            $this->createButtonRow(
36
                $telegram,
37
                '💠 ' . $this->trans('source_code'),
38
                Config::get(self::CONFIG_AUTHOR_SOURCE_CODE, '#')
0 ignored issues
show
Bug introduced by
The constant CSlant\LaravelTelegramGi...NFIG_AUTHOR_SOURCE_CODE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
39
            ),
40
        ];
41
    }
42
43
    /**
44
     * Create a single button row for the inline keyboard.
45
     *
46
     * @param TelegramSDK $telegram The Telegram SDK instance
47
     * @param string $text The button text
48
     * @param string $url The URL to open when the button is pressed
49
     * @return array<array<string, string>> The button row
50
     */
51
    private function createButtonRow(TelegramSDK $telegram, string $text, string $url): array
52
    {
53
        return [$telegram->buildInlineKeyBoardButton($text, $url)];
54
    }
55
56
    /**
57
     * Get a translated string from the language file.
58
     *
59
     * @param string $key The translation key
60
     * @return string The translated string
61
     */
62
    private function trans(string $key): string
63
    {
64
        return __(self::TRANSLATION_PREFIX . $key);
0 ignored issues
show
Bug introduced by
The constant CSlant\LaravelTelegramGi...kup::TRANSLATION_PREFIX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
65
    }
66
}
67