diff --git a/src/Helpers/ConfigHelper.php b/src/Helpers/ConfigHelper.php index ee6e3cd..d345474 100644 --- a/src/Helpers/ConfigHelper.php +++ b/src/Helpers/ConfigHelper.php @@ -42,12 +42,12 @@ public function execConfig(string $string): mixed /** * Return template data * - * @param $partialPath + * @param string $partialPath * @param array $data * * @return bool|string */ - public function getTemplateData($partialPath, array $data = []): bool|string + public function getTemplateData(string $partialPath, array $data = []): bool|string { $viewPathFile = $this->execConfig('telegram-git-notifier.view.path') . '/' . str_replace('.', '/', $partialPath) . '.php'; @@ -56,6 +56,7 @@ public function getTemplateData($partialPath, array $data = []): bool|string return ''; } + $content = ''; ob_start(); try { extract($data, EXTR_SKIP); diff --git a/src/Interfaces/EventInterface.php b/src/Interfaces/EventInterface.php index 846a260..df856ab 100644 --- a/src/Interfaces/EventInterface.php +++ b/src/Interfaces/EventInterface.php @@ -10,12 +10,12 @@ interface EventInterface /** * Get action name of event from payload data * - * @param $payload + * @param object $payload * * @return string * @see ActionEventTrait::getActionOfEvent() */ - public function getActionOfEvent($payload): string; + public function getActionOfEvent(object $payload): string; /** * Set platform and platform file for event diff --git a/src/Interfaces/Structures/NotificationInterface.php b/src/Interfaces/Structures/NotificationInterface.php index 863f01f..1e65546 100644 --- a/src/Interfaces/Structures/NotificationInterface.php +++ b/src/Interfaces/Structures/NotificationInterface.php @@ -50,12 +50,12 @@ public function sendNotify(string $message = null, array $options = []): bool; /** * Get action name of event from payload data * - * @param $payload + * @param object $payload * * @return string * @see EventTrait::getActionOfEvent() */ - public function getActionOfEvent($payload): string; + public function getActionOfEvent(object $payload): string; /** * Convert chat and thread ids to array diff --git a/src/Models/Event.php b/src/Models/Event.php index a6a8287..6bab8f5 100644 --- a/src/Models/Event.php +++ b/src/Models/Event.php @@ -50,8 +50,10 @@ public function setEventConfig( ): void { $this->platform = $platform; - $json = file_get_contents($this->platformFile); - $this->eventConfig = json_decode($json, true); + if (file_exists($this->platformFile)) { + $json = file_get_contents($this->platformFile); + $this->eventConfig = json_decode($json, true); + } } /** diff --git a/src/Models/Setting.php b/src/Models/Setting.php index 6c07913..0f53e13 100644 --- a/src/Models/Setting.php +++ b/src/Models/Setting.php @@ -43,8 +43,10 @@ public function getSettingFile(): string */ public function setSettingConfig(): void { - $json = file_get_contents($this->settingFile); - $this->settings = json_decode($json, true); + if (file_exists($this->settingFile)) { + $json = file_get_contents($this->settingFile); + $this->settings = json_decode($json, true); + } } /** @@ -81,13 +83,13 @@ public function isNotified(): bool * Update setting item value and save to file * * @param string $settingName - * @param $settingValue + * @param array|string|bool|int|null $settingValue * * @return bool */ public function updateSetting( string $settingName, - $settingValue = null + mixed $settingValue = null ): bool { $settingKeys = explode('.', $settingName); $lastKey = array_pop($settingKeys); diff --git a/src/Objects/Validator.php b/src/Objects/Validator.php index 944529d..6c2b4b8 100644 --- a/src/Objects/Validator.php +++ b/src/Objects/Validator.php @@ -25,14 +25,14 @@ public function __construct(Setting $setting, Event $event) * * @param string $platform Source code platform (GitHub, GitLab) * @param string $event Event name (push, pull_request) - * @param $payload + * @param object $payload * * @return bool */ public function isAccessEvent( string $platform, string $event, - $payload + object $payload ): bool { if (!$this->setting->isNotified()) { return false; diff --git a/src/Structures/Notification.php b/src/Structures/Notification.php index cfdbef3..2a04d26 100644 --- a/src/Structures/Notification.php +++ b/src/Structures/Notification.php @@ -9,7 +9,7 @@ trait Notification { - public mixed $payload; + public object $payload; public string $message = ''; diff --git a/src/Trait/ActionEventTrait.php b/src/Trait/ActionEventTrait.php index 7c05b68..5161e0a 100644 --- a/src/Trait/ActionEventTrait.php +++ b/src/Trait/ActionEventTrait.php @@ -4,11 +4,11 @@ trait ActionEventTrait { - public function getActionOfEvent($payload): string + public function getActionOfEvent(object $payload): string { - $action = $payload?->action - ?? $payload?->object_attributes?->action - ?? $payload?->object_attributes?->noteable_type + $action = $payload->action + ?? $payload->object_attributes?->action + ?? $payload->object_attributes?->noteable_type ?? ''; if (!empty($action)) {