Bot   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 18
c 0
b 0
f 0
dl 0
loc 49
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 1
A validateSettingFile() 0 4 2
1
<?php
2
3
namespace CSlant\TelegramGitNotifier;
4
5
use CSlant\TelegramGitNotifier\Constants\EventConstant;
6
use CSlant\TelegramGitNotifier\Exceptions\ConfigFileException;
7
use CSlant\TelegramGitNotifier\Interfaces\BotInterface;
8
use CSlant\TelegramGitNotifier\Models\Event;
9
use CSlant\TelegramGitNotifier\Models\Setting;
10
use CSlant\TelegramGitNotifier\Structures\App;
11
use CSlant\TelegramGitNotifier\Structures\TelegramBot;
12
use CSlant\TelegramGitNotifier\Trait\BotSettingTrait;
13
use CSlant\TelegramGitNotifier\Trait\EventSettingTrait;
14
use CSlant\TelegramGitNotifier\Trait\EventTrait;
15
use Telegram;
16
17
class Bot implements BotInterface
18
{
19
    use App;
20
    use TelegramBot;
21
22
    use EventTrait;
0 ignored issues
show
introduced by
The trait CSlant\TelegramGitNotifier\Trait\EventTrait requires some properties which are not provided by CSlant\TelegramGitNotifier\Bot: $server, $noteable_type, $action, $object_attributes
Loading history...
23
    use BotSettingTrait;
24
    use EventSettingTrait;
25
26
    public Event $event;
27
28
    public Setting $setting;
29
30
    /**
31
     * @param Telegram|null $telegram
32
     * @param string|null $chatBotId
33
     * @param Event|null $event
34
     * @param string|null $platform
35
     * @param string|null $platformFile
36
     * @param Setting|null $setting
37
     * @param string|null $settingFile
38
     *
39
     * @throws ConfigFileException
40
     */
41
    public function __construct(
42
        Telegram $telegram = null,
43
        ?string $chatBotId = null,
44
        Event $event = null,
45
        ?string $platform = EventConstant::DEFAULT_PLATFORM,
46
        ?string $platformFile = null,
47
        Setting $setting = null,
48
        ?string $settingFile = null,
49
    ) {
50
        $this->event = $event ?? new Event();
51
        $this->setPlatFormForEvent($platform, $platformFile);
52
        $this->validatePlatformFile();
53
54
        $this->setting = $setting ?? new Setting();
55
        $this->updateSetting($settingFile);
56
        $this->validateSettingFile();
57
58
        $this->telegram = $telegram ?? new Telegram(config('telegram-git-notifier.bot.token'));
59
        $this->setCurrentChatBotId($chatBotId);
60
    }
61
62
    public function validateSettingFile(): void
63
    {
64
        if (empty($this->setting->getSettingFile())) {
65
            throw ConfigFileException::settingFile($this->setting->getSettingFile());
66
        }
67
    }
68
}
69