diff --git a/src/Interfaces/EventInterface.php b/src/Interfaces/EventInterface.php index df856ab..a2de979 100644 --- a/src/Interfaces/EventInterface.php +++ b/src/Interfaces/EventInterface.php @@ -2,6 +2,7 @@ namespace LbilTech\TelegramGitNotifier\Interfaces; +use LbilTech\TelegramGitNotifier\Constants\EventConstant; use LbilTech\TelegramGitNotifier\Trait\ActionEventTrait; use Symfony\Component\HttpFoundation\Request; @@ -20,13 +21,13 @@ public function getActionOfEvent(object $payload): string; /** * Set platform and platform file for event * - * @param string $platform + * @param string|null $platform * @param string|null $platformFile * * @return void * @see EventTrait::setPlatFormForEvent() */ - public function setPlatFormForEvent(string $platform, string $platformFile = null): void; + public function setPlatFormForEvent(?string $platform = EventConstant::DEFAULT_PLATFORM, string $platformFile = null): void; /** * Set event config and get event name diff --git a/src/Models/Event.php b/src/Models/Event.php index 6bab8f5..d3a12b2 100644 --- a/src/Models/Event.php +++ b/src/Models/Event.php @@ -41,17 +41,18 @@ public function getEventConfig(): array /** * Set event config * - * @param string $platform + * @param string|null $platform * * @return void */ public function setEventConfig( - string $platform = EventConstant::DEFAULT_PLATFORM + string $platform = null ): void { - $this->platform = $platform; + $this->platform = $platform ?? EventConstant::DEFAULT_PLATFORM; - if (file_exists($this->platformFile)) { - $json = file_get_contents($this->platformFile); + $json = file_get_contents($this->platformFile); + + if (!empty($json)) { $this->eventConfig = json_decode($json, true); } } diff --git a/src/Models/Setting.php b/src/Models/Setting.php index 0f53e13..f7b6d8c 100644 --- a/src/Models/Setting.php +++ b/src/Models/Setting.php @@ -43,8 +43,9 @@ public function getSettingFile(): string */ public function setSettingConfig(): void { - if (file_exists($this->settingFile)) { - $json = file_get_contents($this->settingFile); + $json = file_get_contents($this->settingFile); + + if (!empty($json)) { $this->settings = json_decode($json, true); } } diff --git a/src/Trait/EventSettingTrait.php b/src/Trait/EventSettingTrait.php index 486d204..6f5d925 100644 --- a/src/Trait/EventSettingTrait.php +++ b/src/Trait/EventSettingTrait.php @@ -124,9 +124,9 @@ public function getPlatformFromCallback( return $platform; } - if (str_contains($callback, EventConstant::GITHUB_EVENT_SEPARATOR)) { + if ($callback && str_contains($callback, EventConstant::GITHUB_EVENT_SEPARATOR)) { return 'github'; - } elseif (str_contains($callback, EventConstant::GITLAB_EVENT_SEPARATOR)) { + } elseif ($callback && str_contains($callback, EventConstant::GITLAB_EVENT_SEPARATOR)) { return 'gitlab'; } diff --git a/src/Trait/EventTrait.php b/src/Trait/EventTrait.php index 9bd5ae5..2175b0d 100644 --- a/src/Trait/EventTrait.php +++ b/src/Trait/EventTrait.php @@ -9,7 +9,7 @@ trait EventTrait { use ActionEventTrait; - public function setPlatFormForEvent(string $platform, string $platformFile = null): void + public function setPlatFormForEvent(?string $platform = EventConstant::DEFAULT_PLATFORM, string $platformFile = null): void { /** @var array $platformFileDefaults */ $platformFileDefaults = config('telegram-git-notifier.data_file.platform');