run phpcs

This commit is contained in:
James Cole
2025-01-05 07:31:26 +01:00
parent 0f69e0d672
commit c3ffd39450
29 changed files with 112 additions and 94 deletions

View File

@@ -64,7 +64,7 @@ class ConvertsDatesToUTC extends Command
// this variable is ALWAYS en_US.
// stops phpstan complaining about dead code.
if (config('app.fallback_locale') === 'en_US') {
if ('en_US' === config('app.fallback_locale')) {
return Command::SUCCESS;
}
@@ -112,7 +112,7 @@ class ConvertsDatesToUTC extends Command
$items->each(
function ($item) use ($field, $timezoneField): void {
/** @var Carbon $date */
$date = Carbon::parse($item->{$field}, $item->{$timezoneField}); // @phpstan-ignore-line
$date = Carbon::parse($item->{$field}, $item->{$timezoneField}); // @phpstan-ignore-line
$date->setTimezone('UTC');
$item->{$field} = $date->format('Y-m-d H:i:s'); // @phpstan-ignore-line
$item->{$timezoneField} = 'UTC'; // @phpstan-ignore-line

View File

@@ -111,6 +111,7 @@ class CorrectsAccountTypes extends Command
$this->friendlyLine(sprintf('Found %d journals that need to be fixed.', $resultSet->count()));
foreach ($resultSet as $entry) {
app('log')->debug(sprintf('Now fixing journal #%d', $entry->id));
/** @var null|TransactionJournal $journal */
$journal = TransactionJournal::find($entry->id);
if (null !== $journal) {

View File

@@ -236,7 +236,7 @@ class CorrectsNativeAmounts extends Command
TransactionObserver::$recalculate = false;
foreach ($set as $item) {
// here we are.
/** @var Transaction|null $transaction */
/** @var null|Transaction $transaction */
$transaction = Transaction::find($item->id);
$transaction?->touch();
}

View File

@@ -36,7 +36,7 @@ class RemovesEmptyJournals extends Command
protected $description = 'Delete empty and uneven transaction journals.';
protected $signature = 'correction:empty-journals';
protected $signature = 'correction:empty-journals';
/**
* Execute the console command.
@@ -55,8 +55,8 @@ class RemovesEmptyJournals extends Command
private function deleteUnevenJournals(): void
{
$set = Transaction::whereNull('deleted_at')
->groupBy('transactions.transaction_journal_id')
->get([\DB::raw('COUNT(transactions.transaction_journal_id) as the_count'), 'transaction_journal_id']) // @phpstan-ignore-line
->groupBy('transactions.transaction_journal_id')
->get([\DB::raw('COUNT(transactions.transaction_journal_id) as the_count'), 'transaction_journal_id']) // @phpstan-ignore-line
;
$total = 0;
@@ -66,7 +66,7 @@ class RemovesEmptyJournals extends Command
if (1 === $count % 2) {
// uneven number, delete journal and transactions:
try {
/** @var TransactionJournal|null $journal */
/** @var null|TransactionJournal $journal */
$journal = TransactionJournal::find($row->transaction_journal_id);
$journal?->delete();
} catch (QueryException $e) {
@@ -87,13 +87,14 @@ class RemovesEmptyJournals extends Command
{
$count = 0;
$set = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->groupBy('transaction_journals.id')
->whereNull('transactions.transaction_journal_id')
->get(['transaction_journals.id']);
->groupBy('transaction_journals.id')
->whereNull('transactions.transaction_journal_id')
->get(['transaction_journals.id'])
;
foreach ($set as $entry) {
try {
/** @var TransactionJournal|null $journal */
/** @var null|TransactionJournal $journal */
$journal = TransactionJournal::find($entry->id);
$journal?->delete();
} catch (QueryException $e) {

View File

@@ -69,7 +69,7 @@ class RemovesOrphanedTransactions extends Command
}
$this->friendlyInfo(sprintf('Found %d orphaned journal(s).', $count));
foreach ($set as $entry) {
/** @var TransactionJournal|null $journal */
/** @var null|TransactionJournal $journal */
$journal = TransactionJournal::withTrashed()->find($entry->id);
if (null !== $journal) {
$journal->delete();
@@ -131,7 +131,7 @@ class RemovesOrphanedTransactions extends Command
/** @var Transaction $transaction */
foreach ($set as $transaction) {
// delete journals
/** @var TransactionJournal|null $journal */
/** @var null|TransactionJournal $journal */
$journal = TransactionJournal::find($transaction->transaction_journal_id);
if (null !== $journal) {
$journal->delete();

View File

@@ -256,15 +256,16 @@ class ForcesDecimalSize extends Command
foreach ($result as $account) {
/** @var string $field */
foreach ($fields as $field) {
$value = $account->{$field};
$value = $account->{$field};
if (null === $value) {
continue;
}
// fix $field by rounding it down correctly.
$pow = 10 ** $currency->decimal_places;
$correct = bcdiv((string) round($value * $pow), (string) $pow, 12);
$pow = 10 ** $currency->decimal_places;
$correct = bcdiv((string) round($value * $pow), (string) $pow, 12);
$this->friendlyInfo(sprintf('Account #%d has %s with value "%s", this has been corrected to "%s".', $account->id, $field, $value, $correct));
/** @var Account|null $updateAccount */
/** @var null|Account $updateAccount */
$updateAccount = Account::find($account->id);
$updateAccount?->update([$field => $correct]);
}
@@ -315,8 +316,9 @@ class ForcesDecimalSize extends Command
$pow = 10 ** $currency->decimal_places;
$correct = bcdiv((string) round($value * $pow), (string) $pow, 12);
$this->friendlyWarning(sprintf('%s #%d has %s with value "%s", this has been corrected to "%s".', $table, $item->id, $field, $value, $correct));
/** @var Model|null $model */
$model = $class::find($item->id);
/** @var null|Model $model */
$model = $class::find($item->id);
$model?->update([$field => $correct]);
}
}
@@ -369,8 +371,9 @@ class ForcesDecimalSize extends Command
$this->friendlyWarning(
sprintf('Piggy bank event #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct)
);
/** @var PiggyBankEvent|null $event */
$event = PiggyBankEvent::find($item->id);
/** @var null|PiggyBankEvent $event */
$event = PiggyBankEvent::find($item->id);
$event?->update([$field => $correct]);
}
}
@@ -414,17 +417,18 @@ class ForcesDecimalSize extends Command
foreach ($result as $item) {
/** @var string $field */
foreach ($fields as $field) {
$value = $item->{$field};
$value = $item->{$field};
if (null === $value) {
continue;
}
// fix $field by rounding it down correctly.
$pow = 10 ** $currency->decimal_places;
$correct = bcdiv((string) round($value * $pow), (string) $pow, 12);
$pow = 10 ** $currency->decimal_places;
$correct = bcdiv((string) round($value * $pow), (string) $pow, 12);
$this->friendlyWarning(
sprintf('Piggy bank repetition #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct)
);
/** @var PiggyBankRepetition|null $repetition */
/** @var null|PiggyBankRepetition $repetition */
$repetition = PiggyBankRepetition::find($item->id);
$repetition->update([$field => $correct]);
}
@@ -467,15 +471,16 @@ class ForcesDecimalSize extends Command
foreach ($result as $item) {
/** @var string $field */
foreach ($fields as $field) {
$value = $item->{$field};
$value = $item->{$field};
if (null === $value) {
continue;
}
// fix $field by rounding it down correctly.
$pow = 10 ** $currency->decimal_places;
$correct = bcdiv((string) round($value * $pow), (string) $pow, 12);
$pow = 10 ** $currency->decimal_places;
$correct = bcdiv((string) round($value * $pow), (string) $pow, 12);
$this->friendlyWarning(sprintf('Piggy bank #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct));
/** @var PiggyBank|null $piggyBank */
/** @var null|PiggyBank $piggyBank */
$piggyBank = PiggyBank::find($item->id);
$piggyBank?->update([$field => $correct]);
}
@@ -502,15 +507,16 @@ class ForcesDecimalSize extends Command
/** @var Transaction $item */
foreach ($result as $item) {
$value = $item->amount;
$value = $item->amount;
if ('' === $value) {
continue;
}
// fix $field by rounding it down correctly.
$pow = (float) 10 ** $currency->decimal_places;
$correct = bcdiv((string) round((float) $value * $pow), (string) $pow, 12);
$pow = (float) 10 ** $currency->decimal_places;
$correct = bcdiv((string) round((float) $value * $pow), (string) $pow, 12);
$this->friendlyWarning(sprintf('Transaction #%d has amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct));
/** @var Transaction|null $transaction */
/** @var null|Transaction $transaction */
$transaction = Transaction::find($item->id);
$transaction?->update(['amount' => $correct]);
}
@@ -532,17 +538,18 @@ class ForcesDecimalSize extends Command
/** @var Transaction $item */
foreach ($result as $item) {
$value = $item->foreign_amount;
$value = $item->foreign_amount;
if (null === $value) {
continue;
}
// fix $field by rounding it down correctly.
$pow = (float) 10 ** $currency->decimal_places;
$correct = bcdiv((string) round((float) $value * $pow), (string) $pow, 12);
$pow = (float) 10 ** $currency->decimal_places;
$correct = bcdiv((string) round((float) $value * $pow), (string) $pow, 12);
$this->friendlyWarning(
sprintf('Transaction #%d has foreign amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct)
);
/** @var Transaction|null $transaction */
/** @var null|Transaction $transaction */
$transaction = Transaction::find($item->id);
$transaction?->update(['foreign_amount' => $correct]);
}