mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-25 13:10:35 +00:00
Use PSR-12 code style
This commit is contained in:
@@ -36,7 +36,6 @@ use Log;
|
||||
*/
|
||||
class UpdateRequest implements UpdateRequestInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $channel
|
||||
*
|
||||
@@ -83,7 +82,7 @@ class UpdateRequest implements UpdateRequestInterface
|
||||
$url = config('firefly.update_endpoint');
|
||||
Log::debug(sprintf('Going to call %s', $url));
|
||||
try {
|
||||
$client = new Client;
|
||||
$client = new Client();
|
||||
$options = [
|
||||
'headers' => [
|
||||
'User-Agent' => sprintf('FireflyIII/%s/%s', config('firefly.version'), $channel),
|
||||
@@ -110,7 +109,6 @@ class UpdateRequest implements UpdateRequestInterface
|
||||
$body = (string) $res->getBody();
|
||||
try {
|
||||
$json = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
} catch (JsonException $e) {
|
||||
Log::error('Body is not valid JSON');
|
||||
Log::error($body);
|
||||
|
||||
@@ -35,5 +35,4 @@ interface UpdateRequestInterface
|
||||
* @return array
|
||||
*/
|
||||
public function getUpdateInformation(string $channel): array;
|
||||
|
||||
}
|
||||
|
||||
@@ -91,8 +91,7 @@ class AccountDestroyService
|
||||
Log::debug(sprintf('Found opening balance journal with ID #%d', $journalId));
|
||||
|
||||
// get transactions with this journal (should be just one):
|
||||
$transactions = Transaction
|
||||
::where('transaction_journal_id', $journalId)
|
||||
$transactions = Transaction::where('transaction_journal_id', $journalId)
|
||||
->where('account_id', '!=', $account->id)
|
||||
->get();
|
||||
/** @var Transaction $transaction */
|
||||
@@ -159,7 +158,6 @@ class AccountDestroyService
|
||||
*/
|
||||
private function destroyJournals(Account $account): void
|
||||
{
|
||||
|
||||
/** @var JournalDestroyService $service */
|
||||
$service = app(JournalDestroyService::class);
|
||||
|
||||
@@ -181,8 +179,7 @@ class AccountDestroyService
|
||||
*/
|
||||
private function destroyRecurrences(Account $account): void
|
||||
{
|
||||
$recurrences = RecurrenceTransaction::
|
||||
where(
|
||||
$recurrences = RecurrenceTransaction::where(
|
||||
static function (Builder $q) use ($account) {
|
||||
$q->where('source_id', $account->id);
|
||||
$q->orWhere('destination_id', $account->id);
|
||||
@@ -195,5 +192,4 @@ class AccountDestroyService
|
||||
$destroyService->destroyById((int) $recurrenceId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,5 +43,4 @@ class BillDestroyService
|
||||
// @ignoreException
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ class BudgetDestroyService
|
||||
*/
|
||||
public function destroy(Budget $budget): void
|
||||
{
|
||||
|
||||
try {
|
||||
$budget->delete();
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
|
||||
@@ -38,12 +38,10 @@ class CurrencyDestroyService
|
||||
*/
|
||||
public function destroy(TransactionCurrency $currency): void
|
||||
{
|
||||
|
||||
try {
|
||||
$currency->delete();
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
// @ignoreException
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -95,11 +95,8 @@ class JournalDestroyService
|
||||
$group->delete();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
// @ignoreException
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ class RecurrenceDestroyService
|
||||
return;
|
||||
}
|
||||
$this->destroy($recurrence);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,5 +81,4 @@ class RecurrenceDestroyService
|
||||
// @ignoreException
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ use FireflyIII\Models\TransactionGroup;
|
||||
*/
|
||||
class TransactionGroupDestroyService
|
||||
{
|
||||
|
||||
/**
|
||||
* @param TransactionGroup $transactionGroup
|
||||
*/
|
||||
@@ -50,5 +49,4 @@ class TransactionGroupDestroyService
|
||||
// @ignoreException
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -118,8 +118,8 @@ trait AccountServiceTrait
|
||||
// remove currency_id if necessary.
|
||||
$type = $account->accountType->type;
|
||||
$list = config('firefly.valid_currency_account_types');
|
||||
if(!in_array($type, $list, true)) {
|
||||
$pos = array_search('currency_id', $fields);
|
||||
if (!in_array($type, $list, true)) {
|
||||
$pos = array_search('currency_id', $fields, true);
|
||||
if ($pos !== false) {
|
||||
unset($fields[$pos]);
|
||||
}
|
||||
@@ -147,7 +147,6 @@ trait AccountServiceTrait
|
||||
// if the field is set but NULL, skip it.
|
||||
// if the field is set but "", update it.
|
||||
if (array_key_exists($field, $data) && null !== $data[$field]) {
|
||||
|
||||
// convert boolean value:
|
||||
if (is_bool($data[$field]) && false === $data[$field]) {
|
||||
$data[$field] = 0;
|
||||
@@ -184,7 +183,7 @@ trait AccountServiceTrait
|
||||
}
|
||||
$dbNote = $account->notes()->first();
|
||||
if (null === $dbNote) {
|
||||
$dbNote = new Note;
|
||||
$dbNote = new Note();
|
||||
$dbNote->noteable()->associate($account);
|
||||
}
|
||||
$dbNote->text = trim($note);
|
||||
|
||||
@@ -36,7 +36,6 @@ use Log;
|
||||
*/
|
||||
trait BillServiceTrait
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
* @param string $oldName
|
||||
@@ -90,5 +89,4 @@ trait BillServiceTrait
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,10 +22,8 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace FireflyIII\Services\Internal\Support;
|
||||
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Factory\AccountMetaFactory;
|
||||
use FireflyIII\Models\Account;
|
||||
@@ -110,11 +108,11 @@ class CreditRecalculateService
|
||||
|
||||
// destination or source must be liability.
|
||||
$valid = config('firefly.valid_liabilities');
|
||||
if (in_array($destination->accountType->type, $valid)) {
|
||||
if (in_array($destination->accountType->type, $valid, true)) {
|
||||
Log::debug(sprintf('Dest account type is "%s", include it.', $destination->accountType->type));
|
||||
$this->work[] = $destination;
|
||||
}
|
||||
if (in_array($source->accountType->type, $valid)) {
|
||||
if (in_array($source->accountType->type, $valid, true)) {
|
||||
Log::debug(sprintf('Src account type is "%s", include it.', $source->accountType->type));
|
||||
$this->work[] = $source;
|
||||
}
|
||||
@@ -170,7 +168,7 @@ class CreditRecalculateService
|
||||
private function processAccount(): void
|
||||
{
|
||||
$valid = config('firefly.valid_liabilities');
|
||||
if (in_array($this->account->accountType->type, $valid)) {
|
||||
if (in_array($this->account->accountType->type, $valid, true)) {
|
||||
Log::debug(sprintf('Account type is "%s", include it.', $this->account->accountType->type));
|
||||
$this->work[] = $this->account;
|
||||
}
|
||||
@@ -290,6 +288,4 @@ class CreditRecalculateService
|
||||
{
|
||||
$this->group = $group;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -206,13 +206,13 @@ trait JournalServiceTrait
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'Was given %s account #%d ("%s") so will simply return that.',
|
||||
$account->accountType->type, $account->id, $account->name
|
||||
|
||||
$account->accountType->type,
|
||||
$account->id,
|
||||
$account->name
|
||||
)
|
||||
);
|
||||
}
|
||||
if (null === $account) {
|
||||
|
||||
// final attempt, create it.
|
||||
if (AccountType::ASSET === $preferredType) {
|
||||
throw new FireflyException(sprintf('TransactionFactory: Cannot create asset account with these values: %s', json_encode($data)));
|
||||
@@ -258,7 +258,6 @@ trait JournalServiceTrait
|
||||
$metaFactory = app(AccountMetaFactory::class);
|
||||
$metaFactory->create(['account_id' => $account->id, 'name' => 'account_number', 'data' => $data['number']]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $account;
|
||||
@@ -385,7 +384,7 @@ trait JournalServiceTrait
|
||||
$note = $journal->notes()->first();
|
||||
if ('' !== $notes) {
|
||||
if (null === $note) {
|
||||
$note = new Note;
|
||||
$note = new Note();
|
||||
$note->noteable()->associate($journal);
|
||||
}
|
||||
$note->text = $notes;
|
||||
|
||||
@@ -42,7 +42,7 @@ trait LocationServiceTrait
|
||||
{
|
||||
$data['store_location'] = $data['store_location'] ?? false;
|
||||
if ($data['store_location']) {
|
||||
$location = new Location;
|
||||
$location = new Location();
|
||||
$location->latitude = $data['latitude'] ?? config('firefly.default_location.latitude');
|
||||
$location->longitude = $data['longitude'] ?? config('firefly.default_location.longitude');
|
||||
$location->zoom_level = $data['zoom_level'] ?? config('firefly.default_location.zoom_level');
|
||||
@@ -54,5 +54,4 @@ trait LocationServiceTrait
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -97,7 +97,6 @@ trait RecurringTransactionTrait
|
||||
'weekend' => $array['weekend'] ?? 1,
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +180,6 @@ trait RecurringTransactionTrait
|
||||
if (array_key_exists('tags', $array) && is_array($array['tags'])) {
|
||||
$this->updateTags($transaction, $array['tags']);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,11 +224,9 @@ trait RecurringTransactionTrait
|
||||
if (!in_array($expectedType, $cannotCreate, true)) {
|
||||
try {
|
||||
$result = $factory->findOrCreate($accountName, $expectedType);
|
||||
|
||||
} catch (FireflyException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +248,7 @@ trait RecurringTransactionTrait
|
||||
|
||||
$meta = $transaction->recurrenceTransactionMeta()->where('name', 'budget_id')->first();
|
||||
if (null === $meta) {
|
||||
$meta = new RecurrenceTransactionMeta;
|
||||
$meta = new RecurrenceTransactionMeta();
|
||||
$meta->rt_id = $transaction->id;
|
||||
$meta->name = 'budget_id';
|
||||
}
|
||||
@@ -275,7 +271,7 @@ trait RecurringTransactionTrait
|
||||
|
||||
$meta = $transaction->recurrenceTransactionMeta()->where('name', 'bill_id')->first();
|
||||
if (null === $meta) {
|
||||
$meta = new RecurrenceTransactionMeta;
|
||||
$meta = new RecurrenceTransactionMeta();
|
||||
$meta->rt_id = $transaction->id;
|
||||
$meta->name = 'bill_id';
|
||||
}
|
||||
@@ -304,7 +300,7 @@ trait RecurringTransactionTrait
|
||||
|
||||
$meta = $transaction->recurrenceTransactionMeta()->where('name', 'category_id')->first();
|
||||
if (null === $meta) {
|
||||
$meta = new RecurrenceTransactionMeta;
|
||||
$meta = new RecurrenceTransactionMeta();
|
||||
$meta->rt_id = $transaction->id;
|
||||
$meta->name = 'category_id';
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ class AccountUpdateService
|
||||
if (!(null === $data['latitude'] && null === $data['longitude'] && null === $data['zoom_level'])) {
|
||||
$location = $this->accountRepository->getLocation($account);
|
||||
if (null === $location) {
|
||||
$location = new Location;
|
||||
$location = new Location();
|
||||
$location->locatable()->associate($account);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,8 @@ use Log;
|
||||
*/
|
||||
class BillUpdateService
|
||||
{
|
||||
use BillServiceTrait, CreatesObjectGroups;
|
||||
use BillServiceTrait;
|
||||
use CreatesObjectGroups;
|
||||
|
||||
protected User $user;
|
||||
|
||||
@@ -203,7 +204,6 @@ class BillUpdateService
|
||||
$bill->order = $newOrder;
|
||||
$bill->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,7 +239,6 @@ class BillUpdateService
|
||||
}
|
||||
$this->updateRules($rules, $ruleTriggerKey, $oldData[$field], $newData[$field]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -130,8 +130,7 @@ class CategoryUpdateService
|
||||
*/
|
||||
private function updateRecurrences(string $oldName, string $newName): void
|
||||
{
|
||||
RecurrenceTransactionMeta
|
||||
::leftJoin('recurrences_transactions', 'rt_meta.rt_id', '=', 'recurrences_transactions.id')
|
||||
RecurrenceTransactionMeta::leftJoin('recurrences_transactions', 'rt_meta.rt_id', '=', 'recurrences_transactions.id')
|
||||
->leftJoin('recurrences', 'recurrences.id', '=', 'recurrences_transactions.recurrence_id')
|
||||
->where('recurrences.user_id', $this->user->id)
|
||||
->where('rt_meta.name', 'category_name')
|
||||
@@ -165,11 +164,10 @@ class CategoryUpdateService
|
||||
}
|
||||
$dbNote = $category->notes()->first();
|
||||
if (null === $dbNote) {
|
||||
$dbNote = new Note;
|
||||
$dbNote = new Note();
|
||||
$dbNote->noteable()->associate($category);
|
||||
}
|
||||
$dbNote->text = trim($note);
|
||||
$dbNote->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -64,5 +64,4 @@ class CurrencyUpdateService
|
||||
|
||||
return $currency;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class GroupCloneService
|
||||
// clone linked piggy banks
|
||||
/** @var PiggyBankEvent $event */
|
||||
$event = $journal->piggyBankEvents()->first();
|
||||
if(null !== $event) {
|
||||
if (null !== $event) {
|
||||
$piggyBank = $event->piggyBank;
|
||||
$factory = app(PiggyBankEventFactory::class);
|
||||
$factory->create($newJournal, $piggyBank);
|
||||
@@ -136,11 +136,11 @@ class GroupCloneService
|
||||
{
|
||||
$newNote = $note->replicate();
|
||||
$newNote->text .= sprintf(
|
||||
"\n\n%s", trans('firefly.clones_journal_x', ['description' => $newJournal->description, 'id' => $oldGroupId])
|
||||
"\n\n%s",
|
||||
trans('firefly.clones_journal_x', ['description' => $newJournal->description, 'id' => $oldGroupId])
|
||||
);
|
||||
$newNote->noteable_id = $newJournal->id;
|
||||
$newNote->save();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -227,5 +227,4 @@ class GroupUpdateService
|
||||
|
||||
return $collection->first();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -456,7 +456,9 @@ class JournalUpdateService
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'Trying to change journal #%d from a %s to a %s.',
|
||||
$this->transactionJournal->id, $this->transactionJournal->transactionType->type, $type
|
||||
$this->transactionJournal->id,
|
||||
$this->transactionJournal->transactionType->type,
|
||||
$type
|
||||
)
|
||||
);
|
||||
|
||||
@@ -483,10 +485,10 @@ class JournalUpdateService
|
||||
{
|
||||
$type = $this->transactionJournal->transactionType->type;
|
||||
if ((
|
||||
array_key_exists('bill_id', $this->data)
|
||||
|| array_key_exists('bill_name', $this->data)
|
||||
)
|
||||
&& TransactionType::WITHDRAWAL === $type
|
||||
array_key_exists('bill_id', $this->data)
|
||||
|| array_key_exists('bill_name', $this->data)
|
||||
)
|
||||
&& TransactionType::WITHDRAWAL === $type
|
||||
) {
|
||||
$billId = (int) ($this->data['bill_id'] ?? 0);
|
||||
$billName = (string) ($this->data['bill_name'] ?? '');
|
||||
|
||||
@@ -42,7 +42,8 @@ use Log;
|
||||
*/
|
||||
class RecurrenceUpdateService
|
||||
{
|
||||
use TransactionTypeTrait, RecurringTransactionTrait;
|
||||
use TransactionTypeTrait;
|
||||
use RecurringTransactionTrait;
|
||||
|
||||
private User $user;
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class StandardWebhookSender implements WebhookSenderInterface
|
||||
Log::error('Did not send message because of a Firefly III Exception.');
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
$attempt = new WebhookAttempt;
|
||||
$attempt = new WebhookAttempt();
|
||||
$attempt->webhookMessage()->associate($this->message);
|
||||
$attempt->status_code = 0;
|
||||
$attempt->logs = sprintf('Exception: %s', $e->getMessage());
|
||||
@@ -83,7 +83,7 @@ class StandardWebhookSender implements WebhookSenderInterface
|
||||
Log::error('Did not send message because of a JSON error.');
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
$attempt = new WebhookAttempt;
|
||||
$attempt = new WebhookAttempt();
|
||||
$attempt->webhookMessage()->associate($this->message);
|
||||
$attempt->status_code = 0;
|
||||
$attempt->logs = sprintf('Json error: %s', $e->getMessage());
|
||||
@@ -105,7 +105,7 @@ class StandardWebhookSender implements WebhookSenderInterface
|
||||
'timeout' => 10,
|
||||
],
|
||||
];
|
||||
$client = new Client;
|
||||
$client = new Client();
|
||||
try {
|
||||
$res = $client->request('POST', $this->message->webhook->url, $options);
|
||||
$this->message->sent = true;
|
||||
@@ -119,7 +119,7 @@ class StandardWebhookSender implements WebhookSenderInterface
|
||||
$this->message->sent = false;
|
||||
$this->message->save();
|
||||
|
||||
$attempt = new WebhookAttempt;
|
||||
$attempt = new WebhookAttempt();
|
||||
$attempt->webhookMessage()->associate($this->message);
|
||||
$attempt->status_code = $e->hasResponse() ? $e->getResponse()->getStatusCode() : 0;
|
||||
$attempt->logs = $logs;
|
||||
|
||||
Reference in New Issue
Block a user