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 07b74e4 commit 7b1d14e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Interfaces/Structures/AppInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ interface AppInterface
/**
* Send a message to telegram
*
* @param string $message
* @param string|null $message
* @param array $options
*
* @return void
* @throws MessageIsEmptyException
* @see App::sendMessage()
*/
public function sendMessage(string $message = '', array $options = []): void;
public function sendMessage(?string $message = '', array $options = []): void;

/**
* Send a photo to telegram
Expand Down
2 changes: 1 addition & 1 deletion src/Structures/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private function createTelegramBaseContent(): array
];
}

public function sendMessage(string $message = '', array $options = []): void
public function sendMessage(?string $message = '', array $options = []): void
{
if (empty($message)) {
throw MessageIsEmptyException::create();
Expand Down
21 changes: 18 additions & 3 deletions src/Structures/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use GuzzleHttp\Exception\GuzzleException;
use LbilTech\TelegramGitNotifier\Constants\EventConstant;
use LbilTech\TelegramGitNotifier\Exceptions\MessageIsEmptyException;
use LbilTech\TelegramGitNotifier\Exceptions\SendNotificationException;
use Symfony\Component\HttpFoundation\Request;

Expand All @@ -30,11 +31,18 @@ public function accessDenied(

public function setPayload(Request $request, string $event)
{
$content = null;

if ($this->event->platform === 'gitlab') {
$this->payload = json_decode($request->getContent());
$content = $request->getContent();
} elseif ($this->event->platform === EventConstant::DEFAULT_PLATFORM) {
$this->payload = json_decode($request->request->get('payload'));
$content = $request->request->get('payload');
}

if (is_string($content)) {
$this->payload = json_decode($content);
}

$this->setMessage($event);

return $this->payload;
Expand All @@ -46,6 +54,7 @@ public function setPayload(Request $request, string $event)
* @param string $typeEvent
*
* @return void
* @throws MessageIsEmptyException
*/
private function setMessage(string $typeEvent): void
{
Expand All @@ -56,10 +65,16 @@ private function setMessage(string $typeEvent): void
? "events.{$this->event->platform}.{$event}.default"
: "events.{$this->event->platform}.{$event}.{$action}";

$this->message = view($viewTemplate, [
$viewResult = view($viewTemplate, [
'payload' => $this->payload,
'event' => tgn_convert_event_name($typeEvent),
]);

if ($viewResult === null) {
throw MessageIsEmptyException::create();
}

$this->message = $viewResult;
}

public function sendNotify(string $message = null, array $options = []): bool
Expand Down
4 changes: 4 additions & 0 deletions src/Trait/EventSettingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ public function sendSettingEventMessage(

public function getEventFromCallback(?string $callback): string
{
if (!$callback) {
return '';
}

return str_replace([
EventConstant::EVENT_PREFIX,
EventConstant::GITHUB_EVENT_SEPARATOR,
Expand Down

0 comments on commit 7b1d14e

Please sign in to comment.