Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Clean up some code.
James Cole9c5df6ab6e70
diff --git a/app/Console/Commands/Correction/DeleteEmptyJournals.php b/app/Console/Commands/Correction/DeleteEmptyJournals.phpindex 10dd7c17e1..dad50592ef 100644--- a/app/Console/Commands/Correction/DeleteEmptyJournals.php+++ b/app/Console/Commands/Correction/DeleteEmptyJournals.php@@ -25,6 +25,8 @@ use DB;use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionJournal;use Illuminate\Console\Command;+use Exception;+use Log;/*** Class DeleteEmptyJournals@@ -68,7 +70,11 @@ class DeleteEmptyJournals extends Command->get(['transaction_journals.id']);foreach ($set as $entry) {- TransactionJournal::find($entry->id)->delete();+ try {+ TransactionJournal::find($entry->id)->delete();+ } catch (Exception $e) {+ Log::info(sprintf('Could not delete entry: %s', $e->getMessage()));+ }$this->info(sprintf('Deleted empty transaction journal #%d', $entry->id));++$count;}@@ -103,7 +109,11 @@ class DeleteEmptyJournals extends Command$count = (int)$row->the_count;if (1 === $count % 2) {// uneven number, delete journal and transactions:- TransactionJournal::find((int)$row->transaction_journal_id)->delete();+ try {+ TransactionJournal::find((int)$row->transaction_journal_id)->delete();+ } catch(Exception $e) {+ Log::info(sprintf('Could not delete journal: %s', $e->getMessage()));+ }Transaction::where('transaction_journal_id', (int)$row->transaction_journal_id)->delete();$this->info(sprintf('Deleted transaction journal #%d because it had an uneven number of transactions.', $row->transaction_journal_id));$total++;diff --git a/app/Console/Commands/Correction/DeleteOrphanedTransactions.php b/app/Console/Commands/Correction/DeleteOrphanedTransactions.phpindex 072d2f9a79..1cd267b9c8 100644--- a/app/Console/Commands/Correction/DeleteOrphanedTransactions.php+++ b/app/Console/Commands/Correction/DeleteOrphanedTransactions.php@@ -26,6 +26,7 @@ use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionJournal;use Illuminate\Console\Command;use stdClass;+use Log;/*** Deletes transactions where the journal has been deleted.@@ -78,7 +79,11 @@ class DeleteOrphanedTransactions extends Command// delete journals$journal = TransactionJournal::find((int)$transaction->transaction_journal_id);if ($journal) {- $journal->delete();+ try {+ $journal->delete();+ } catch (Exception $e) {+ Log::info(sprintf('Could not delete transaction %s', $e->getMessage()));+ }}Transaction::where('transaction_journal_id', (int)$transaction->transaction_journal_id)->delete();$this->line(diff --git a/app/Console/Commands/DecryptDatabase.php b/app/Console/Commands/DecryptDatabase.phpindex 5885712bc2..21cd995db6 100644--- a/app/Console/Commands/DecryptDatabase.php+++ b/app/Console/Commands/DecryptDatabase.php@@ -28,7 +28,6 @@ use Crypt;use DB;use FireflyIII\Exceptions\FireflyException;use FireflyIII\Models\Preference;-use FireflyIII\Support\Facades\FireflyConfig;use Illuminate\Console\Command;use Illuminate\Contracts\Encryption\DecryptException;use Log;@@ -56,6 +55,7 @@ class DecryptDatabase extends Command* Execute the console command.** @return mixed+ * @throws FireflyException*/public function handle(){@@ -113,7 +113,7 @@ class DecryptDatabase extends Command$this->line(sprintf('Decrypted the data in table "%s".', $table));// mark as decrypted:$configName = sprintf('is_decrypted_%s', $table);- FireflyConfig::set($configName, true);+ app('fireflyconfig')->set($configName, true);}$this->info('Done!');@@ -129,7 +129,7 @@ class DecryptDatabase extends Commandprivate function isDecrypted(string $table): bool{$configName = sprintf('is_decrypted_%s', $table);- $configVar = FireflyConfig::get($configName, false);+ $configVar = app('fireflyconfig')->get($configName, false);if (null !== $configVar) {return (bool)$configVar->data;}@@ -139,9 +139,11 @@ class DecryptDatabase extends Command/**- * @param $value+ * Tries to decrypt data. Will only throw an exception when the MAC is invalid.*- * @return mixed+ * @param $value+ * @return string+ * @throws FireflyException*/private function tryDecrypt($value){diff --git a/app/Console/Commands/ScanAttachments.php b/app/Console/Commands/ScanAttachments.phpindex 034a1c2fa3..d6218c2f7e 100644--- a/app/Console/Commands/ScanAttachments.php+++ b/app/Console/Commands/ScanAttachments.php@@ -75,10 +75,10 @@ class ScanAttachments extends Command$this->error(sprintf('Could not decrypt data of attachment #%d: %s', $attachment->id, $e->getMessage()));continue;}- $tmpfname = tempnam(sys_get_temp_dir(), 'FireflyIII');- file_put_contents($tmpfname, $decrypted);- $md5 = md5_file($tmpfname);- $mime = mime_content_type($tmpfname);+ $tempFileName = tempnam(sys_get_temp_dir(), 'FireflyIII');+ file_put_contents($tempFileName, $decrypted);+ $md5 = md5_file($tempFileName);+ $mime = mime_content_type($tempFileName);$attachment->md5 = $md5;$attachment->mime = $mime;$attachment->save();diff --git a/app/Console/Commands/Tools/ApplyRules.php b/app/Console/Commands/Tools/ApplyRules.phpindex de22ed46fc..6e7f92157d 100644--- a/app/Console/Commands/Tools/ApplyRules.php+++ b/app/Console/Commands/Tools/ApplyRules.php@@ -36,7 +36,6 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;use FireflyIII\Repositories\Rule\RuleRepositoryInterface;use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;use FireflyIII\TransactionRules\Engine\RuleEngine;-use FireflyIII\TransactionRules\Processor;use Illuminate\Console\Command;use Illuminate\Support\Collection;use Log;diff --git a/app/Console/Commands/Tools/Cron.php b/app/Console/Commands/Tools/Cron.phpindex 206774f5cb..31926c674a 100644--- a/app/Console/Commands/Tools/Cron.php+++ b/app/Console/Commands/Tools/Cron.php@@ -24,6 +24,7 @@ declare(strict_types=1);namespace FireflyIII\Console\Commands\Tools;+use Exception;use FireflyIII\Exceptions\FireflyException;use FireflyIII\Support\Cronjobs\RecurringCronjob;use Illuminate\Console\Command;@@ -52,9 +53,8 @@ class Cron extends Command';/**- * Execute the console command.- *- * @return mixed+ * @return int+ * @throws Exception*/public function handle(): int{diff --git a/app/Console/Commands/Upgrade/BackToJournals.php b/app/Console/Commands/Upgrade/BackToJournals.phpindex d435eac012..35ee45512d 100644--- a/app/Console/Commands/Upgrade/BackToJournals.php+++ b/app/Console/Commands/Upgrade/BackToJournals.php@@ -151,7 +151,7 @@ class BackToJournals extends Command{$journalIds = $this->getIdsForBudgets();$journals = TransactionJournal::whereIn('id', $journalIds)->with(['transactions', 'budgets', 'transactions.budgets'])->get();- $this->line(sprintf('Check %d transaction journals for budget info.', $journals->count()));+ $this->line(sprintf('Check %d transaction journals for budget info.',count($journals)));/** @var TransactionJournal $journal */foreach ($journals as $journal) {$this->migrateBudgetsForJournal($journal);@@ -193,7 +193,7 @@ class BackToJournals extends Command{$journalIds = $this->getIdsForCategories();$journals = TransactionJournal::whereIn('id', $journalIds)->with(['transactions', 'categories', 'transactions.categories'])->get();- $this->line(sprintf('Check %d transaction journals for category info.', $journals->count()));+ $this->line(sprintf('Check %d transaction journals for category info.', count($journals)));/** @var TransactionJournal $journal */foreach ($journals as $journal) {$this->migrateCategoriesForJournal($journal);diff --git a/app/Console/Commands/Upgrade/JournalCurrencies.php b/app/Console/Commands/Upgrade/JournalCurrencies.phpindex eae5df4aad..df4cbaa9fd 100644--- a/app/Console/Commands/Upgrade/JournalCurrencies.php+++ b/app/Console/Commands/Upgrade/JournalCurrencies.php@@ -279,7 +279,9 @@ class JournalCurrencies extends Command* @SuppressWarnings(PHPMD.ExcessiveMethodLength)* @SuppressWarnings(PHPMD.NPathComplexity)*- * @param Transaction $transaction+ * @param TransactionJournal $journal+ * @param Transaction $source+ * @param Transaction $destination*/private function updateTransactionCurrency(TransactionJournal $journal, Transaction $source, Transaction $destination): void{diff --git a/app/Console/Commands/Upgrade/TransactionIdentifier.php b/app/Console/Commands/Upgrade/TransactionIdentifier.phpindex 7fdc561c00..c08651c06b 100644--- a/app/Console/Commands/Upgrade/TransactionIdentifier.php+++ b/app/Console/Commands/Upgrade/TransactionIdentifier.php@@ -85,7 +85,7 @@ class TransactionIdentifier extends Command$journalIds = array_unique($result->pluck('id')->toArray());$count= 0;foreach ($journalIds as $journalId) {- $this->updateJournalidentifiers((int)$journalId);+ $this->updateJournalIdentifiers((int)$journalId);$count++;}$end = round(microtime(true) - $start, 2);@@ -117,12 +117,12 @@ class TransactionIdentifier extends Command}/**- * grab all positive transactiosn from this journal that are not deleted. for each one, grab the negative opposing one+ * grab all positive transactions from this journal that are not deleted. for each one, grab the negative opposing one* which has 0 as an identifier and give it the same identifier.** @param int $journalId*/- private function updateJournalidentifiers(int $journalId): void+ private function updateJournalIdentifiers(int $journalId): void{$identifier = 0;$processed = [];diff --git a/app/Console/Kernel.php b/app/Console/Kernel.phpindex 9ede16c879..161cd3b48f 100644--- a/app/Console/Kernel.php+++ b/app/Console/Kernel.php@@ -49,7 +49,7 @@ class Kernel extends ConsoleKernel/*** Define the application's command schedule.*- * @param \Illuminate\Console\Scheduling\Schedule $schedule+ * @param Schedule $schedule*/protected function schedule(Schedule $schedule): void{diff --git a/app/Events/RequestedReportOnJournals.php b/app/Events/RequestedReportOnJournals.phpindex 4b869ee173..23e5e7c26c 100644--- a/app/Events/RequestedReportOnJournals.php+++ b/app/Events/RequestedReportOnJournals.php@@ -43,6 +43,7 @@ declare(strict_types=1);namespace FireflyIII\Events;+use Illuminate\Broadcasting\Channel;use Illuminate\Broadcasting\InteractsWithSockets;use Illuminate\Broadcasting\PrivateChannel;use Illuminate\Foundation\Events\Dispatchable;@@ -80,7 +81,7 @@ class RequestedReportOnJournals/*** Get the channels the event should broadcast on.*- * @return \Illuminate\Broadcasting\Channel|array+ * @return Channel|array*/public function broadcastOn(){diff --git a/app/Events/StoredTransactionGroup.php b/app/Events/StoredTransactionGroup.phpindex e473b7d487..e558dd4d36 100644--- a/app/Events/StoredTransactionGroup.php+++ b/app/Events/StoredTransactionGroup.php@@ -45,6 +45,7 @@ class StoredTransactionGroup extends Event* Create a new event instance.** @param TransactionGroup $transactionGroup+ * @param bool $applyRules*/public function __construct(TransactionGroup $transactionGroup, bool $applyRules = true){diff --git a/app/Events/UpdatedTransactionGroup.php b/app/Events/UpdatedTransactionGroup.phpindex 8d1c3ff647..af12194b17 100644--- a/app/Events/UpdatedTransactionGroup.php+++ b/app/Events/UpdatedTransactionGroup.php@@ -25,7 +25,6 @@ declare(strict_types=1);namespace FireflyIII\Events;use FireflyIII\Models\TransactionGroup;-use FireflyIII\Models\TransactionJournal;use Illuminate\Queue\SerializesModels;/**diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.phpindex 5d2cdb2426..969defaede 100644--- a/app/Exceptions/Handler.php+++ b/app/Exceptions/Handler.php@@ -81,7 +81,7 @@ class Handler extends ExceptionHandlerreturn response()->json(['message' => $exception->getMessage(),- 'exception' => \get_class($exception),+ 'exception' => get_class($exception),'line' => $exception->getLine(),'file' => $exception->getFile(),'trace' => $exception->getTrace(),@@ -89,7 +89,7 @@ class Handler extends ExceptionHandler);}- return response()->json(['message' => 'Internal Firefly III Exception. See log files.', 'exception' => \get_class($exception)], 500);+ return response()->json(['message' => 'Internal Firefly III Exception. See log files.', 'exception' => get_class($exception)], 500);}if ($exception instanceof FireflyException || $exception instanceof ErrorException || $exception instanceof OAuthServerException) {@@ -104,11 +104,11 @@ class Handler extends ExceptionHandler/*** Report or log an exception.*- * This is a great spot to send exceptions to Sentry, Bugsnag, etc.+ * This is a great spot to send exceptions to Sentry etc.** @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's five its fine.*- * @param \Exception $exception+ * @param Exception $exception** @return mixed|void*@@ -131,7 +131,7 @@ class Handler extends ExceptionHandler$userData['email'] = auth()->user()->email;}$data = [- 'class' => \get_class($exception),+ 'class' => get_class($exception),'errorMessage' => $exception->getMessage(),'time' => date('r'),'stackTrace' => $exception->getTraceAsString(),diff --git a/app/Exceptions/NotImplementedException.php b/app/Exceptions/NotImplementedException.phpindex 7254d56d34..83aa21fbee 100644--- a/app/Exceptions/NotImplementedException.php+++ b/app/Exceptions/NotImplementedException.php@@ -24,9 +24,11 @@ declare(strict_types=1);namespace FireflyIII\Exceptions;+use Exception;+/*** Class NotImplementedException.*/-class NotImplementedException extends \Exception+class NotImplementedException extends Exception{}diff --git a/app/Exceptions/ValidationException.php b/app/Exceptions/ValidationException.phpindex 602b4df9b0..db8c115fd1 100644--- a/app/Exceptions/ValidationException.php+++ b/app/Exceptions/ValidationException.php@@ -24,9 +24,11 @@ declare(strict_types=1);namespace FireflyIII\Exceptions;+use Exception;+/*** Class ValidationExceptions.*/-class ValidationException extends \Exception+class ValidationException extends Exception{}