Various code cleanup

This commit is contained in:
James Cole
2023-01-03 06:48:53 +01:00
parent 6784fe4436
commit 07e4e93632
47 changed files with 118 additions and 211 deletions

View File

@@ -146,11 +146,7 @@ class DeleteOrphanedTransactions extends Command
// delete journals
$journal = TransactionJournal::find((int)$transaction->transaction_journal_id);
if ($journal) {
try {
$journal->delete();
} catch (QueryException $e) {
Log::info(sprintf('Could not delete journal %s', $e->getMessage()));
}
$journal->delete();
}
Transaction::where('transaction_journal_id', (int)$transaction->transaction_journal_id)->delete();
$this->line(

View File

@@ -60,11 +60,7 @@ class DeleteZeroAmount extends Command
/** @var TransactionJournal $journal */
foreach ($journals as $journal) {
$this->info(sprintf('Deleted transaction journal #%d because the amount is zero (0.00).', $journal->id));
try {
$journal->delete();
} catch (QueryException $e) {
$this->line($e->getMessage());
}
$journal->delete();
Transaction::where('transaction_journal_id', $journal->id)->delete();
}

View File

@@ -64,7 +64,7 @@ class FixPiggies extends Command
if (null === $event->transaction_journal_id) {
continue;
}
/** @var TransactionJournal $journal */
/** @var TransactionJournal|null $journal */
$journal = $event->transactionJournal;
if (null === $journal) {

View File

@@ -146,6 +146,7 @@ class FixTransactionTypes extends Command
}
/** @var Transaction $transaction */
$transaction = $collection->first();
/** @var Account|null $account */
$account = $transaction->account;
if (null === $account) {
throw new FireflyException(sprintf('Journal #%d, transaction #%d has no source account.', $journal->id, $transaction->id));
@@ -175,6 +176,7 @@ class FixTransactionTypes extends Command
}
/** @var Transaction $transaction */
$transaction = $collection->first();
/** @var Account|null $account */
$account = $transaction->account;
if (null === $account) {
throw new FireflyException(sprintf('Journal #%d, transaction #%d has no destination account.', $journal->id, $transaction->id));

View File

@@ -93,7 +93,7 @@ class FixUnevenAmount extends Command
if (!$journal) {
return;
}
/** @var Transaction $source */
/** @var Transaction|null $source */
$source = $journal->transactions()->where('amount', '<', 0)->first();
if (null === $source) {
@@ -113,7 +113,7 @@ class FixUnevenAmount extends Command
$amount = bcmul('-1', (string)$source->amount);
// fix amount of destination:
/** @var Transaction $destination */
/** @var Transaction|null $destination */
$destination = $journal->transactions()->where('amount', '>', 0)->first();
if (null === $destination) {

View File

@@ -53,7 +53,7 @@ class RemoveBills extends Command
public function handle(): int
{
$start = microtime(true);
/** @var TransactionType $withdrawal */
/** @var TransactionType|null $withdrawal */
$withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
if (null === $withdrawal) {
return 0;

View File

@@ -163,16 +163,16 @@ class BackToJournals extends Command
private function migrateBudgetsForJournal(TransactionJournal $journal): void
{
// grab category from first transaction
/** @var Transaction $transaction */
/** @var Transaction|null $transaction */
$transaction = $journal->transactions->first();
if (null === $transaction) {
$this->info(sprintf('Transaction journal #%d has no transactions. Will be fixed later.', $journal->id));
return;
}
/** @var Budget $budget */
/** @var Budget|null $budget */
$budget = $transaction->budgets->first();
/** @var Budget $journalBudget */
/** @var Budget|null $journalBudget */
$journalBudget = $journal->budgets->first();
// both have a budget, but they don't match.
@@ -239,16 +239,16 @@ class BackToJournals extends Command
private function migrateCategoriesForJournal(TransactionJournal $journal): void
{
// grab category from first transaction
/** @var Transaction $transaction */
/** @var Transaction|null $transaction */
$transaction = $journal->transactions->first();
if (null === $transaction) {
$this->info(sprintf('Transaction journal #%d has no transactions. Will be fixed later.', $journal->id));
return;
}
/** @var Category $category */
/** @var Category|null $category */
$category = $transaction->categories->first();
/** @var Category $journalCategory */
/** @var Category|null $journalCategory */
$journalCategory = $journal->categories->first();
// both have a category, but they don't match.

View File

@@ -134,6 +134,7 @@ class CreateGroupMemberships extends Command
throw new FireflyException('Firefly III could not find a user role. Please make sure all validations have run.');
}
/** @var GroupMembership|null $membership */
$membership = GroupMembership::create(
[
'user_id' => $user->id,

View File

@@ -81,11 +81,7 @@ class MigrateJournalNotes extends Command
$note->text = $meta->data;
$note->save();
Log::debug(sprintf('Migrated meta note #%d to Note #%d', $meta->id, $note->id));
try {
$meta->delete();
} catch (QueryException $e) {
Log::error(sprintf('Could not delete old meta entry #%d: %s', $meta->id, $e->getMessage()));
}
$meta->delete();
$count++;
}

View File

@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Recurrence;
use FireflyIII\Models\RecurrenceMeta;
use FireflyIII\Models\RecurrenceTransactionMeta;
use Illuminate\Console\Command;
@@ -124,6 +125,7 @@ class MigrateRecurrenceMeta extends Command
*/
private function migrateEntry(RecurrenceMeta $meta): int
{
/** @var Recurrence|null $recurrence */
$recurrence = $meta->recurrence;
if (null === $recurrence) {
return 0;

View File

@@ -351,7 +351,7 @@ class MigrateToGroups extends Command
Log::debug('Now in getTransactionBudget()');
// try to get a budget ID from the left transaction:
/** @var Budget $budget */
/** @var Budget|null $budget */
$budget = $left->budgets()->first();
if (null !== $budget) {
Log::debug(sprintf('Return budget #%d, from transaction #%d', $budget->id, $left->id));
@@ -360,7 +360,7 @@ class MigrateToGroups extends Command
}
// try to get a budget ID from the right transaction:
/** @var Budget $budget */
/** @var Budget|null $budget */
$budget = $right->budgets()->first();
if (null !== $budget) {
Log::debug(sprintf('Return budget #%d, from transaction #%d', $budget->id, $right->id));
@@ -384,7 +384,7 @@ class MigrateToGroups extends Command
Log::debug('Now in getTransactionCategory()');
// try to get a category ID from the left transaction:
/** @var Category $category */
/** @var Category|null $category */
$category = $left->categories()->first();
if (null !== $category) {
Log::debug(sprintf('Return category #%d, from transaction #%d', $category->id, $left->id));
@@ -393,7 +393,7 @@ class MigrateToGroups extends Command
}
// try to get a category ID from the left transaction:
/** @var Category $category */
/** @var Category|null $category */
$category = $right->categories()->first();
if (null !== $category) {
Log::debug(sprintf('Return category #%d, from transaction #%d', $category->id, $category->id));

View File

@@ -57,8 +57,6 @@ class TransactionIdentifier extends Command
private $cliRepository;
/** @var int */
private $count;
/** @var JournalRepositoryInterface */
private $journalRepository;
/**
* This method gives all transactions which are part of a split journal (so more than 2) a sort of "order" so they are easier
@@ -117,7 +115,6 @@ class TransactionIdentifier extends Command
*/
private function stupidLaravel(): void
{
$this->journalRepository = app(JournalRepositoryInterface::class);
$this->cliRepository = app(JournalCLIRepositoryInterface::class);
$this->count = 0;
}