From 112a27dbd9bab723d389f33c72688e04399287a2 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 27 Apr 2021 06:42:07 +0200 Subject: [PATCH] Clean up some code. --- .../Correction/DeleteEmptyJournals.php | 1 + .../Commands/Correction/FixGroupAccounts.php | 1 + app/Console/Commands/DecryptDatabase.php | 2 +- app/Console/Commands/Export/ExportData.php | 3 +- .../Commands/Upgrade/BackToJournals.php | 3 +- .../Commands/Upgrade/MigrateToGroups.php | 2 +- app/Exceptions/GracefulNotFoundHandler.php | 30 +++++++++---------- app/Factory/TransactionCurrencyFactory.php | 2 +- .../Collector/GroupCollectorInterface.php | 2 -- app/Helpers/Report/ReportHelper.php | 2 +- .../Controllers/Chart/PiggyBankController.php | 2 +- app/Models/Budget.php | 1 + app/Models/Transaction.php | 1 + app/Models/TransactionJournal.php | 1 + 14 files changed, 28 insertions(+), 25 deletions(-) diff --git a/app/Console/Commands/Correction/DeleteEmptyJournals.php b/app/Console/Commands/Correction/DeleteEmptyJournals.php index 7fe3f66778..f73b293a5d 100644 --- a/app/Console/Commands/Correction/DeleteEmptyJournals.php +++ b/app/Console/Commands/Correction/DeleteEmptyJournals.php @@ -71,6 +71,7 @@ class DeleteEmptyJournals extends Command ->groupBy('transactions.transaction_journal_id') ->get([DB::raw('COUNT(transactions.transaction_journal_id) as the_count'), 'transaction_journal_id']); $total = 0; + /** @var Transaction $row */ foreach ($set as $row) { $count = (int)$row->the_count; if (1 === $count % 2) { diff --git a/app/Console/Commands/Correction/FixGroupAccounts.php b/app/Console/Commands/Correction/FixGroupAccounts.php index 9cc6ed924c..7b818ce46e 100644 --- a/app/Console/Commands/Correction/FixGroupAccounts.php +++ b/app/Console/Commands/Correction/FixGroupAccounts.php @@ -60,6 +60,7 @@ class FixGroupAccounts extends Command $res = TransactionJournal ::groupBy('transaction_group_id') ->get(['transaction_group_id', DB::raw('COUNT(transaction_group_id) as the_count')]); + /** @var TransactionJournal $journal */ foreach ($res as $journal) { if ((int)$journal->the_count > 1) { $groups[] = (int)$journal->transaction_group_id; diff --git a/app/Console/Commands/DecryptDatabase.php b/app/Console/Commands/DecryptDatabase.php index a9e8cfb548..60897032f4 100644 --- a/app/Console/Commands/DecryptDatabase.php +++ b/app/Console/Commands/DecryptDatabase.php @@ -177,7 +177,7 @@ class DecryptDatabase extends Command /** * Tries to decrypt data. Will only throw an exception when the MAC is invalid. * - * @param $value + * @param mixed $value * * @return string * @throws FireflyException diff --git a/app/Console/Commands/Export/ExportData.php b/app/Console/Commands/Export/ExportData.php index 18e81c4005..5c39b6e861 100644 --- a/app/Console/Commands/Export/ExportData.php +++ b/app/Console/Commands/Export/ExportData.php @@ -28,6 +28,7 @@ use Carbon\Carbon; use Exception; use FireflyIII\Console\Commands\VerifiesAccessToken; use FireflyIII\Exceptions\FireflyException; +use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; @@ -241,7 +242,7 @@ class ExportData extends Command $accounts = $this->accountRepository->getAccountsByType($types); } // filter accounts, - /** @var AccountType $account */ + /** @var Account $account */ foreach ($accounts as $account) { if (in_array($account->accountType->type, $types, true)) { $final->push($account); diff --git a/app/Console/Commands/Upgrade/BackToJournals.php b/app/Console/Commands/Upgrade/BackToJournals.php index 10522e030c..4de0bd1eed 100644 --- a/app/Console/Commands/Upgrade/BackToJournals.php +++ b/app/Console/Commands/Upgrade/BackToJournals.php @@ -144,8 +144,7 @@ class BackToJournals extends Command $chunks = array_chunk($transactions, 500); foreach ($chunks as $chunk) { - $set = DB::table('transactions')->whereIn('transactions.id', $chunk) - ->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray(); + $set = DB::table('transactions')->whereIn('transactions.id', $chunk)->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray(); $array = array_merge($array, $set); } diff --git a/app/Console/Commands/Upgrade/MigrateToGroups.php b/app/Console/Commands/Upgrade/MigrateToGroups.php index 7511eac1ff..8b2e0f3993 100644 --- a/app/Console/Commands/Upgrade/MigrateToGroups.php +++ b/app/Console/Commands/Upgrade/MigrateToGroups.php @@ -414,7 +414,7 @@ class MigrateToGroups extends Command if ($total > 0) { Log::debug(sprintf('Going to convert %d transaction journals. Please hold..', $total)); $this->line(sprintf('Going to convert %d transaction journals. Please hold..', $total)); - /** @var array $journal */ + /** @var array $array */ foreach ($orphanedJournals as $array) { $this->giveGroup($array); } diff --git a/app/Exceptions/GracefulNotFoundHandler.php b/app/Exceptions/GracefulNotFoundHandler.php index c87c4a5327..7a95a5c978 100644 --- a/app/Exceptions/GracefulNotFoundHandler.php +++ b/app/Exceptions/GracefulNotFoundHandler.php @@ -48,38 +48,38 @@ class GracefulNotFoundHandler extends ExceptionHandler * Render an exception into an HTTP response. * * @param Request $request - * @param Exception $exception + * @param Throwable $e * * @return mixed - * @throws Exception + * @throws Throwable */ - public function render($request, Throwable $exception) + public function render($request, Throwable $e) { $route = $request->route(); if (null === $route) { - return parent::render($request, $exception); + return parent::render($request, $e); } $name = $route->getName(); if (!auth()->check()) { - return parent::render($request, $exception); + return parent::render($request, $e); } switch ($name) { default: Log::warning(sprintf('GracefulNotFoundHandler cannot handle route with name "%s"', $name)); - return parent::render($request, $exception); + return parent::render($request, $e); case 'accounts.show': case 'accounts.show.all': - return $this->handleAccount($request, $exception); + return $this->handleAccount($request, $e); case 'transactions.show': - return $this->handleGroup($request, $exception); + return $this->handleGroup($request, $e); case 'attachments.show': case 'attachments.edit': case 'attachments.download': case 'attachments.view': // redirect to original attachment holder. - return $this->handleAttachment($request, $exception); + return $this->handleAttachment($request, $e); break; case 'bills.show': $request->session()->reflash(); @@ -131,7 +131,7 @@ class GracefulNotFoundHandler extends ExceptionHandler return redirect(route('index')); } - return parent::render($request, $exception); + return parent::render($request, $e); } } @@ -141,7 +141,7 @@ class GracefulNotFoundHandler extends ExceptionHandler * @param Throwable $exception * * @return Redirector|Response - * @throws Exception + * @throws Throwable */ private function handleAccount(Request $request, Throwable $exception) { @@ -165,11 +165,11 @@ class GracefulNotFoundHandler extends ExceptionHandler } /** - * @param Throwable $request - * @param Exception $exception + * @param Request $request + * @param Throwable $exception * * @return RedirectResponse|\Illuminate\Http\Response|Redirector|Response - * @throws Exception + * @throws Throwable */ private function handleGroup(Request $request, Throwable $exception) { @@ -209,7 +209,7 @@ class GracefulNotFoundHandler extends ExceptionHandler * @param Throwable $exception * * @return RedirectResponse|Redirector|Response - * @throws Exception + * @throws Throwable */ private function handleAttachment(Request $request, Throwable $exception) { diff --git a/app/Factory/TransactionCurrencyFactory.php b/app/Factory/TransactionCurrencyFactory.php index ba769f5338..e8aa313844 100644 --- a/app/Factory/TransactionCurrencyFactory.php +++ b/app/Factory/TransactionCurrencyFactory.php @@ -46,7 +46,7 @@ class TransactionCurrencyFactory public function create(array $data): TransactionCurrency { try { - /** @var TransactionCurrency $currency */ + /** @var TransactionCurrency $result */ $result = TransactionCurrency::create( [ 'name' => $data['name'], diff --git a/app/Helpers/Collector/GroupCollectorInterface.php b/app/Helpers/Collector/GroupCollectorInterface.php index 64354d5f6d..380a7598b7 100644 --- a/app/Helpers/Collector/GroupCollectorInterface.php +++ b/app/Helpers/Collector/GroupCollectorInterface.php @@ -549,8 +549,6 @@ interface GroupCollectorInterface public function withoutCategory(): GroupCollectorInterface; /** - * @param string $value - * * @return GroupCollectorInterface */ public function withoutNotes(): GroupCollectorInterface; diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php index 5deebb3292..0c2c2b5e15 100644 --- a/app/Helpers/Report/ReportHelper.php +++ b/app/Helpers/Report/ReportHelper.php @@ -91,7 +91,7 @@ class ReportHelper implements ReportHelperInterface 'paid_moments' => [], ]; - /** @var Carbon $start */ + /** @var Carbon $expectedStart */ foreach ($expectedDates as $expectedStart) { $expectedEnd = app('navigation')->endOfX($expectedStart, $bill->repeat_freq, null); diff --git a/app/Http/Controllers/Chart/PiggyBankController.php b/app/Http/Controllers/Chart/PiggyBankController.php index c79cbe27e0..3bf3218e97 100644 --- a/app/Http/Controllers/Chart/PiggyBankController.php +++ b/app/Http/Controllers/Chart/PiggyBankController.php @@ -82,7 +82,7 @@ class PiggyBankController extends Controller // get first event or start date of piggy bank or today $startDate = $piggyBank->startdate ?? today(config('app.timezone')); - /** @var PiggyBankEvent $first */ + /** @var PiggyBankEvent $firstEvent */ $firstEvent = $set->first(); $firstDate = null === $firstEvent ? new Carbon : $firstEvent->date; diff --git a/app/Models/Budget.php b/app/Models/Budget.php index d5a48c2f5a..c0ed5391a6 100644 --- a/app/Models/Budget.php +++ b/app/Models/Budget.php @@ -74,6 +74,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @method static Builder|Budget withTrashed() * @method static Builder|Budget withoutTrashed() * @mixin Eloquent + * @property string $email */ class Budget extends Model { diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index 418a673d00..b20f7b47d2 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -83,6 +83,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @method static \Illuminate\Database\Query\Builder|Transaction withTrashed() * @method static \Illuminate\Database\Query\Builder|Transaction withoutTrashed() * @mixin Eloquent + * @property int $the_count */ class Transaction extends Model { diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index 0b63f2e1df..5c95f267c8 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -114,6 +114,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @mixin Eloquent * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Location[] $locations * @property-read int|null $locations_count + * @property int $the_count */ class TransactionJournal extends Model {