Various code cleanup and fixed alignments.

This commit is contained in:
James Cole
2024-01-01 14:36:31 +01:00
parent d4488f041b
commit 30bbd0b3a4
6 changed files with 11 additions and 46 deletions

View File

@@ -104,12 +104,12 @@ class PiggyBankController extends Controller
/** @var PiggyBank $piggy */
foreach ($piggies as $piggy) {
$currency = $this->accountRepository->getAccountCurrency($piggy->account) ?? $defaultCurrency;
$currentAmount = $this->piggyRepository->getRepetition($piggy)->currentamount ?? '0';
$currentAmount = $this->piggyRepository->getRepetition($piggy)->currentamount ?? '0';
$objectGroup = $piggy->objectGroups()->first();
$response[] = [
'id' => (string) $piggy->id,
'name' => $piggy->name,
'name_with_balance' => sprintf(
'id' => (string) $piggy->id,
'name' => $piggy->name,
'name_with_balance' => sprintf(
'%s (%s / %s)',
$piggy->name,
app('amount')->formatAnything($currency, $currentAmount, false),

View File

@@ -54,14 +54,9 @@ class MigrateRecurrenceType extends Command
return 0;
}
$this->friendlyWarning('This command has been disabled.');
$this->markAsExecuted();
return 0;
// $this->migrateTypes();
// $this->markAsExecuted();
//
// return 0;
}
private function isExecuted(): bool
@@ -71,37 +66,6 @@ class MigrateRecurrenceType extends Command
return (bool)$configVar?->data;
}
private function migrateTypes(): void
{
$set = Recurrence::get();
/** @var Recurrence $recurrence */
foreach ($set as $recurrence) {
if (TransactionType::INVALID !== $recurrence->transactionType->type) {
$this->migrateRecurrence($recurrence);
}
}
}
private function migrateRecurrence(Recurrence $recurrence): void
{
$originalType = $recurrence->transaction_type_id;
$newType = $this->getInvalidType();
$recurrence->transaction_type_id = $newType->id;
$recurrence->save();
/** @var RecurrenceTransaction $transaction */
foreach ($recurrence->recurrenceTransactions as $transaction) {
$transaction->transaction_type_id = $originalType;
$transaction->save();
}
$this->friendlyInfo(sprintf('Updated recurrence #%d to new transaction type model.', $recurrence->id));
}
private function getInvalidType(): TransactionType
{
return TransactionType::whereType(TransactionType::INVALID)->firstOrCreate(['type' => TransactionType::INVALID]);
}
private function markAsExecuted(): void
{

View File

@@ -681,7 +681,7 @@ trait MetaCollection
// this method adds a "postFilter" to the collector.
$list = $tags->pluck('tag')->toArray();
$list = array_map('strtolower', $list);
$filter = static function (array $object) use ($list): bool | array {
$filter = static function (array $object) use ($list): bool|array {
$return = $object;
unset($return['transactions']);
$return['transactions'] = [];
@@ -712,6 +712,7 @@ trait MetaCollection
if (true === $result) {
return $return;
}
return false;
};
$this->postFilters[] = $filter;

View File

@@ -561,7 +561,7 @@ class GroupCollector implements GroupCollectorInterface
if (0 !== count($journalIds)) {
// make all integers.
$integerIDs = array_map('intval', $journalIds);
Log::debug(sprintf('GroupCollector: setJournalIds: %s', join(', ', $integerIDs)));
Log::debug(sprintf('GroupCollector: setJournalIds: %s', implode(', ', $integerIDs)));
$this->query->whereIn('transaction_journals.id', $integerIDs);
}

View File

@@ -60,6 +60,7 @@ class RecurrenceController extends Controller
* Shows all events for a repetition. Used in calendar.
*
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
* @throws FireflyException
*/
@@ -126,7 +127,7 @@ class RecurrenceController extends Controller
foreach ($occurrences as $current) {
if ($current->gte($start)) {
$event = [
'id' => $repetitionType . $firstDate->format('Ymd'),
'id' => $repetitionType.$firstDate->format('Ymd'),
'title' => 'X',
'allDay' => true,
'start' => $current->format('Y-m-d'),

View File

@@ -75,9 +75,8 @@ class BudgetFormStoreRequest extends FormRequest
*/
public function withValidator(Validator $validator): void
{
if($validator->fails()) {
Log::channel('audit')->error(sprintf('Validation errors for budget'), $validator->errors()->toArray());
Log::channel('audit')->error('Validation errors for budget', $validator->errors()->toArray());
}
$validator->after(