mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Various PSR12 code cleanup
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
@@ -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
|
||||
*/
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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
|
||||
*/
|
||||
|
@@ -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
|
||||
*/
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user