Various PSR12 code cleanup

This commit is contained in:
James Cole
2022-12-29 19:42:26 +01:00
parent dbf3e76ecc
commit 6cfdc58cb1
415 changed files with 7462 additions and 6874 deletions

View File

@@ -41,8 +41,8 @@ use stdClass;
class AccountDestroyService
{
/**
* @param Account $account
* @param Account|null $moveTo
* @param Account $account
* @param Account|null $moveTo
*
* @return void
*/
@@ -76,7 +76,7 @@ class AccountDestroyService
}
/**
* @param Account $account
* @param Account $account
*/
private function destroyOpeningBalance(Account $account): void
{
@@ -87,13 +87,13 @@ class AccountDestroyService
->where('transaction_types.type', TransactionType::OPENING_BALANCE)
->get(['transactions.transaction_journal_id']);
if ($set->count() > 0) {
$journalId = (int) $set->first()->transaction_journal_id;
$journalId = (int)$set->first()->transaction_journal_id;
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)
->where('account_id', '!=', $account->id)
->get();
->where('account_id', '!=', $account->id)
->get();
/** @var Transaction $transaction */
foreach ($transactions as $transaction) {
Log::debug(sprintf('Found transaction with ID #%d', $transaction->id));
@@ -112,8 +112,8 @@ class AccountDestroyService
}
/**
* @param Account $account
* @param Account $moveTo
* @param Account $account
* @param Account $moveTo
*/
public function moveTransactions(Account $account, Account $moveTo): void
{
@@ -132,8 +132,8 @@ class AccountDestroyService
$user = $account->user;
/** @var stdClass $row */
foreach ($collection as $row) {
if ((int) $row->the_count > 1) {
$journalId = (int) $row->transaction_journal_id;
if ((int)$row->the_count > 1) {
$journalId = (int)$row->transaction_journal_id;
$journal = $user->transactionJournals()->find($journalId);
if (null !== $journal) {
Log::debug(sprintf('Deleted journal #%d because it has the same source as destination.', $journal->id));
@@ -144,8 +144,8 @@ class AccountDestroyService
}
/**
* @param Account $account
* @param Account $moveTo
* @param Account $account
* @param Account $moveTo
*/
private function updateRecurrences(Account $account, Account $moveTo): void
{
@@ -154,28 +154,28 @@ class AccountDestroyService
}
/**
* @param Account $account
* @param Account $account
*/
private function destroyJournals(Account $account): void
{
/** @var JournalDestroyService $service */
$service = app(JournalDestroyService::class);
Log::debug('Now trigger account delete response #' . $account->id);
Log::debug('Now trigger account delete response #'.$account->id);
/** @var Transaction $transaction */
foreach ($account->transactions()->get() as $transaction) {
Log::debug('Now at transaction #' . $transaction->id);
Log::debug('Now at transaction #'.$transaction->id);
/** @var TransactionJournal $journal */
$journal = $transaction->transactionJournal()->first();
if (null !== $journal) {
Log::debug('Call for deletion of journal #' . $journal->id);
Log::debug('Call for deletion of journal #'.$journal->id);
$service->destroy($journal);
}
}
}
/**
* @param Account $account
* @param Account $account
*/
private function destroyRecurrences(Account $account): void
{
@@ -189,7 +189,7 @@ class AccountDestroyService
/** @var RecurrenceDestroyService $destroyService */
$destroyService = app(RecurrenceDestroyService::class);
foreach ($recurrences as $recurrenceId) {
$destroyService->destroyById((int) $recurrenceId);
$destroyService->destroyById((int)$recurrenceId);
}
}
}

View File

@@ -33,7 +33,7 @@ use FireflyIII\Models\Bill;
class BillDestroyService
{
/**
* @param Bill $bill
* @param Bill $bill
*/
public function destroy(Bill $bill): void
{

View File

@@ -35,7 +35,7 @@ use FireflyIII\Models\Budget;
class BudgetDestroyService
{
/**
* @param Budget $budget
* @param Budget $budget
*/
public function destroy(Budget $budget): void
{
@@ -51,10 +51,10 @@ class BudgetDestroyService
}
// also delete all relations between categories and transaction journals:
DB::table('budget_transaction_journal')->where('budget_id', (int) $budget->id)->delete();
DB::table('budget_transaction_journal')->where('budget_id', (int)$budget->id)->delete();
// also delete all relations between categories and transactions:
DB::table('budget_transaction')->where('budget_id', (int) $budget->id)->delete();
DB::table('budget_transaction')->where('budget_id', (int)$budget->id)->delete();
// also delete all budget limits
$budget->budgetlimits()->delete();

View File

@@ -35,7 +35,7 @@ use FireflyIII\Models\Category;
class CategoryDestroyService
{
/**
* @param Category $category
* @param Category $category
*/
public function destroy(Category $category): void
{
@@ -46,9 +46,9 @@ class CategoryDestroyService
}
// also delete all relations between categories and transaction journals:
DB::table('category_transaction_journal')->where('category_id', (int) $category->id)->delete();
DB::table('category_transaction_journal')->where('category_id', (int)$category->id)->delete();
// also delete all relations between categories and transactions:
DB::table('category_transaction')->where('category_id', (int) $category->id)->delete();
DB::table('category_transaction')->where('category_id', (int)$category->id)->delete();
}
}

View File

@@ -34,7 +34,7 @@ use FireflyIII\Models\TransactionCurrency;
class CurrencyDestroyService
{
/**
* @param TransactionCurrency $currency
* @param TransactionCurrency $currency
*/
public function destroy(TransactionCurrency $currency): void
{

View File

@@ -39,7 +39,7 @@ use Log;
class JournalDestroyService
{
/**
* @param TransactionJournal $journal
* @param TransactionJournal $journal
*/
public function destroy(TransactionJournal $journal): void
{

View File

@@ -36,7 +36,7 @@ class RecurrenceDestroyService
/**
* Delete recurrence by ID
*
* @param int $recurrenceId
* @param int $recurrenceId
*/
public function destroyById(int $recurrenceId): void
{
@@ -50,7 +50,7 @@ class RecurrenceDestroyService
/**
* Delete recurrence.
*
* @param Recurrence $recurrence
* @param Recurrence $recurrence
*
*/
public function destroy(Recurrence $recurrence): void

View File

@@ -35,7 +35,7 @@ use FireflyIII\Models\TransactionGroup;
class TransactionGroupDestroyService
{
/**
* @param TransactionGroup $transactionGroup
* @param TransactionGroup $transactionGroup
*/
public function destroy(TransactionGroup $transactionGroup): void
{

View File

@@ -39,6 +39,7 @@ use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Services\Internal\Destroy\TransactionGroupDestroyService;
use JsonException;
use Log;
use Validator;
@@ -377,7 +378,7 @@ trait AccountServiceTrait
*
* @return TransactionCurrency
* @throws FireflyException
* @throws \JsonException
* @throws JsonException
*/
protected function getCurrency(int $currencyId, string $currencyCode): TransactionCurrency
{

View File

@@ -37,9 +37,9 @@ use Log;
trait BillServiceTrait
{
/**
* @param Bill $bill
* @param string $oldName
* @param string $newName
* @param Bill $bill
* @param string $oldName
* @param string $newName
*/
public function updateBillActions(Bill $bill, string $oldName, string $newName): void
{
@@ -60,8 +60,8 @@ trait BillServiceTrait
}
/**
* @param Bill $bill
* @param string $note
* @param Bill $bill
* @param string $note
*
* @return bool
*/

View File

@@ -262,7 +262,9 @@ class CreditRecalculateService
&& 'credit' === $direction
) {
$amount = bcadd($amount, app('steam')->positive($usedAmount));
Log::debug(sprintf('Is withdrawal (%s) into credit liability #%d, will increase amount due to %s.', $transaction->account_id, $usedAmount, $amount));
Log::debug(
sprintf('Is withdrawal (%s) into credit liability #%d, will increase amount due to %s.', $transaction->account_id, $usedAmount, $amount)
);
return $amount;
}

View File

@@ -50,9 +50,9 @@ trait JournalServiceTrait
private TagFactory $tagFactory;
/**
* @param string $transactionType
* @param string $direction
* @param array $data
* @param string $transactionType
* @param string $direction
* @param array $data
*
* @return Account|null
* @codeCoverageIgnore
@@ -88,8 +88,8 @@ trait JournalServiceTrait
}
/**
* @param array $data
* @param array $types
* @param array $data
* @param array $types
*
* @return Account|null
*/
@@ -98,7 +98,7 @@ trait JournalServiceTrait
$search = null;
// first attempt, find by ID.
if (null !== $data['id']) {
$search = $this->accountRepository->find((int) $data['id']);
$search = $this->accountRepository->find((int)$data['id']);
if (null !== $search && in_array($search->accountType->type, $types, true)) {
Log::debug(
sprintf('Found "account_id" object: #%d, "%s" of type %s', $search->id, $search->name, $search->accountType->type)
@@ -110,9 +110,9 @@ trait JournalServiceTrait
}
/**
* @param Account|null $account
* @param array $data
* @param array $types
* @param Account|null $account
* @param array $data
* @param array $types
*
* @return Account|null
*/
@@ -137,22 +137,22 @@ trait JournalServiceTrait
}
/**
* @param Account|null $account
* @param array $data
* @param array $types
* @param Account|null $account
* @param array $data
* @param array $types
*
* @return Account|null
*/
private function findAccountByNumber(?Account $account, array $data, array $types): ?Account
{
// third attempt, find by account number
if (null === $account && null !== $data['number'] && '' !== (string) $data['number']) {
if (null === $account && null !== $data['number'] && '' !== (string)$data['number']) {
Log::debug(sprintf('Searching for account number "%s".', $data['number']));
// find by preferred type.
$source = $this->accountRepository->findByAccountNumber((string) $data['number'], [$types[0]]);
$source = $this->accountRepository->findByAccountNumber((string)$data['number'], [$types[0]]);
// or any expected type.
$source = $source ?? $this->accountRepository->findByAccountNumber((string) $data['number'], $types);
$source = $source ?? $this->accountRepository->findByAccountNumber((string)$data['number'], $types);
if (null !== $source) {
Log::debug(sprintf('Found account: #%d, %s', $source->id, $source->name));
@@ -165,9 +165,9 @@ trait JournalServiceTrait
}
/**
* @param Account|null $account
* @param array $data
* @param array $types
* @param Account|null $account
* @param array $data
* @param array $types
*
* @return Account|null
*/
@@ -191,9 +191,9 @@ trait JournalServiceTrait
}
/**
* @param Account|null $account
* @param array $data
* @param string $preferredType
* @param Account|null $account
* @param array $data
* @param string $preferredType
*
* @return Account|null
* @throws FireflyException
@@ -218,12 +218,12 @@ trait JournalServiceTrait
throw new FireflyException(sprintf('TransactionFactory: Cannot create asset account with these values: %s', json_encode($data)));
}
// fix name of account if only IBAN is given:
if ('' === (string) $data['name'] && '' !== (string) $data['iban']) {
if ('' === (string)$data['name'] && '' !== (string)$data['iban']) {
Log::debug(sprintf('Account name is now IBAN ("%s")', $data['iban']));
$data['name'] = $data['iban'];
}
// fix name of account if only number is given:
if ('' === (string) $data['name'] && '' !== (string) $data['number']) {
if ('' === (string)$data['name'] && '' !== (string)$data['number']) {
Log::debug(sprintf('Account name is now account number ("%s")', $data['number']));
$data['name'] = $data['number'];
}
@@ -264,16 +264,16 @@ trait JournalServiceTrait
}
/**
* @param Account|null $account
* @param array $data
* @param array $types
* @param Account|null $account
* @param array $data
* @param array $types
*
* @return Account|null
*/
private function getCashAccount(?Account $account, array $data, array $types): ?Account
{
// return cash account.
if (null === $account && '' === (string) $data['name']
if (null === $account && '' === (string)$data['name']
&& in_array(AccountType::CASH, $types, true)) {
$account = $this->accountRepository->getCashAccount();
}
@@ -282,7 +282,7 @@ trait JournalServiceTrait
}
/**
* @param string $amount
* @param string $amount
*
* @return string
* @throws FireflyException
@@ -302,7 +302,7 @@ trait JournalServiceTrait
}
/**
* @param string|null $amount
* @param string|null $amount
*
* @return string|null
* @codeCoverageIgnore
@@ -330,8 +330,8 @@ trait JournalServiceTrait
}
/**
* @param TransactionJournal $journal
* @param NullArrayObject $data
* @param TransactionJournal $journal
* @param NullArrayObject $data
*
* @codeCoverageIgnore
*/
@@ -354,8 +354,8 @@ trait JournalServiceTrait
}
/**
* @param TransactionJournal $journal
* @param NullArrayObject $data
* @param TransactionJournal $journal
* @param NullArrayObject $data
*
* @codeCoverageIgnore
*/
@@ -373,14 +373,14 @@ trait JournalServiceTrait
}
/**
* @param TransactionJournal $journal
* @param string|null $notes
* @param TransactionJournal $journal
* @param string|null $notes
*
* @codeCoverageIgnore
*/
protected function storeNotes(TransactionJournal $journal, ?string $notes): void
{
$notes = (string) $notes;
$notes = (string)$notes;
$note = $journal->notes()->first();
if ('' !== $notes) {
if (null === $note) {
@@ -406,8 +406,8 @@ trait JournalServiceTrait
/**
* Link tags to journal.
*
* @param TransactionJournal $journal
* @param array|null $tags
* @param TransactionJournal $journal
* @param array|null $tags
*
* @codeCoverageIgnore
*/
@@ -423,7 +423,7 @@ trait JournalServiceTrait
}
Log::debug('Start of loop.');
foreach ($tags as $string) {
$string = (string) $string;
$string = (string)$string;
Log::debug(sprintf('Now at tag "%s"', $string));
if ('' !== $string) {
$tag = $this->tagFactory->findOrCreate($string);

View File

@@ -33,8 +33,8 @@ use Illuminate\Database\Eloquent\Model;
trait LocationServiceTrait
{
/**
* @param Model $model
* @param array $data
* @param Model $model
* @param array $data
*
* @return Location|null
*/

View File

@@ -41,6 +41,7 @@ use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\Models\RecurrenceTransactionMeta;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Validation\AccountValidator;
use JsonException;
use Log;
/**
@@ -50,8 +51,8 @@ use Log;
trait RecurringTransactionTrait
{
/**
* @param Recurrence $recurrence
* @param string $note
* @param Recurrence $recurrence
* @param string $note
*
* @return bool
*/
@@ -81,8 +82,8 @@ trait RecurringTransactionTrait
}
/**
* @param Recurrence $recurrence
* @param array $repetitions
* @param Recurrence $recurrence
* @param array $repetitions
*/
protected function createRepetitions(Recurrence $recurrence, array $repetitions): void
{
@@ -103,11 +104,11 @@ trait RecurringTransactionTrait
/**
* Store transactions of a recurring transactions. It's complex but readable.
*
* @param Recurrence $recurrence
* @param array $transactions
* @param Recurrence $recurrence
* @param array $transactions
*
* @throws FireflyException
* @throws \JsonException
* @throws JsonException
*/
protected function createTransactions(Recurrence $recurrence, array $transactions): void
{
@@ -144,7 +145,7 @@ trait RecurringTransactionTrait
if (!$validator->validateDestination(['id' => $destination->id])) {
throw new FireflyException(sprintf('Destination invalid: %s', $validator->destError));
}
if (array_key_exists('foreign_amount', $array) && '' === (string) $array['foreign_amount']) {
if (array_key_exists('foreign_amount', $array) && '' === (string)$array['foreign_amount']) {
unset($array['foreign_amount']);
}
// TODO typeOverrule. The account validator may have a different opinion on the type of the transaction.
@@ -156,25 +157,25 @@ trait RecurringTransactionTrait
'source_id' => $source->id,
'destination_id' => $destination->id,
'amount' => $array['amount'],
'foreign_amount' => array_key_exists('foreign_amount', $array) ? (string) $array['foreign_amount'] : null,
'foreign_amount' => array_key_exists('foreign_amount', $array) ? (string)$array['foreign_amount'] : null,
'description' => $array['description'],
]
);
$transaction->save();
if (array_key_exists('budget_id', $array)) {
$this->setBudget($transaction, (int) $array['budget_id']);
$this->setBudget($transaction, (int)$array['budget_id']);
}
if (array_key_exists('bill_id', $array)) {
$this->setBill($transaction, (int) $array['bill_id']);
$this->setBill($transaction, (int)$array['bill_id']);
}
if (array_key_exists('category_id', $array)) {
$this->setCategory($transaction, (int) $array['category_id']);
$this->setCategory($transaction, (int)$array['category_id']);
}
// same for piggy bank
if (array_key_exists('piggy_bank_id', $array)) {
$this->updatePiggyBank($transaction, (int) $array['piggy_bank_id']);
$this->updatePiggyBank($transaction, (int)$array['piggy_bank_id']);
}
if (array_key_exists('tags', $array) && is_array($array['tags'])) {
@@ -184,23 +185,23 @@ trait RecurringTransactionTrait
}
/**
* @param array $expectedTypes
* @param int|null $accountId
* @param string|null $accountName
* @param array $expectedTypes
* @param int|null $accountId
* @param string|null $accountName
*
* @return Account
*/
protected function findAccount(array $expectedTypes, ?int $accountId, ?string $accountName): Account
{
$result = null;
$accountId = (int) $accountId;
$accountName = (string) $accountName;
$accountId = (int)$accountId;
$accountName = (string)$accountName;
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($this->user);
// if user has submitted an account ID, search for it.
$result = $repository->find((int) $accountId);
$result = $repository->find((int)$accountId);
if (null !== $result) {
return $result;
}
@@ -234,8 +235,8 @@ trait RecurringTransactionTrait
}
/**
* @param RecurrenceTransaction $transaction
* @param int $budgetId
* @param RecurrenceTransaction $transaction
* @param int $budgetId
*/
private function setBudget(RecurrenceTransaction $transaction, int $budgetId): void
{
@@ -257,8 +258,8 @@ trait RecurringTransactionTrait
}
/**
* @param RecurrenceTransaction $transaction
* @param int $billId
* @param RecurrenceTransaction $transaction
* @param int $billId
*/
private function setBill(RecurrenceTransaction $transaction, int $billId): void
{
@@ -280,8 +281,8 @@ trait RecurringTransactionTrait
}
/**
* @param RecurrenceTransaction $transaction
* @param int $categoryId
* @param RecurrenceTransaction $transaction
* @param int $categoryId
*
* @throws FireflyException
*/
@@ -309,8 +310,8 @@ trait RecurringTransactionTrait
}
/**
* @param RecurrenceTransaction $transaction
* @param int $piggyId
* @param RecurrenceTransaction $transaction
* @param int $piggyId
*/
protected function updatePiggyBank(RecurrenceTransaction $transaction, int $piggyId): void
{
@@ -334,8 +335,8 @@ trait RecurringTransactionTrait
}
/**
* @param RecurrenceTransaction $transaction
* @param array $tags
* @param RecurrenceTransaction $transaction
* @param array $tags
*/
protected function updateTags(RecurrenceTransaction $transaction, array $tags): void
{
@@ -355,7 +356,7 @@ trait RecurringTransactionTrait
}
/**
* @param Recurrence $recurrence
* @param Recurrence $recurrence
*
* @codeCoverageIgnore
*/
@@ -365,7 +366,7 @@ trait RecurringTransactionTrait
}
/**
* @param Recurrence $recurrence
* @param Recurrence $recurrence
*
* @codeCoverageIgnore
*/

View File

@@ -38,7 +38,7 @@ trait TransactionTypeTrait
* Get the transaction type. Since this is mandatory, will throw an exception when nothing comes up. Will always
* use TransactionType repository.
*
* @param string $type
* @param string $type
*
* @return TransactionType
* @throws FireflyException

View File

@@ -62,19 +62,11 @@ class AccountUpdateService
$this->accountRepository = app(AccountRepositoryInterface::class);
}
/**
* @param User $user
*/
public function setUser(User $user): void
{
$this->user = $user;
}
/**
* Update account data.
*
* @param Account $account
* @param array $data
* @param Account $account
* @param array $data
*
* @return Account
* @throws FireflyException
@@ -89,7 +81,7 @@ class AccountUpdateService
// find currency, or use default currency instead.
if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
$currency = $this->getCurrency((int) ($data['currency_id'] ?? null), (string) ($data['currency_code'] ?? null));
$currency = $this->getCurrency((int)($data['currency_id'] ?? null), (string)($data['currency_code'] ?? null));
unset($data['currency_code'], $data['currency_id']);
$data['currency_id'] = $currency->id;
}
@@ -108,7 +100,7 @@ class AccountUpdateService
// update note:
if (array_key_exists('notes', $data) && null !== $data['notes']) {
$this->updateNote($account, (string) $data['notes']);
$this->updateNote($account, (string)$data['notes']);
}
// update preferences if inactive:
@@ -120,8 +112,16 @@ class AccountUpdateService
}
/**
* @param Account $account
* @param array $data
* @param User $user
*/
public function setUser(User $user): void
{
$this->user = $user;
}
/**
* @param Account $account
* @param array $data
*
* @return Account
*/
@@ -135,19 +135,19 @@ class AccountUpdateService
$account->active = $data['active'];
}
if (array_key_exists('iban', $data)) {
$account->iban = app('steam')->filterSpaces((string) $data['iban']);
$account->iban = app('steam')->filterSpaces((string)$data['iban']);
}
// set liability, but account must already be a liability.
//$liabilityType = $data['liability_type'] ?? '';
if ($this->isLiability($account) && array_key_exists('liability_type', $data)) {
$type = $this->getAccountType($data['liability_type']);
$type = $this->getAccountType($data['liability_type']);
$account->account_type_id = $type->id;
}
// set liability, alternative method used in v1 layout:
if ($this->isLiability($account) && array_key_exists('account_type_id', $data)) {
$type = AccountType::find((int) $data['account_type_id']);
$type = AccountType::find((int)$data['account_type_id']);
if (null !== $type && in_array($type->type, config('firefly.valid_liabilities'), true)) {
$account->account_type_id = $type->id;
@@ -165,7 +165,7 @@ class AccountUpdateService
}
/**
* @param Account $account
* @param Account $account
*
* @return bool
*/
@@ -177,7 +177,7 @@ class AccountUpdateService
}
/**
* @param string $type
* @param string $type
*
* @return AccountType
*/
@@ -187,8 +187,8 @@ class AccountUpdateService
}
/**
* @param Account $account
* @param array $data
* @param Account $account
* @param array $data
*
* @return Account
*/
@@ -208,7 +208,7 @@ class AccountUpdateService
return $account;
}
// get account type ID's because a join and an update is hard:
$oldOrder = (int) $account->order;
$oldOrder = (int)$account->order;
$newOrder = $data['order'];
Log::debug(sprintf('Order is set to be updated from %s to %s', $oldOrder, $newOrder));
$list = $this->getTypeIds([AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT]);
@@ -246,15 +246,15 @@ class AccountUpdateService
foreach ($array as $type) {
/** @var AccountType $type */
$type = AccountType::whereType($type)->first();
$return[] = (int) $type->id;
$return[] = (int)$type->id;
}
return $return;
}
/**
* @param Account $account
* @param array $data
* @param Account $account
* @param array $data
*/
private function updateLocation(Account $account, array $data): void
{
@@ -283,8 +283,8 @@ class AccountUpdateService
}
/**
* @param Account $account
* @param array $data
* @param Account $account
* @param array $data
*
* @throws FireflyException
*/
@@ -308,8 +308,8 @@ class AccountUpdateService
}
/**
* @param Account $account
* @param array $data
* @param Account $account
* @param array $data
*
* @throws FireflyException
*/
@@ -338,7 +338,7 @@ class AccountUpdateService
}
/**
* @param Account $account
* @param Account $account
*
* @throws FireflyException
*/
@@ -355,12 +355,12 @@ class AccountUpdateService
$array = $preference->data;
Log::debug('Old array is: ', $array);
Log::debug(sprintf('Must remove : %d', $account->id));
$removeAccountId = (int) $account->id;
$removeAccountId = (int)$account->id;
$new = [];
foreach ($array as $value) {
if ((int) $value !== $removeAccountId) {
if ((int)$value !== $removeAccountId) {
Log::debug(sprintf('Will include: %d', $value));
$new[] = (int) $value;
$new[] = (int)$value;
}
}
Log::debug('Final new array is', $new);

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Update;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\TransactionCurrencyFactory;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Rule;
@@ -32,6 +33,7 @@ use FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups;
use FireflyIII\Services\Internal\Support\BillServiceTrait;
use FireflyIII\User;
use Illuminate\Support\Collection;
use JsonException;
use Log;
/**
@@ -46,12 +48,12 @@ class BillUpdateService
protected User $user;
/**
* @param Bill $bill
* @param array $data
* @param Bill $bill
* @param array $data
*
* @return Bill
* @throws \FireflyIII\Exceptions\FireflyException
* @throws \JsonException
* @throws FireflyException
* @throws JsonException
*/
public function update(Bill $bill, array $data): Bill
{
@@ -59,7 +61,7 @@ class BillUpdateService
if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
$factory = app(TransactionCurrencyFactory::class);
$currency = $factory->find((int) ($data['currency_id'] ?? null), $data['currency_code'] ?? null) ??
$currency = $factory->find((int)($data['currency_id'] ?? null), $data['currency_code'] ?? null) ??
app('amount')->getDefaultCurrencyByUser($bill->user);
// enable the currency if it isn't.
@@ -81,14 +83,14 @@ class BillUpdateService
];
// update note:
if (array_key_exists('notes', $data)) {
$this->updateNote($bill, (string) $data['notes']);
$this->updateNote($bill, (string)$data['notes']);
}
// update order.
if (array_key_exists('order', $data)) {
// update the order of the piggy bank:
$oldOrder = (int) $bill->order;
$newOrder = (int) ($data['order'] ?? $oldOrder);
$oldOrder = (int)$bill->order;
$newOrder = (int)($data['order'] ?? $oldOrder);
if ($oldOrder !== $newOrder) {
$this->updateOrder($bill, $oldOrder, $newOrder);
}
@@ -120,7 +122,7 @@ class BillUpdateService
}
if (array_key_exists('object_group_id', $data)) {
// try also with ID:
$objectGroupId = (int) ($data['object_group_id'] ?? 0);
$objectGroupId = (int)($data['object_group_id'] ?? 0);
if (0 !== $objectGroupId) {
$objectGroup = $this->findObjectGroupById($objectGroupId);
if (null !== $objectGroup) {
@@ -140,27 +142,27 @@ class BillUpdateService
}
/**
* @param Bill $bill
* @param array $data
* @param Bill $bill
* @param array $data
*
* @return Bill
*/
private function updateBillProperties(Bill $bill, array $data): Bill
{
if (array_key_exists('name', $data) && '' !== (string) $data['name']) {
if (array_key_exists('name', $data) && '' !== (string)$data['name']) {
$bill->name = $data['name'];
}
if (array_key_exists('amount_min', $data) && '' !== (string) $data['amount_min']) {
if (array_key_exists('amount_min', $data) && '' !== (string)$data['amount_min']) {
$bill->amount_min = $data['amount_min'];
}
if (array_key_exists('amount_max', $data) && '' !== (string) $data['amount_max']) {
if (array_key_exists('amount_max', $data) && '' !== (string)$data['amount_max']) {
$bill->amount_max = $data['amount_max'];
}
if (array_key_exists('date', $data) && '' !== (string) $data['date']) {
if (array_key_exists('date', $data) && '' !== (string)$data['date']) {
$bill->date = $data['date'];
}
if (array_key_exists('repeat_freq', $data) && '' !== (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)) {
@@ -184,9 +186,9 @@ class BillUpdateService
}
/**
* @param Bill $bill
* @param int $oldOrder
* @param int $newOrder
* @param Bill $bill
* @param int $oldOrder
* @param int $newOrder
*/
private function updateOrder(Bill $bill, int $oldOrder, int $newOrder): void
{
@@ -207,9 +209,9 @@ class BillUpdateService
}
/**
* @param Bill $bill
* @param array $oldData
* @param array $newData
* @param Bill $bill
* @param array $oldData
* @param array $newData
*/
private function updateBillTriggers(Bill $bill, array $oldData, array $newData): void
{
@@ -228,7 +230,8 @@ class BillUpdateService
'name' => 'description_contains',
'amount_min' => 'amount_more',
'amount_max' => 'amount_less',
'transaction_currency_name' => 'currency_is'];
'transaction_currency_name' => 'currency_is',
];
foreach ($fields as $field => $ruleTriggerKey) {
if (!array_key_exists($field, $newData)) {
continue;
@@ -242,10 +245,10 @@ class BillUpdateService
}
/**
* @param Collection $rules
* @param string $key
* @param string $oldValue
* @param string $newValue
* @param Collection $rules
* @param string $key
* @param string $oldValue
* @param string $newValue
*/
private function updateRules(Collection $rules, string $key, string $oldValue, string $newValue): void
{
@@ -268,8 +271,8 @@ class BillUpdateService
}
/**
* @param Rule $rule
* @param string $key
* @param Rule $rule
* @param string $key
*
* @return RuleTrigger|null
*/

View File

@@ -51,7 +51,7 @@ class CategoryUpdateService
}
/**
* @param mixed $user
* @param mixed $user
*/
public function setUser($user): void
{
@@ -59,8 +59,8 @@ class CategoryUpdateService
}
/**
* @param Category $category
* @param array $data
* @param Category $category
* @param array $data
*
* @return Category
* @throws Exception
@@ -83,8 +83,8 @@ class CategoryUpdateService
}
/**
* @param string $oldName
* @param string $newName
* @param string $oldName
* @param string $newName
*/
private function updateRuleTriggers(string $oldName, string $newName): void
{
@@ -104,8 +104,8 @@ class CategoryUpdateService
}
/**
* @param string $oldName
* @param string $newName
* @param string $oldName
* @param string $newName
*/
private function updateRuleActions(string $oldName, string $newName): void
{
@@ -125,22 +125,22 @@ class CategoryUpdateService
}
/**
* @param string $oldName
* @param string $newName
* @param string $oldName
* @param string $newName
*/
private function updateRecurrences(string $oldName, string $newName): void
{
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')
->where('rt_meta.value', $oldName)
->update(['rt_meta.value' => $newName]);
->leftJoin('recurrences', 'recurrences.id', '=', 'recurrences_transactions.recurrence_id')
->where('recurrences.user_id', $this->user->id)
->where('rt_meta.name', 'category_name')
->where('rt_meta.value', $oldName)
->update(['rt_meta.value' => $newName]);
}
/**
* @param Category $category
* @param array $data
* @param Category $category
* @param array $data
*
* @throws Exception
*/

View File

@@ -33,22 +33,22 @@ use FireflyIII\Models\TransactionCurrency;
class CurrencyUpdateService
{
/**
* @param TransactionCurrency $currency
* @param array $data
* @param TransactionCurrency $currency
* @param array $data
*
* @return TransactionCurrency
*/
public function update(TransactionCurrency $currency, array $data): TransactionCurrency
{
if (array_key_exists('code', $data) && '' !== (string) $data['code']) {
if (array_key_exists('code', $data) && '' !== (string)$data['code']) {
$currency->code = $data['code'];
}
if (array_key_exists('symbol', $data) && '' !== (string) $data['symbol']) {
if (array_key_exists('symbol', $data) && '' !== (string)$data['symbol']) {
$currency->symbol = $data['symbol'];
}
if (array_key_exists('name', $data) && '' !== (string) $data['name']) {
if (array_key_exists('name', $data) && '' !== (string)$data['name']) {
$currency->name = $data['name'];
}

View File

@@ -41,7 +41,7 @@ use FireflyIII\Models\TransactionJournalMeta;
class GroupCloneService
{
/**
* @param TransactionGroup $group
* @param TransactionGroup $group
*
* @return TransactionGroup
*/
@@ -50,16 +50,16 @@ class GroupCloneService
$newGroup = $group->replicate();
$newGroup->save();
foreach ($group->transactionJournals as $journal) {
$this->cloneJournal($journal, $newGroup, (int) $group->id);
$this->cloneJournal($journal, $newGroup, (int)$group->id);
}
return $newGroup;
}
/**
* @param TransactionJournal $journal
* @param TransactionGroup $newGroup
* @param int $originalGroup
* @param TransactionJournal $journal
* @param TransactionGroup $newGroup
* @param int $originalGroup
*/
private function cloneJournal(TransactionJournal $journal, TransactionGroup $newGroup, int $originalGroup): void
{
@@ -107,17 +107,17 @@ class GroupCloneService
// add relation.
// TODO clone ALL linked piggy banks
/** @var PiggyBankEvent $event */
$event = $journal->piggyBankEvents()->first();
$event = $journal->piggyBankEvents()->first();
if (null !== $event) {
$piggyBank = $event->piggyBank;
$factory = app(PiggyBankEventFactory::class);
$factory = app(PiggyBankEventFactory::class);
$factory->create($newJournal, $piggyBank);
}
}
/**
* @param Transaction $transaction
* @param TransactionJournal $newJournal
* @param Transaction $transaction
* @param TransactionJournal $newJournal
*/
private function cloneTransaction(Transaction $transaction, TransactionJournal $newJournal): void
{
@@ -128,9 +128,9 @@ class GroupCloneService
}
/**
* @param Note $note
* @param TransactionJournal $newJournal
* @param int $oldGroupId
* @param Note $note
* @param TransactionJournal $newJournal
* @param int $oldGroupId
*/
private function cloneNote(Note $note, TransactionJournal $newJournal, int $oldGroupId): void
{
@@ -144,8 +144,8 @@ class GroupCloneService
}
/**
* @param TransactionJournalMeta $meta
* @param TransactionJournal $newJournal
* @param TransactionJournalMeta $meta
* @param TransactionJournal $newJournal
*/
private function cloneMeta(TransactionJournalMeta $meta, TransactionJournal $newJournal): void
{

View File

@@ -29,6 +29,7 @@ use FireflyIII\Factory\TransactionJournalFactory;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
use JsonException;
use Log;
/**
@@ -39,8 +40,8 @@ class GroupUpdateService
/**
* Update a transaction group.
*
* @param TransactionGroup $transactionGroup
* @param array $data
* @param TransactionGroup $transactionGroup
* @param array $data
*
* @return TransactionGroup
* @throws DuplicateTransactionException
@@ -96,7 +97,7 @@ class GroupUpdateService
/** @var string $deletedId */
foreach ($result as $deletedId) {
/** @var TransactionJournal $journal */
$journal = $transactionGroup->transactionJournals()->find((int) $deletedId);
$journal = $transactionGroup->transactionJournals()->find((int)$deletedId);
/** @var JournalDestroyService $service */
$service = app(JournalDestroyService::class);
$service->destroy($journal);
@@ -112,9 +113,9 @@ class GroupUpdateService
/**
* Update single journal.
*
* @param TransactionGroup $transactionGroup
* @param TransactionJournal $journal
* @param array $data
* @param TransactionGroup $transactionGroup
* @param TransactionJournal $journal
* @param array $data
*/
private function updateTransactionJournal(TransactionGroup $transactionGroup, TransactionJournal $journal, array $data): void
{
@@ -134,8 +135,8 @@ class GroupUpdateService
}
/**
* @param TransactionGroup $transactionGroup
* @param array $transactions
* @param TransactionGroup $transactionGroup
* @param array $transactions
*
* @return array
* @throws DuplicateTransactionException
@@ -147,12 +148,12 @@ class GroupUpdateService
// updated or created transaction journals:
$updated = [];
/**
* @var int $index
* @var int $index
* @var array $transaction
*/
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);
$journalId = (int)($transaction['transaction_journal_id'] ?? 0);
/** @var TransactionJournal|null $journal */
$journal = $transactionGroup->transactionJournals()->find($journalId);
if (null === $journal) {
@@ -190,14 +191,14 @@ class GroupUpdateService
}
/**
* @param TransactionGroup $transactionGroup
* @param array $data
* @param TransactionGroup $transactionGroup
* @param array $data
*
* @return TransactionJournal|null
*
* @throws DuplicateTransactionException
* @throws FireflyException
* @throws \JsonException
* @throws JsonException
*/
private function createTransactionJournal(TransactionGroup $transactionGroup, array $data): ?TransactionJournal
{

View File

@@ -82,14 +82,26 @@ class JournalUpdateService
$this->tagFactory = app(TagFactory::class);
$this->accountRepository = app(AccountRepositoryInterface::class);
$this->currencyRepository = app(CurrencyRepositoryInterface::class);
$this->metaString = ['sepa_cc', 'sepa_ct_op', 'sepa_ct_id', 'sepa_db', 'sepa_country', 'sepa_ep', 'sepa_ci', 'sepa_batch_id',
'recurrence_id',
'internal_reference', 'bunq_payment_id', 'external_id', 'external_url'];
$this->metaString = [
'sepa_cc',
'sepa_ct_op',
'sepa_ct_id',
'sepa_db',
'sepa_country',
'sepa_ep',
'sepa_ci',
'sepa_batch_id',
'recurrence_id',
'internal_reference',
'bunq_payment_id',
'external_id',
'external_url',
];
$this->metaDate = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date',];
}
/**
* @param array $data
* @param array $data
*/
public function setData(array $data): void
{
@@ -97,7 +109,7 @@ class JournalUpdateService
}
/**
* @param TransactionGroup $transactionGroup
* @param TransactionGroup $transactionGroup
*/
public function setTransactionGroup(TransactionGroup $transactionGroup): void
{
@@ -114,7 +126,7 @@ class JournalUpdateService
}
/**
* @param TransactionJournal $transactionJournal
* @param TransactionJournal $transactionJournal
*/
public function setTransactionJournal(TransactionJournal $transactionJournal): void
{
@@ -226,7 +238,7 @@ class JournalUpdateService
}
/**
* @param array $fields
* @param array $fields
*
* @return bool
*/
@@ -360,7 +372,7 @@ class JournalUpdateService
}
$sourceInfo = [
'id' => (int) ($this->data['source_id'] ?? null),
'id' => (int)($this->data['source_id'] ?? null),
'name' => $this->data['source_name'] ?? null,
'iban' => $this->data['source_iban'] ?? null,
'number' => $this->data['source_number'] ?? null,
@@ -425,7 +437,7 @@ class JournalUpdateService
}
$destInfo = [
'id' => (int) ($this->data['destination_id'] ?? null),
'id' => (int)($this->data['destination_id'] ?? null),
'name' => $this->data['destination_name'] ?? null,
'iban' => $this->data['destination_iban'] ?? null,
'number' => $this->data['destination_number'] ?? null,
@@ -490,8 +502,8 @@ class JournalUpdateService
)
&& TransactionType::WITHDRAWAL === $type
) {
$billId = (int) ($this->data['bill_id'] ?? 0);
$billName = (string) ($this->data['bill_name'] ?? '');
$billId = (int)($this->data['bill_id'] ?? 0);
$billName = (string)($this->data['bill_name'] ?? '');
$bill = $this->billRepository->findBill($billId, $billName);
$this->transactionJournal->bill_id = $bill?->id;
Log::debug('Updated bill ID');
@@ -501,11 +513,11 @@ class JournalUpdateService
/**
* Update journal generic field. Cannot be set to NULL.
*
* @param string $fieldName
* @param string $fieldName
*/
private function updateField(string $fieldName): void
{
if (array_key_exists($fieldName, $this->data) && '' !== (string) $this->data[$fieldName]) {
if (array_key_exists($fieldName, $this->data) && '' !== (string)$this->data[$fieldName]) {
$value = $this->data[$fieldName];
if ('date' === $fieldName) {
@@ -582,7 +594,7 @@ class JournalUpdateService
{
// update notes.
if ($this->hasFields(['notes'])) {
$notes = '' === (string) $this->data['notes'] ? null : $this->data['notes'];
$notes = '' === (string)$this->data['notes'] ? null : $this->data['notes'];
$this->storeNotes($this->transactionJournal, $notes);
}
}
@@ -639,7 +651,7 @@ class JournalUpdateService
foreach ($this->metaDate as $field) {
if ($this->hasFields([$field])) {
try {
$value = '' === (string) $this->data[$field] ? null : new Carbon($this->data[$field]);
$value = '' === (string)$this->data[$field] ? null : new Carbon($this->data[$field]);
} catch (Exception $e) {
Log::debug(sprintf('%s is not a valid date value: %s', $this->data[$field], $e->getMessage()));

View File

@@ -52,8 +52,8 @@ class RecurrenceUpdateService
*
* TODO if the user updates the type, the accounts must be validated again.
*
* @param Recurrence $recurrence
* @param array $data
* @param Recurrence $recurrence
* @param array $data
*
* @return Recurrence
* @throws FireflyException
@@ -79,7 +79,7 @@ class RecurrenceUpdateService
$recurrence->repetitions = 0;
}
if (array_key_exists('nr_of_repetitions', $info)) {
if (0 !== (int) $info['nr_of_repetitions']) {
if (0 !== (int)$info['nr_of_repetitions']) {
$recurrence->repeat_until = null;
}
$recurrence->repetitions = $info['nr_of_repetitions'];
@@ -115,8 +115,8 @@ class RecurrenceUpdateService
}
/**
* @param Recurrence $recurrence
* @param string $text
* @param Recurrence $recurrence
* @param string $text
*/
private function setNoteText(Recurrence $recurrence, string $text): void
{
@@ -142,8 +142,8 @@ class RecurrenceUpdateService
/**
*
* @param Recurrence $recurrence
* @param array $repetitions
* @param Recurrence $recurrence
* @param array $repetitions
*
* @throws FireflyException
*/
@@ -187,8 +187,8 @@ class RecurrenceUpdateService
}
/**
* @param Recurrence $recurrence
* @param array $data
* @param Recurrence $recurrence
* @param array $data
*
* @return RecurrenceRepetition|null
*/
@@ -201,11 +201,12 @@ class RecurrenceUpdateService
return $recurrence->recurrenceRepetitions()->first();
}
// find it:
$fields = ['id' => 'id',
'type' => 'repetition_type',
'moment' => 'repetition_moment',
'skip' => 'repetition_skip',
'weekend' => 'weekend',
$fields = [
'id' => 'id',
'type' => 'repetition_type',
'moment' => 'repetition_moment',
'skip' => 'repetition_skip',
'weekend' => 'weekend',
];
$query = $recurrence->recurrenceRepetitions();
foreach ($fields as $field => $column) {
@@ -220,8 +221,8 @@ class RecurrenceUpdateService
/**
* TODO this method is very complex.
*
* @param Recurrence $recurrence
* @param array $transactions
* @param Recurrence $recurrence
* @param array $transactions
*
* @throws FireflyException
*/
@@ -258,7 +259,7 @@ class RecurrenceUpdateService
unset($current['currency_id'], $current['currency_code']);
}
if (null !== $currency) {
$current['currency_id'] = (int) $currency->id;
$current['currency_id'] = (int)$currency->id;
}
if (array_key_exists('foreign_currency_id', $current) || array_key_exists('foreign_currency_code', $current)) {
$foreignCurrency = $currencyFactory->find($current['foreign_currency_id'] ?? null, $currency['foreign_currency_code'] ?? null);
@@ -267,7 +268,7 @@ class RecurrenceUpdateService
unset($current['foreign_currency_id'], $currency['foreign_currency_code']);
}
if (null !== $foreignCurrency) {
$current['foreign_currency_id'] = (int) $foreignCurrency->id;
$current['foreign_currency_id'] = (int)$foreignCurrency->id;
}
// update fields
@@ -288,35 +289,35 @@ class RecurrenceUpdateService
}
// update meta data
if (array_key_exists('budget_id', $current)) {
$this->setBudget($match, (int) $current['budget_id']);
$this->setBudget($match, (int)$current['budget_id']);
}
if (array_key_exists('bill_id', $current)) {
$this->setBill($match, (int) $current['bill_id']);
$this->setBill($match, (int)$current['bill_id']);
}
// reset category if name is set but empty:
// can be removed when v1 is retired.
if (array_key_exists('category_name', $current) && '' === (string) $current['category_name']) {
if (array_key_exists('category_name', $current) && '' === (string)$current['category_name']) {
$current['category_name'] = null;
$current['category_id'] = 0;
}
if (array_key_exists('category_id', $current)) {
$this->setCategory($match, (int) $current['category_id']);
$this->setCategory($match, (int)$current['category_id']);
}
if (array_key_exists('tags', $current) && is_array($current['tags'])) {
$this->updateTags($match, $current['tags']);
}
if (array_key_exists('piggy_bank_id', $current)) {
$this->updatePiggyBank($match, (int) $current['piggy_bank_id']);
$this->updatePiggyBank($match, (int)$current['piggy_bank_id']);
}
}
}
}
/**
* @param Recurrence $recurrence
* @param array $data
* @param Recurrence $recurrence
* @param array $data
*
* @return RecurrenceTransaction|null
*/