Skip to content

Commit

Permalink
fix: phpstan test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhongit committed Oct 30, 2023
1 parent eef4e50 commit 75aadbd
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/Helpers/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -56,6 +56,7 @@ public function getTemplateData($partialPath, array $data = []): bool|string
return '';
}

$content = '';
ob_start();
try {
extract($data, EXTR_SKIP);
Expand Down
4 changes: 2 additions & 2 deletions src/Interfaces/EventInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Interfaces/Structures/NotificationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/Models/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Objects/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Structures/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

trait Notification
{
public mixed $payload;
public object $payload;

public string $message = '';

Expand Down
8 changes: 4 additions & 4 deletions src/Trait/ActionEventTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 75aadbd

Please sign in to comment.