Passed
Push — main ( ef2030...a17612 )
by Tan
15:25 queued 13:15
created

Bot::validateSettingFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 2
nc 2
nop 0
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\Interfaces\EventInterface;
9
use CSlant\TelegramGitNotifier\Interfaces\SettingInterface;
10
use CSlant\TelegramGitNotifier\Interfaces\Structures\AppInterface;
11
use CSlant\TelegramGitNotifier\Models\Event;
12
use CSlant\TelegramGitNotifier\Models\Setting;
13
use CSlant\TelegramGitNotifier\Structures\App;
14
use CSlant\TelegramGitNotifier\Structures\TelegramBot;
15
use CSlant\TelegramGitNotifier\Trait\BotSettingTrait;
16
use CSlant\TelegramGitNotifier\Trait\EventSettingTrait;
17
use CSlant\TelegramGitNotifier\Trait\EventTrait;
18
use Telegram;
19
20
class Bot implements AppInterface, BotInterface, EventInterface, SettingInterface
21
{
22
    use App;
23
    use TelegramBot;
24
25
    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...
26
    use BotSettingTrait;
27
    use EventSettingTrait;
28
29
    public Event $event;
30
31
    public Setting $setting;
32
33
    /**
34
     * @param Telegram|null $telegram
35
     * @param string|null $chatBotId
36
     * @param Event|null $event
37
     * @param string|null $platform
38
     * @param string|null $platformFile
39
     * @param Setting|null $setting
40
     * @param string|null $settingFile
41
     *
42
     * @throws ConfigFileException
43
     */
44
    public function __construct(
45
        Telegram $telegram = null,
46
        ?string $chatBotId = null,
47
        Event $event = null,
48
        ?string $platform = EventConstant::DEFAULT_PLATFORM,
49
        ?string $platformFile = null,
50
        Setting $setting = null,
51
        ?string $settingFile = null,
52
    ) {
53
        $this->event = $event ?? new Event();
54
        $this->setPlatFormForEvent($platform, $platformFile);
55
        $this->validatePlatformFile();
56
57
        $this->setting = $setting ?? new Setting();
58
        $this->updateSetting($settingFile);
59
        $this->validateSettingFile();
60
61
        $this->telegram = $telegram ?? new Telegram(config('telegram-git-notifier.bot.token'));
62
        $this->setCurrentChatBotId($chatBotId);
63
    }
64
65
    public function validateSettingFile(): void
66
    {
67
        if (empty($this->setting->getSettingFile())) {
68
            throw ConfigFileException::settingFile($this->setting->getSettingFile());
69
        }
70
    }
71
}
72