mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-26 05:26:17 +00:00
Various code cleanup.
This commit is contained in:
@@ -51,12 +51,11 @@ class AccountUpdateService
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// TODO move to configuration.
|
||||
$this->canHaveVirtual = [AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD];
|
||||
$this->canHaveVirtual = config('firefly.can_have_virtual_amounts');
|
||||
$this->validAssetFields = config('firefly.valid_asset_fields');
|
||||
$this->validCCFields = config('firefly.valid_cc_fields');
|
||||
$this->validFields = config('firefly.valid_account_fields');
|
||||
$this->accountRepository = app(AccountRepositoryInterface::class);
|
||||
$this->validAssetFields = ['account_role', 'account_number', 'currency_id', 'BIC', 'include_net_worth'];
|
||||
$this->validCCFields = ['account_role', 'cc_monthly_payment_date', 'cc_type', 'account_number', 'currency_id', 'BIC', 'include_net_worth'];
|
||||
$this->validFields = ['account_number', 'currency_id', 'BIC', 'interest', 'interest_period', 'include_net_worth'];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +99,7 @@ class AccountUpdateService
|
||||
$this->updateOpeningBalance($account, $data);
|
||||
|
||||
// update note:
|
||||
if (isset($data['notes']) && null !== $data['notes']) {
|
||||
if (array_key_exists('notes', $data) && null !== $data['notes']) {
|
||||
$this->updateNote($account, (string)$data['notes']);
|
||||
}
|
||||
|
||||
|
||||
@@ -144,20 +144,20 @@ class BillUpdateService
|
||||
*/
|
||||
private function updateBillProperties(Bill $bill, array $data): Bill
|
||||
{
|
||||
if (isset($data['name']) && '' !== (string)$data['name']) {
|
||||
if (array_key_exists('name', $data) && '' !== (string)$data['name']) {
|
||||
$bill->name = $data['name'];
|
||||
}
|
||||
|
||||
if (isset($data['amount_min']) && '' !== (string)$data['amount_min']) {
|
||||
if (array_key_exists('amount_min', $data) && '' !== (string)$data['amount_min']) {
|
||||
$bill->amount_min = $data['amount_min'];
|
||||
}
|
||||
if (isset($data['amount_max']) && '' !== (string)$data['amount_max']) {
|
||||
if (array_key_exists('amount_max', $data) && '' !== (string)$data['amount_max']) {
|
||||
$bill->amount_max = $data['amount_max'];
|
||||
}
|
||||
if (isset($data['date']) && '' !== (string)$data['date']) {
|
||||
if (array_key_exists('date', $data) && '' !== (string)$data['date']) {
|
||||
$bill->date = $data['date'];
|
||||
}
|
||||
if (isset($data['repeat_freq']) && '' !== (string)$data['repeat_freq']) {
|
||||
if (array_key_exists('repeat_freq', $data) && '' !== (string)$data['repeat_freq']) {
|
||||
$bill->repeat_freq = $data['repeat_freq'];
|
||||
}
|
||||
if (array_key_exists('skip', $data)) {
|
||||
|
||||
@@ -154,7 +154,7 @@ class CategoryUpdateService
|
||||
try {
|
||||
$dbNote->delete();
|
||||
} catch (Exception $e) {
|
||||
Log::debug($e->getMessage());
|
||||
// @ignoreException
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -130,15 +130,15 @@ class GroupUpdateService
|
||||
foreach ($transactions as $index => $transaction) {
|
||||
Log::debug(sprintf('Now at #%d of %d', ($index + 1), count($transactions)), $transaction);
|
||||
$journalId = (int)($transaction['transaction_journal_id'] ?? 0);
|
||||
/** @var TransactionJournal $journal */
|
||||
/** @var TransactionJournal|null $journal */
|
||||
$journal = $transactionGroup->transactionJournals()->find($journalId);
|
||||
if (null === $journal) {
|
||||
Log::debug('This entry has no existing journal: make a new split.');
|
||||
// force the transaction type on the transaction data.
|
||||
// by plucking it from another journal in the group:
|
||||
if (!isset($transaction['type'])) {
|
||||
if (!array_key_exists('type', $transaction)) {
|
||||
Log::debug('No transaction type is indicated.');
|
||||
/** @var TransactionJournal $randomJournal */
|
||||
/** @var TransactionJournal|null $randomJournal */
|
||||
$randomJournal = $transactionGroup->transactionJournals()->inRandomOrder()->with(['transactionType'])->first();
|
||||
if (null !== $randomJournal) {
|
||||
$transaction['type'] = $randomJournal->transactionType->type;
|
||||
@@ -182,7 +182,7 @@ class GroupUpdateService
|
||||
} catch (FireflyException $e) {
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
throw new FireflyException(sprintf('Could not create new transaction journal: %s', $e->getMessage()));
|
||||
throw new FireflyException(sprintf('Could not create new transaction journal: %s', $e->getMessage()), 0, $e);
|
||||
}
|
||||
$collection->each(
|
||||
function (TransactionJournal $journal) use ($transactionGroup) {
|
||||
|
||||
@@ -616,7 +616,7 @@ class JournalUpdateService
|
||||
if ($this->hasFields([$field])) {
|
||||
try {
|
||||
$value = '' === (string)$this->data[$field] ? null : new Carbon($this->data[$field]);
|
||||
} catch (Exception $e) {
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
Log::debug(sprintf('%s is not a valid date value: %s', $this->data[$field], $e->getMessage()));
|
||||
|
||||
return;
|
||||
|
||||
@@ -133,11 +133,10 @@ class RecurrenceUpdateService
|
||||
if (null !== $dbNote && '' === $text) {
|
||||
try {
|
||||
$dbNote->delete();
|
||||
} catch (Exception $e) {
|
||||
Log::debug(sprintf('Could not delete note: %s', $e->getMessage()));
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
// @ignoreException
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -252,7 +251,7 @@ class RecurrenceUpdateService
|
||||
$currency = $currencyFactory->find($current['currency_id'] ?? null, $currency['currency_code'] ?? null);
|
||||
}
|
||||
if (null === $currency) {
|
||||
unset($current['currency_id'], $currency['currency_code']);
|
||||
unset($current['currency_id'], $current['currency_code']);
|
||||
}
|
||||
if (null !== $currency) {
|
||||
$current['currency_id'] = (int)$currency->id;
|
||||
|
||||
@@ -22,9 +22,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Password;
|
||||
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Log;
|
||||
use RuntimeException;
|
||||
|
||||
@@ -51,7 +51,7 @@ class PwndVerifierV2 implements Verifier
|
||||
$uri = sprintf('https://api.pwnedpasswords.com/range/%s', $prefix);
|
||||
$opt = [
|
||||
'headers' => [
|
||||
'User-Agent' => 'Firefly III v' . config('firefly.version'),
|
||||
'User-Agent' => sprintf('Firefly III v%s', config('firefly.version')),
|
||||
'Add-Padding' => 'true',
|
||||
],
|
||||
'timeout' => 3.1415];
|
||||
@@ -62,7 +62,7 @@ class PwndVerifierV2 implements Verifier
|
||||
try {
|
||||
$client = new Client();
|
||||
$res = $client->request('GET', $uri, $opt);
|
||||
} catch (GuzzleException | Exception $e) {
|
||||
} catch (GuzzleException | RequestException $e) {
|
||||
Log::error(sprintf('Could not verify password security: %s', $e->getMessage()));
|
||||
|
||||
return true;
|
||||
@@ -73,7 +73,7 @@ class PwndVerifierV2 implements Verifier
|
||||
}
|
||||
try {
|
||||
$strpos = stripos($res->getBody()->getContents(), $rest);
|
||||
} catch (RuntimeException $e) {
|
||||
} catch (RuntimeException $e) { // @phpstan-ignore-line
|
||||
Log::error(sprintf('Could not get body from Pwnd result: %s', $e->getMessage()));
|
||||
$strpos = false;
|
||||
}
|
||||
|
||||
@@ -23,12 +23,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Webhook;
|
||||
|
||||
use Exception;
|
||||
use FireflyIII\Helpers\Webhook\SignatureGeneratorInterface;
|
||||
use FireflyIII\Models\WebhookAttempt;
|
||||
use FireflyIII\Models\WebhookMessage;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use JsonException;
|
||||
use Log;
|
||||
|
||||
@@ -92,7 +91,7 @@ class StandardWebhookSender implements WebhookSenderInterface
|
||||
try {
|
||||
$res = $client->request('POST', $this->message->webhook->url, $options);
|
||||
$this->message->sent = true;
|
||||
} catch (ClientException | Exception $e) {
|
||||
} catch (RequestException $e) {
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
|
||||
@@ -104,7 +103,7 @@ class StandardWebhookSender implements WebhookSenderInterface
|
||||
|
||||
$attempt = new WebhookAttempt;
|
||||
$attempt->webhookMessage()->associate($this->message);
|
||||
$attempt->status_code = $e->getResponse() ? $e->getResponse()->getStatusCode() : 0;
|
||||
$attempt->status_code = $e->hasResponse() ? $e->getResponse()->getStatusCode() : 0;
|
||||
$attempt->logs = $logs;
|
||||
$attempt->save();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user