mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 20:16:22 +00:00
Fix phpstan issues
This commit is contained in:
@@ -25,6 +25,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Repositories\TransactionGroup;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Exceptions\DuplicateTransactionException;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
@@ -42,14 +43,13 @@ use FireflyIII\Models\TransactionJournalLink;
|
||||
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
|
||||
use FireflyIII\Services\Internal\Destroy\TransactionGroupDestroyService;
|
||||
use FireflyIII\Services\Internal\Update\GroupUpdateService;
|
||||
use FireflyIII\Support\Facades\Amount;
|
||||
use FireflyIII\Support\NullArrayObject;
|
||||
use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface;
|
||||
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Exception;
|
||||
|
||||
use function Safe\json_decode;
|
||||
|
||||
/**
|
||||
@@ -143,22 +143,21 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
{
|
||||
$repository = app(AttachmentRepositoryInterface::class);
|
||||
$repository->setUser($this->user);
|
||||
$journals = $group->transactionJournals->pluck('id')->toArray();
|
||||
$set = Attachment::whereIn('attachable_id', $journals)
|
||||
->where('attachable_type', TransactionJournal::class)
|
||||
->where('uploaded', true)
|
||||
->whereNull('deleted_at')->get()
|
||||
;
|
||||
$journals = $group->transactionJournals->pluck('id')->toArray();
|
||||
$set = Attachment::whereIn('attachable_id', $journals)
|
||||
->where('attachable_type', TransactionJournal::class)
|
||||
->where('uploaded', true)
|
||||
->whereNull('deleted_at')->get();
|
||||
|
||||
$result = [];
|
||||
$result = [];
|
||||
|
||||
/** @var Attachment $attachment */
|
||||
foreach ($set as $attachment) {
|
||||
$journalId = $attachment->attachable_id;
|
||||
$result[$journalId] ??= [];
|
||||
$current = $attachment->toArray();
|
||||
$current['file_exists'] = true;
|
||||
$current['notes'] = $repository->getNoteText($attachment);
|
||||
$journalId = $attachment->attachable_id;
|
||||
$result[$journalId] ??= [];
|
||||
$current = $attachment->toArray();
|
||||
$current['file_exists'] = true;
|
||||
$current['notes'] = $repository->getNoteText($attachment);
|
||||
// already determined that this attachable is a TransactionJournal.
|
||||
$current['journal_title'] = $attachment->attachable->description;
|
||||
$result[$journalId][] = $current;
|
||||
@@ -174,9 +173,8 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
{
|
||||
/** @var null|Note $note */
|
||||
$note = Note::where('noteable_id', $journalId)
|
||||
->where('noteable_type', TransactionJournal::class)
|
||||
->first()
|
||||
;
|
||||
->where('noteable_type', TransactionJournal::class)
|
||||
->first();
|
||||
if (null === $note) {
|
||||
return null;
|
||||
}
|
||||
@@ -197,14 +195,13 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
$q->orWhereIn('destination_id', $journals);
|
||||
}
|
||||
)
|
||||
->with(['source', 'destination', 'source.transactions'])
|
||||
->leftJoin('link_types', 'link_types.id', '=', 'journal_links.link_type_id')
|
||||
->get(['journal_links.*', 'link_types.inward', 'link_types.outward', 'link_types.editable'])
|
||||
;
|
||||
->with(['source', 'destination', 'source.transactions'])
|
||||
->leftJoin('link_types', 'link_types.id', '=', 'journal_links.link_type_id')
|
||||
->get(['journal_links.*', 'link_types.inward', 'link_types.outward', 'link_types.editable']);
|
||||
|
||||
/** @var TransactionJournalLink $entry */
|
||||
foreach ($set as $entry) {
|
||||
$journalId = in_array($entry->source_id, $journals, true) ? $entry->source_id : $entry->destination_id;
|
||||
$journalId = in_array($entry->source_id, $journals, true) ? $entry->source_id : $entry->destination_id;
|
||||
$return[$journalId] ??= [];
|
||||
|
||||
// phpstan: the editable field is provided by the query.
|
||||
@@ -248,13 +245,9 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
$type = $journal->transactionType->type;
|
||||
$amount = app('steam')->positive($transaction->amount);
|
||||
if (TransactionTypeEnum::WITHDRAWAL->value === $type) {
|
||||
return app('amount')->formatAnything($currency, app('steam')->negative($amount));
|
||||
return Amount::formatAnything($currency, app('steam')->negative($amount));
|
||||
}
|
||||
if (TransactionTypeEnum::WITHDRAWAL->value !== $type) {
|
||||
return app('amount')->formatAnything($currency, $amount);
|
||||
}
|
||||
|
||||
return '';
|
||||
return Amount::formatAnything($currency, $amount);
|
||||
}
|
||||
|
||||
private function getFormattedForeignAmount(TransactionJournal $journal): string
|
||||
@@ -264,20 +257,18 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
if (null === $transaction->foreign_amount || '' === $transaction->foreign_amount) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (0 === bccomp('0', (string)$transaction->foreign_amount)) {
|
||||
return '';
|
||||
}
|
||||
$currency = $transaction->foreignCurrency;
|
||||
$type = $journal->transactionType->type;
|
||||
$amount = app('steam')->positive($transaction->foreign_amount);
|
||||
if (TransactionTypeEnum::WITHDRAWAL->value === $type) {
|
||||
return app('amount')->formatAnything($currency, app('steam')->negative($amount));
|
||||
}
|
||||
if (TransactionTypeEnum::WITHDRAWAL->value !== $type) {
|
||||
return app('amount')->formatAnything($currency, $amount);
|
||||
}
|
||||
|
||||
return '';
|
||||
$currency = $transaction->foreignCurrency;
|
||||
$type = $journal->transactionType->type;
|
||||
$amount = app('steam')->positive($transaction->foreign_amount);
|
||||
if (TransactionTypeEnum::WITHDRAWAL->value === $type) {
|
||||
return Amount::formatAnything($currency, app('steam')->negative($amount));
|
||||
}
|
||||
return Amount::formatAnything($currency, $amount);
|
||||
}
|
||||
|
||||
public function getLocation(int $journalId): ?Location
|
||||
@@ -297,11 +288,10 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
public function getMetaDateFields(int $journalId, array $fields): NullArrayObject
|
||||
{
|
||||
$query = DB::table('journal_meta')
|
||||
->where('transaction_journal_id', $journalId)
|
||||
->whereIn('name', $fields)
|
||||
->whereNull('deleted_at')
|
||||
->get(['name', 'data'])
|
||||
;
|
||||
->where('transaction_journal_id', $journalId)
|
||||
->whereIn('name', $fields)
|
||||
->whereNull('deleted_at')
|
||||
->get(['name', 'data']);
|
||||
$return = [];
|
||||
|
||||
foreach ($query as $row) {
|
||||
@@ -317,11 +307,10 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
public function getMetaFields(int $journalId, array $fields): NullArrayObject
|
||||
{
|
||||
$query = DB::table('journal_meta')
|
||||
->where('transaction_journal_id', $journalId)
|
||||
->whereIn('name', $fields)
|
||||
->whereNull('deleted_at')
|
||||
->get(['name', 'data'])
|
||||
;
|
||||
->where('transaction_journal_id', $journalId)
|
||||
->whereIn('name', $fields)
|
||||
->whereNull('deleted_at')
|
||||
->get(['name', 'data']);
|
||||
$return = [];
|
||||
|
||||
foreach ($query as $row) {
|
||||
@@ -340,11 +329,10 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
{
|
||||
$return = [];
|
||||
$journals = $group->transactionJournals->pluck('id')->toArray();
|
||||
$currency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
|
||||
$currency = Amount::getPrimaryCurrencyByUserGroup($this->user->userGroup);
|
||||
$data = PiggyBankEvent::whereIn('transaction_journal_id', $journals)
|
||||
->with('piggyBank', 'piggyBank.account')
|
||||
->get(['piggy_bank_events.*'])
|
||||
;
|
||||
->with('piggyBank', 'piggyBank.account')
|
||||
->get(['piggy_bank_events.*']);
|
||||
|
||||
/** @var PiggyBankEvent $row */
|
||||
foreach ($data as $row) {
|
||||
@@ -352,20 +340,19 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
continue;
|
||||
}
|
||||
// get currency preference.
|
||||
$currencyPreference = AccountMeta::where('account_id', $row->piggyBank->account_id)
|
||||
->where('name', 'currency_id')
|
||||
->first()
|
||||
;
|
||||
$currencyPreference = AccountMeta::where('account_id', $row->piggyBank->account_id)
|
||||
->where('name', 'currency_id')
|
||||
->first();
|
||||
if (null !== $currencyPreference) {
|
||||
$currency = TransactionCurrency::where('id', $currencyPreference->data)->first();
|
||||
}
|
||||
$journalId = $row->transaction_journal_id;
|
||||
$journalId = $row->transaction_journal_id;
|
||||
$return[$journalId] ??= [];
|
||||
|
||||
$return[$journalId][] = [
|
||||
'piggy' => $row->piggyBank->name,
|
||||
'piggy_id' => $row->piggy_bank_id,
|
||||
'amount' => app('amount')->formatAnything($currency, $row->amount),
|
||||
'amount' => Amount::formatAnything($currency, $row->amount),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -386,11 +373,10 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
public function getTags(int $journalId): array
|
||||
{
|
||||
$result = DB::table('tag_transaction_journal')
|
||||
->leftJoin('tags', 'tag_transaction_journal.tag_id', '=', 'tags.id')
|
||||
->where('tag_transaction_journal.transaction_journal_id', $journalId)
|
||||
->orderBy('tags.tag', 'ASC')
|
||||
->get(['tags.tag'])
|
||||
;
|
||||
->leftJoin('tags', 'tag_transaction_journal.tag_id', '=', 'tags.id')
|
||||
->where('tag_transaction_journal.transaction_journal_id', $journalId)
|
||||
->orderBy('tags.tag', 'ASC')
|
||||
->get(['tags.tag']);
|
||||
|
||||
return $result->pluck('tag')->toArray();
|
||||
}
|
||||
@@ -445,7 +431,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($journal->transactions as $transaction) {
|
||||
if (-1 === bccomp('0', (string)$transaction->amount)) {
|
||||
$sum = bcadd($sum, (string) $transaction->amount);
|
||||
$sum = bcadd($sum, (string)$transaction->amount);
|
||||
$names = sprintf('%s%s', $names, $transaction->account->name);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user