Code cleanup.

This commit is contained in:
James Cole
2023-12-20 19:35:52 +01:00
parent c4f6366642
commit 64ec0cf62e
997 changed files with 12908 additions and 28136 deletions

View File

@@ -30,7 +30,6 @@ use FireflyIII\Models\WebhookMessage;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use JsonException;
/**
* Class StandardWebhookSender
@@ -40,17 +39,11 @@ class StandardWebhookSender implements WebhookSenderInterface
private WebhookMessage $message;
private int $version = 1;
/**
* @inheritDoc
*/
public function getVersion(): int
{
return $this->version;
}
/**
* @inheritDoc
*/
public function send(): void
{
// have the signature generator generate a signature. If it fails, the error thrown will
@@ -58,6 +51,7 @@ class StandardWebhookSender implements WebhookSenderInterface
$signatureGenerator = app(SignatureGeneratorInterface::class);
$this->message->sent = true;
$this->message->save();
try {
$signature = $signatureGenerator->generate($this->message);
} catch (FireflyException $e) {
@@ -80,7 +74,7 @@ class StandardWebhookSender implements WebhookSenderInterface
try {
$json = json_encode($this->message->message, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
} catch (\JsonException $e) {
app('log')->error('Did not send message because of a JSON error.');
app('log')->error($e->getMessage());
app('log')->error($e->getTraceAsString());
@@ -107,14 +101,14 @@ class StandardWebhookSender implements WebhookSenderInterface
],
];
$client = new Client();
try {
$res = $client->request('POST', $this->message->webhook->url, $options);
} catch (RequestException | ConnectException $e) {
} catch (ConnectException|RequestException $e) {
app('log')->error('The webhook could NOT be submitted but Firefly III caught the error below.');
app('log')->error($e->getMessage());
app('log')->error($e->getTraceAsString());
$logs = sprintf("%s\n%s", $e->getMessage(), $e->getTraceAsString());
$this->message->errored = true;
@@ -143,9 +137,6 @@ class StandardWebhookSender implements WebhookSenderInterface
app('log')->debug(sprintf('Response body: %s', $res->getBody()));
}
/**
* @inheritDoc
*/
public function setMessage(WebhookMessage $message): void
{
$this->message = $message;

View File

@@ -30,18 +30,9 @@ use FireflyIII\Models\WebhookMessage;
*/
interface WebhookSenderInterface
{
/**
* @return int
*/
public function getVersion(): int;
/**
*
*/
public function send(): void;
/**
* @param WebhookMessage $message
*/
public function setMessage(WebhookMessage $message): void;
}