Clean up some code.

This commit is contained in:
James Cole
2021-04-27 06:42:07 +02:00
parent 366eca3173
commit 112a27dbd9
14 changed files with 28 additions and 25 deletions

View File

@@ -71,6 +71,7 @@ class DeleteEmptyJournals extends Command
->groupBy('transactions.transaction_journal_id') ->groupBy('transactions.transaction_journal_id')
->get([DB::raw('COUNT(transactions.transaction_journal_id) as the_count'), 'transaction_journal_id']); ->get([DB::raw('COUNT(transactions.transaction_journal_id) as the_count'), 'transaction_journal_id']);
$total = 0; $total = 0;
/** @var Transaction $row */
foreach ($set as $row) { foreach ($set as $row) {
$count = (int)$row->the_count; $count = (int)$row->the_count;
if (1 === $count % 2) { if (1 === $count % 2) {

View File

@@ -60,6 +60,7 @@ class FixGroupAccounts extends Command
$res = TransactionJournal $res = TransactionJournal
::groupBy('transaction_group_id') ::groupBy('transaction_group_id')
->get(['transaction_group_id', DB::raw('COUNT(transaction_group_id) as the_count')]); ->get(['transaction_group_id', DB::raw('COUNT(transaction_group_id) as the_count')]);
/** @var TransactionJournal $journal */
foreach ($res as $journal) { foreach ($res as $journal) {
if ((int)$journal->the_count > 1) { if ((int)$journal->the_count > 1) {
$groups[] = (int)$journal->transaction_group_id; $groups[] = (int)$journal->transaction_group_id;

View File

@@ -177,7 +177,7 @@ class DecryptDatabase extends Command
/** /**
* Tries to decrypt data. Will only throw an exception when the MAC is invalid. * Tries to decrypt data. Will only throw an exception when the MAC is invalid.
* *
* @param $value * @param mixed $value
* *
* @return string * @return string
* @throws FireflyException * @throws FireflyException

View File

@@ -28,6 +28,7 @@ use Carbon\Carbon;
use Exception; use Exception;
use FireflyIII\Console\Commands\VerifiesAccessToken; use FireflyIII\Console\Commands\VerifiesAccessToken;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
@@ -241,7 +242,7 @@ class ExportData extends Command
$accounts = $this->accountRepository->getAccountsByType($types); $accounts = $this->accountRepository->getAccountsByType($types);
} }
// filter accounts, // filter accounts,
/** @var AccountType $account */ /** @var Account $account */
foreach ($accounts as $account) { foreach ($accounts as $account) {
if (in_array($account->accountType->type, $types, true)) { if (in_array($account->accountType->type, $types, true)) {
$final->push($account); $final->push($account);

View File

@@ -144,8 +144,7 @@ class BackToJournals extends Command
$chunks = array_chunk($transactions, 500); $chunks = array_chunk($transactions, 500);
foreach ($chunks as $chunk) { foreach ($chunks as $chunk) {
$set = DB::table('transactions')->whereIn('transactions.id', $chunk) $set = DB::table('transactions')->whereIn('transactions.id', $chunk)->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray();
->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray();
$array = array_merge($array, $set); $array = array_merge($array, $set);
} }

View File

@@ -414,7 +414,7 @@ class MigrateToGroups extends Command
if ($total > 0) { if ($total > 0) {
Log::debug(sprintf('Going to convert %d transaction journals. Please hold..', $total)); Log::debug(sprintf('Going to convert %d transaction journals. Please hold..', $total));
$this->line(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) { foreach ($orphanedJournals as $array) {
$this->giveGroup($array); $this->giveGroup($array);
} }

View File

@@ -48,38 +48,38 @@ class GracefulNotFoundHandler extends ExceptionHandler
* Render an exception into an HTTP response. * Render an exception into an HTTP response.
* *
* @param Request $request * @param Request $request
* @param Exception $exception * @param Throwable $e
* *
* @return mixed * @return mixed
* @throws Exception * @throws Throwable
*/ */
public function render($request, Throwable $exception) public function render($request, Throwable $e)
{ {
$route = $request->route(); $route = $request->route();
if (null === $route) { if (null === $route) {
return parent::render($request, $exception); return parent::render($request, $e);
} }
$name = $route->getName(); $name = $route->getName();
if (!auth()->check()) { if (!auth()->check()) {
return parent::render($request, $exception); return parent::render($request, $e);
} }
switch ($name) { switch ($name) {
default: default:
Log::warning(sprintf('GracefulNotFoundHandler cannot handle route with name "%s"', $name)); 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':
case 'accounts.show.all': case 'accounts.show.all':
return $this->handleAccount($request, $exception); return $this->handleAccount($request, $e);
case 'transactions.show': case 'transactions.show':
return $this->handleGroup($request, $exception); return $this->handleGroup($request, $e);
case 'attachments.show': case 'attachments.show':
case 'attachments.edit': case 'attachments.edit':
case 'attachments.download': case 'attachments.download':
case 'attachments.view': case 'attachments.view':
// redirect to original attachment holder. // redirect to original attachment holder.
return $this->handleAttachment($request, $exception); return $this->handleAttachment($request, $e);
break; break;
case 'bills.show': case 'bills.show':
$request->session()->reflash(); $request->session()->reflash();
@@ -131,7 +131,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
return redirect(route('index')); 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 * @param Throwable $exception
* *
* @return Redirector|Response * @return Redirector|Response
* @throws Exception * @throws Throwable
*/ */
private function handleAccount(Request $request, Throwable $exception) private function handleAccount(Request $request, Throwable $exception)
{ {
@@ -165,11 +165,11 @@ class GracefulNotFoundHandler extends ExceptionHandler
} }
/** /**
* @param Throwable $request * @param Request $request
* @param Exception $exception * @param Throwable $exception
* *
* @return RedirectResponse|\Illuminate\Http\Response|Redirector|Response * @return RedirectResponse|\Illuminate\Http\Response|Redirector|Response
* @throws Exception * @throws Throwable
*/ */
private function handleGroup(Request $request, Throwable $exception) private function handleGroup(Request $request, Throwable $exception)
{ {
@@ -209,7 +209,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
* @param Throwable $exception * @param Throwable $exception
* *
* @return RedirectResponse|Redirector|Response * @return RedirectResponse|Redirector|Response
* @throws Exception * @throws Throwable
*/ */
private function handleAttachment(Request $request, Throwable $exception) private function handleAttachment(Request $request, Throwable $exception)
{ {

View File

@@ -46,7 +46,7 @@ class TransactionCurrencyFactory
public function create(array $data): TransactionCurrency public function create(array $data): TransactionCurrency
{ {
try { try {
/** @var TransactionCurrency $currency */ /** @var TransactionCurrency $result */
$result = TransactionCurrency::create( $result = TransactionCurrency::create(
[ [
'name' => $data['name'], 'name' => $data['name'],

View File

@@ -549,8 +549,6 @@ interface GroupCollectorInterface
public function withoutCategory(): GroupCollectorInterface; public function withoutCategory(): GroupCollectorInterface;
/** /**
* @param string $value
*
* @return GroupCollectorInterface * @return GroupCollectorInterface
*/ */
public function withoutNotes(): GroupCollectorInterface; public function withoutNotes(): GroupCollectorInterface;

View File

@@ -91,7 +91,7 @@ class ReportHelper implements ReportHelperInterface
'paid_moments' => [], 'paid_moments' => [],
]; ];
/** @var Carbon $start */ /** @var Carbon $expectedStart */
foreach ($expectedDates as $expectedStart) { foreach ($expectedDates as $expectedStart) {
$expectedEnd = app('navigation')->endOfX($expectedStart, $bill->repeat_freq, null); $expectedEnd = app('navigation')->endOfX($expectedStart, $bill->repeat_freq, null);

View File

@@ -82,7 +82,7 @@ class PiggyBankController extends Controller
// get first event or start date of piggy bank or today // get first event or start date of piggy bank or today
$startDate = $piggyBank->startdate ?? today(config('app.timezone')); $startDate = $piggyBank->startdate ?? today(config('app.timezone'));
/** @var PiggyBankEvent $first */ /** @var PiggyBankEvent $firstEvent */
$firstEvent = $set->first(); $firstEvent = $set->first();
$firstDate = null === $firstEvent ? new Carbon : $firstEvent->date; $firstDate = null === $firstEvent ? new Carbon : $firstEvent->date;

View File

@@ -74,6 +74,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @method static Builder|Budget withTrashed() * @method static Builder|Budget withTrashed()
* @method static Builder|Budget withoutTrashed() * @method static Builder|Budget withoutTrashed()
* @mixin Eloquent * @mixin Eloquent
* @property string $email
*/ */
class Budget extends Model class Budget extends Model
{ {

View File

@@ -83,6 +83,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @method static \Illuminate\Database\Query\Builder|Transaction withTrashed() * @method static \Illuminate\Database\Query\Builder|Transaction withTrashed()
* @method static \Illuminate\Database\Query\Builder|Transaction withoutTrashed() * @method static \Illuminate\Database\Query\Builder|Transaction withoutTrashed()
* @mixin Eloquent * @mixin Eloquent
* @property int $the_count
*/ */
class Transaction extends Model class Transaction extends Model
{ {

View File

@@ -114,6 +114,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @mixin Eloquent * @mixin Eloquent
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Location[] $locations * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Location[] $locations
* @property-read int|null $locations_count * @property-read int|null $locations_count
* @property int $the_count
*/ */
class TransactionJournal extends Model class TransactionJournal extends Model
{ {