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

@@ -28,7 +28,6 @@ use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
@@ -38,7 +37,6 @@ use Illuminate\Http\JsonResponse;
class DestroyController extends Controller class DestroyController extends Controller
{ {
private CurrencyRepositoryInterface $repository; private CurrencyRepositoryInterface $repository;
private UserRepositoryInterface $userRepository;
/** /**
* CurrencyRepository constructor. * CurrencyRepository constructor.
@@ -50,8 +48,7 @@ class DestroyController extends Controller
parent::__construct(); parent::__construct();
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
$this->repository = app(CurrencyRepositoryInterface::class); $this->repository = app(CurrencyRepositoryInterface::class);
$this->userRepository = app(UserRepositoryInterface::class);
$this->repository->setUser(auth()->user()); $this->repository->setUser(auth()->user());
return $next($request); return $next($request);

View File

@@ -67,8 +67,6 @@ class ListController extends Controller
use TransactionFilter; use TransactionFilter;
private CurrencyRepositoryInterface $repository; private CurrencyRepositoryInterface $repository;
private UserRepositoryInterface $userRepository;
/** /**
* CurrencyRepository constructor. * CurrencyRepository constructor.
* *
@@ -80,7 +78,6 @@ class ListController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
$this->repository = app(CurrencyRepositoryInterface::class); $this->repository = app(CurrencyRepositoryInterface::class);
$this->userRepository = app(UserRepositoryInterface::class);
$this->repository->setUser(auth()->user()); $this->repository->setUser(auth()->user());
return $next($request); return $next($request);

View File

@@ -28,7 +28,6 @@ use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\TransactionCurrency\StoreRequest; use FireflyIII\Api\V1\Requests\Models\TransactionCurrency\StoreRequest;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Support\Http\Api\AccountFilter; use FireflyIII\Support\Http\Api\AccountFilter;
use FireflyIII\Support\Http\Api\TransactionFilter; use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Transformers\CurrencyTransformer; use FireflyIII\Transformers\CurrencyTransformer;
@@ -45,7 +44,6 @@ class StoreController extends Controller
use TransactionFilter; use TransactionFilter;
private CurrencyRepositoryInterface $repository; private CurrencyRepositoryInterface $repository;
private UserRepositoryInterface $userRepository;
/** /**
* CurrencyRepository constructor. * CurrencyRepository constructor.
@@ -57,8 +55,7 @@ class StoreController extends Controller
parent::__construct(); parent::__construct();
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
$this->repository = app(CurrencyRepositoryInterface::class); $this->repository = app(CurrencyRepositoryInterface::class);
$this->userRepository = app(UserRepositoryInterface::class);
$this->repository->setUser(auth()->user()); $this->repository->setUser(auth()->user());
return $next($request); return $next($request);

View File

@@ -46,7 +46,6 @@ class UpdateController extends Controller
use TransactionFilter; use TransactionFilter;
private CurrencyRepositoryInterface $repository; private CurrencyRepositoryInterface $repository;
private UserRepositoryInterface $userRepository;
/** /**
* CurrencyRepository constructor. * CurrencyRepository constructor.
@@ -58,8 +57,7 @@ class UpdateController extends Controller
parent::__construct(); parent::__construct();
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
$this->repository = app(CurrencyRepositoryInterface::class); $this->repository = app(CurrencyRepositoryInterface::class);
$this->userRepository = app(UserRepositoryInterface::class);
$this->repository->setUser(auth()->user()); $this->repository->setUser(auth()->user());
return $next($request); return $next($request);

View File

@@ -46,7 +46,6 @@ class ListController extends Controller
use TransactionFilter; use TransactionFilter;
private LinkTypeRepositoryInterface $repository; private LinkTypeRepositoryInterface $repository;
private UserRepositoryInterface $userRepository;
/** /**
* LinkTypeController constructor. * LinkTypeController constructor.
@@ -61,7 +60,6 @@ class ListController extends Controller
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
$this->repository = app(LinkTypeRepositoryInterface::class); $this->repository = app(LinkTypeRepositoryInterface::class);
$this->userRepository = app(UserRepositoryInterface::class);
$this->repository->setUser($user); $this->repository->setUser($user);
return $next($request); return $next($request);

View File

@@ -46,7 +46,6 @@ class ShowController extends Controller
use TransactionFilter; use TransactionFilter;
private LinkTypeRepositoryInterface $repository; private LinkTypeRepositoryInterface $repository;
private UserRepositoryInterface $userRepository;
/** /**
* LinkTypeController constructor. * LinkTypeController constructor.
@@ -61,7 +60,6 @@ class ShowController extends Controller
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
$this->repository = app(LinkTypeRepositoryInterface::class); $this->repository = app(LinkTypeRepositoryInterface::class);
$this->userRepository = app(UserRepositoryInterface::class);
$this->repository->setUser($user); $this->repository->setUser($user);
return $next($request); return $next($request);

View File

@@ -96,7 +96,7 @@ class UserUpdateRequest extends FormRequest
*/ */
public function withValidator(Validator $validator): void public function withValidator(Validator $validator): void
{ {
/** @var User $current */ /** @var User|null $current */
$current = $this->route()->parameter('user'); $current = $this->route()->parameter('user');
$validator->after( $validator->after(
static function (Validator $validator) use ($current) { static function (Validator $validator) use ($current) {

View File

@@ -38,7 +38,6 @@ class NetWorthController extends Controller
use ConvertsExchangeRates; use ConvertsExchangeRates;
private NetWorthInterface $netWorth; private NetWorthInterface $netWorth;
private AccountRepositoryInterface $repository;
/** /**
* *
@@ -48,7 +47,6 @@ class NetWorthController extends Controller
parent::__construct(); parent::__construct();
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
$this->repository = app(AccountRepositoryInterface::class);
$this->netWorth = app(NetWorthInterface::class); $this->netWorth = app(NetWorthInterface::class);
$this->netWorth->setUser(auth()->user()); $this->netWorth->setUser(auth()->user());
return $next($request); return $next($request);

View File

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

View File

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

View File

@@ -146,6 +146,7 @@ class FixTransactionTypes extends Command
} }
/** @var Transaction $transaction */ /** @var Transaction $transaction */
$transaction = $collection->first(); $transaction = $collection->first();
/** @var Account|null $account */
$account = $transaction->account; $account = $transaction->account;
if (null === $account) { if (null === $account) {
throw new FireflyException(sprintf('Journal #%d, transaction #%d has no source account.', $journal->id, $transaction->id)); 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 */ /** @var Transaction $transaction */
$transaction = $collection->first(); $transaction = $collection->first();
/** @var Account|null $account */
$account = $transaction->account; $account = $transaction->account;
if (null === $account) { if (null === $account) {
throw new FireflyException(sprintf('Journal #%d, transaction #%d has no destination account.', $journal->id, $transaction->id)); 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) { if (!$journal) {
return; return;
} }
/** @var Transaction $source */ /** @var Transaction|null $source */
$source = $journal->transactions()->where('amount', '<', 0)->first(); $source = $journal->transactions()->where('amount', '<', 0)->first();
if (null === $source) { if (null === $source) {
@@ -113,7 +113,7 @@ class FixUnevenAmount extends Command
$amount = bcmul('-1', (string)$source->amount); $amount = bcmul('-1', (string)$source->amount);
// fix amount of destination: // fix amount of destination:
/** @var Transaction $destination */ /** @var Transaction|null $destination */
$destination = $journal->transactions()->where('amount', '>', 0)->first(); $destination = $journal->transactions()->where('amount', '>', 0)->first();
if (null === $destination) { if (null === $destination) {

View File

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

View File

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

View File

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

View File

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

View File

@@ -351,7 +351,7 @@ class MigrateToGroups extends Command
Log::debug('Now in getTransactionBudget()'); Log::debug('Now in getTransactionBudget()');
// try to get a budget ID from the left transaction: // try to get a budget ID from the left transaction:
/** @var Budget $budget */ /** @var Budget|null $budget */
$budget = $left->budgets()->first(); $budget = $left->budgets()->first();
if (null !== $budget) { if (null !== $budget) {
Log::debug(sprintf('Return budget #%d, from transaction #%d', $budget->id, $left->id)); 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: // try to get a budget ID from the right transaction:
/** @var Budget $budget */ /** @var Budget|null $budget */
$budget = $right->budgets()->first(); $budget = $right->budgets()->first();
if (null !== $budget) { if (null !== $budget) {
Log::debug(sprintf('Return budget #%d, from transaction #%d', $budget->id, $right->id)); 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()'); Log::debug('Now in getTransactionCategory()');
// try to get a category ID from the left transaction: // try to get a category ID from the left transaction:
/** @var Category $category */ /** @var Category|null $category */
$category = $left->categories()->first(); $category = $left->categories()->first();
if (null !== $category) { if (null !== $category) {
Log::debug(sprintf('Return category #%d, from transaction #%d', $category->id, $left->id)); 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: // try to get a category ID from the left transaction:
/** @var Category $category */ /** @var Category|null $category */
$category = $right->categories()->first(); $category = $right->categories()->first();
if (null !== $category) { if (null !== $category) {
Log::debug(sprintf('Return category #%d, from transaction #%d', $category->id, $category->id)); 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; private $cliRepository;
/** @var int */ /** @var int */
private $count; 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 * 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 private function stupidLaravel(): void
{ {
$this->journalRepository = app(JournalRepositoryInterface::class);
$this->cliRepository = app(JournalCLIRepositoryInterface::class); $this->cliRepository = app(JournalCLIRepositoryInterface::class);
$this->count = 0; $this->count = 0;
} }

View File

@@ -33,7 +33,7 @@ class DestroyedTransactionLink extends Event
{ {
use SerializesModels; use SerializesModels;
private TransactionJournalLink $link; private TransactionJournalLink $link; /// @phpstan-ignore-line PHPStan thinks this property is never read.
/** /**
* DestroyedTransactionLink constructor. * DestroyedTransactionLink constructor.

View File

@@ -138,7 +138,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
* @param Request $request * @param Request $request
* @param Throwable $exception * @param Throwable $exception
* *
* @return Redirector|Response * @return Response
* @throws Throwable * @throws Throwable
*/ */
private function handleAccount(Request $request, Throwable $exception) private function handleAccount(Request $request, Throwable $exception)
@@ -154,7 +154,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
if (!($param instanceof Account)) { if (!($param instanceof Account)) {
$accountId = (int)$param; $accountId = (int)$param;
} }
/** @var Account $account */ /** @var Account|null $account */
$account = $user->accounts()->with(['accountType'])->withTrashed()->find($accountId); $account = $user->accounts()->with(['accountType'])->withTrashed()->find($accountId);
if (null === $account) { if (null === $account) {
Log::error(sprintf('Could not find account %d, so give big fat error.', $accountId)); Log::error(sprintf('Could not find account %d, so give big fat error.', $accountId));
@@ -172,7 +172,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
* @param Request $request * @param Request $request
* @param Throwable $exception * @param Throwable $exception
* *
* @return RedirectResponse|\Illuminate\Http\Response|Redirector|Response * @return Response
* @throws Throwable * @throws Throwable
*/ */
private function handleGroup(Request $request, Throwable $exception) private function handleGroup(Request $request, Throwable $exception)
@@ -183,14 +183,14 @@ class GracefulNotFoundHandler extends ExceptionHandler
$route = $request->route(); $route = $request->route();
$groupId = (int)$route->parameter('transactionGroup'); $groupId = (int)$route->parameter('transactionGroup');
/** @var TransactionGroup $group */ /** @var TransactionGroup|null $group */
$group = $user->transactionGroups()->withTrashed()->find($groupId); $group = $user->transactionGroups()->withTrashed()->find($groupId);
if (null === $group) { if (null === $group) {
Log::error(sprintf('Could not find group %d, so give big fat error.', $groupId)); Log::error(sprintf('Could not find group %d, so give big fat error.', $groupId));
return parent::render($request, $exception); return parent::render($request, $exception);
} }
/** @var TransactionJournal $journal */ /** @var TransactionJournal|null $journal */
$journal = $group->transactionJournals()->withTrashed()->first(); $journal = $group->transactionJournals()->withTrashed()->first();
if (null === $journal) { if (null === $journal) {
Log::error(sprintf('Could not find journal for group %d, so give big fat error.', $groupId)); Log::error(sprintf('Could not find journal for group %d, so give big fat error.', $groupId));
@@ -211,7 +211,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
* @param Request $request * @param Request $request
* @param Throwable $exception * @param Throwable $exception
* *
* @return RedirectResponse|Redirector|Response * @return Response
* @throws Throwable * @throws Throwable
*/ */
private function handleAttachment(Request $request, Throwable $exception) private function handleAttachment(Request $request, Throwable $exception)

View File

@@ -177,10 +177,7 @@ class Handler extends ExceptionHandler
$userData['email'] = auth()->user()->email; $userData['email'] = auth()->user()->email;
} }
$headers = []; $headers = request()->headers->all();
if (request()->headers) {
$headers = request()->headers->all();
}
$data = [ $data = [
'class' => get_class($e), 'class' => get_class($e),

View File

@@ -26,7 +26,6 @@ namespace FireflyIII\Factory;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta; use FireflyIII\Models\AccountMeta;
use Illuminate\Database\QueryException;
use Log; use Log;
/** /**
@@ -45,7 +44,7 @@ class AccountMetaFactory
*/ */
public function crud(Account $account, string $field, string $value): ?AccountMeta public function crud(Account $account, string $field, string $value): ?AccountMeta
{ {
/** @var AccountMeta $entry */ /** @var AccountMeta|null $entry */
$entry = $account->accountMeta()->where('name', $field)->first(); $entry = $account->accountMeta()->where('name', $field)->first();
// must not be an empty string: // must not be an empty string:
if ('' !== $value) { if ('' !== $value) {
@@ -62,11 +61,7 @@ class AccountMetaFactory
Log::debug(sprintf('Updated meta-field "%s":"%s" for #%d ("%s") ', $field, $value, $account->id, $account->name)); Log::debug(sprintf('Updated meta-field "%s":"%s" for #%d ("%s") ', $field, $value, $account->id, $account->name));
} }
if ('' === $value && null !== $entry) { if ('' === $value && null !== $entry) {
try { $entry->delete();
$entry->delete();
} catch (QueryException $e) {
Log::debug(sprintf('Could not delete entry: %s', $e->getMessage()));
}
return null; return null;
} }

View File

@@ -51,7 +51,7 @@ class AttachmentFactory
// get journal instead of transaction. // get journal instead of transaction.
if (Transaction::class === $model) { if (Transaction::class === $model) {
/** @var Transaction $transaction */ /** @var Transaction|null $transaction */
$transaction = $this->user->transactions()->find((int)$data['attachable_id']); $transaction = $this->user->transactions()->find((int)$data['attachable_id']);
if (null === $transaction) { if (null === $transaction) {
throw new FireflyException('Unexpectedly could not find transaction'); throw new FireflyException('Unexpectedly could not find transaction');

View File

@@ -45,7 +45,7 @@ class TagFactory
$tag = trim($tag); $tag = trim($tag);
Log::debug(sprintf('Now in TagFactory::findOrCreate("%s")', $tag)); Log::debug(sprintf('Now in TagFactory::findOrCreate("%s")', $tag));
/** @var Tag $dbTag */ /** @var Tag|null $dbTag */
$dbTag = $this->user->tags()->where('tag', $tag)->first(); $dbTag = $this->user->tags()->where('tag', $tag)->first();
if (null !== $dbTag) { if (null !== $dbTag) {
Log::debug(sprintf('Tag exists (#%d), return it.', $dbTag->id)); Log::debug(sprintf('Tag exists (#%d), return it.', $dbTag->id));

View File

@@ -43,7 +43,6 @@ class TransactionFactory
private ?TransactionCurrency $foreignCurrency; private ?TransactionCurrency $foreignCurrency;
private TransactionJournal $journal; private TransactionJournal $journal;
private bool $reconciled; private bool $reconciled;
private User $user;
/** /**
* Constructor. * Constructor.
@@ -85,7 +84,6 @@ class TransactionFactory
*/ */
private function create(string $amount, ?string $foreignAmount): Transaction private function create(string $amount, ?string $foreignAmount): Transaction
{ {
$result = null;
if ('' === $foreignAmount) { if ('' === $foreignAmount) {
$foreignAmount = null; $foreignAmount = null;
} }
@@ -101,6 +99,7 @@ class TransactionFactory
'identifier' => 0, 'identifier' => 0,
]; ];
try { try {
/** @var Transaction|null $result */
$result = Transaction::create($data); $result = Transaction::create($data);
} catch (QueryException $e) { } catch (QueryException $e) {
Log::error(sprintf('Could not create transaction: %s', $e->getMessage()), $data); Log::error(sprintf('Could not create transaction: %s', $e->getMessage()), $data);
@@ -112,25 +111,23 @@ class TransactionFactory
throw new FireflyException('Transaction is NULL.'); throw new FireflyException('Transaction is NULL.');
} }
if (null !== $result) { Log::debug(
Log::debug( sprintf(
sprintf( 'Created transaction #%d (%s %s, account %s), part of journal #%d',
'Created transaction #%d (%s %s, account %s), part of journal #%d', $result->id,
$result->id, $this->currency->code,
$this->currency->code, $amount,
$amount, $this->account->name,
$this->account->name, $this->journal->id
$this->journal->id )
) );
);
// do foreign currency thing: add foreign currency info to $one and $two if necessary. // do foreign currency thing: add foreign currency info to $one and $two if necessary.
if (null !== $this->foreignCurrency && null !== $foreignAmount && $this->foreignCurrency->id !== $this->currency->id && '' !== $foreignAmount) { if (null !== $this->foreignCurrency && null !== $foreignAmount && $this->foreignCurrency->id !== $this->currency->id && '' !== $foreignAmount) {
$result->foreign_currency_id = $this->foreignCurrency->id; $result->foreign_currency_id = $this->foreignCurrency->id;
$result->foreign_amount = $foreignAmount; $result->foreign_amount = $foreignAmount;
}
$result->save();
} }
$result->save();
return $result; return $result;
} }
@@ -213,6 +210,6 @@ class TransactionFactory
*/ */
public function setUser(User $user): void public function setUser(User $user): void
{ {
$this->user = $user; // empty function.
} }
} }

View File

@@ -28,6 +28,7 @@ use Exception;
use FireflyIII\Exceptions\DuplicateTransactionException; use FireflyIII\Exceptions\DuplicateTransactionException;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\Preference;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
@@ -45,7 +46,6 @@ use FireflyIII\Services\Internal\Support\JournalServiceTrait;
use FireflyIII\Support\NullArrayObject; use FireflyIII\Support\NullArrayObject;
use FireflyIII\User; use FireflyIII\User;
use FireflyIII\Validation\AccountValidator; use FireflyIII\Validation\AccountValidator;
use Illuminate\Database\QueryException;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use JsonException; use JsonException;
use Log; use Log;
@@ -312,10 +312,6 @@ class TransactionJournalFactory
unset($dataRow['import_hash_v2'], $dataRow['original_source']); unset($dataRow['import_hash_v2'], $dataRow['original_source']);
$json = json_encode($dataRow, JSON_THROW_ON_ERROR); $json = json_encode($dataRow, JSON_THROW_ON_ERROR);
if (false === $json) {
$json = json_encode((string)microtime(), JSON_THROW_ON_ERROR);
Log::error(sprintf('Could not hash the original row! %s', json_last_error_msg()), $dataRow);
}
$hash = hash('sha256', $json); $hash = hash('sha256', $json);
Log::debug(sprintf('The hash is: %s', $hash), $dataRow); Log::debug(sprintf('The hash is: %s', $hash), $dataRow);
@@ -336,15 +332,12 @@ class TransactionJournalFactory
if (false === $this->errorOnHash) { if (false === $this->errorOnHash) {
return; return;
} }
$result = null; Log::debug('Will verify duplicate!');
if ($this->errorOnHash) { /** @var TransactionJournalMeta|null $result */
Log::debug('Will verify duplicate!'); $result = TransactionJournalMeta::withTrashed()
/** @var TransactionJournalMeta $result */ ->where('data', json_encode($hash, JSON_THROW_ON_ERROR))
$result = TransactionJournalMeta::withTrashed() ->with(['transactionJournal', 'transactionJournal.transactionGroup'])
->where('data', json_encode($hash, JSON_THROW_ON_ERROR)) ->first();
->with(['transactionJournal', 'transactionJournal.transactionGroup'])
->first();
}
if (null !== $result) { if (null !== $result) {
app('log')->warning(sprintf('Found a duplicate in errorIfDuplicate because hash %s is not unique!', $hash)); app('log')->warning(sprintf('Found a duplicate in errorIfDuplicate because hash %s is not unique!', $hash));
$journal = $result->transactionJournal()->withTrashed()->first(); $journal = $result->transactionJournal()->withTrashed()->first();
@@ -474,6 +467,7 @@ class TransactionJournalFactory
private function getCurrency(?TransactionCurrency $currency, Account $account): TransactionCurrency private function getCurrency(?TransactionCurrency $currency, Account $account): TransactionCurrency
{ {
Log::debug('Now in getCurrency()'); Log::debug('Now in getCurrency()');
/** @var Preference|null $preference */
$preference = $this->accountRepository->getAccountCurrency($account); $preference = $this->accountRepository->getAccountCurrency($account);
if (null === $preference && null === $currency) { if (null === $preference && null === $currency) {
// return user's default: // return user's default:
@@ -555,13 +549,7 @@ class TransactionJournalFactory
*/ */
private function forceTrDelete(Transaction $transaction): void private function forceTrDelete(Transaction $transaction): void
{ {
try { $transaction->delete();
$transaction->delete();
} catch (QueryException $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
Log::error('Could not delete negative transaction.');
}
} }
/** /**

View File

@@ -42,15 +42,11 @@ class TransactionJournalMetaFactory
{ {
//Log::debug('In updateOrCreate()'); //Log::debug('In updateOrCreate()');
$value = $data['data']; $value = $data['data'];
/** @var TransactionJournalMeta $entry */ /** @var TransactionJournalMeta|null $entry */
$entry = $data['journal']->transactionJournalMeta()->where('name', $data['name'])->first(); $entry = $data['journal']->transactionJournalMeta()->where('name', $data['name'])->first();
if (null === $value && null !== $entry) { if (null === $value && null !== $entry) {
//Log::debug('Value is empty, delete meta value.'); //Log::debug('Value is empty, delete meta value.');
try { $entry->delete();
$entry->delete();
} catch (QueryException $e) {
Log::error(sprintf('Could not delete transaction journal meta: %s', $e->getMessage()));
}
return null; return null;
} }
@@ -64,11 +60,7 @@ class TransactionJournalMetaFactory
// don't store blank strings. // don't store blank strings.
if (null !== $entry) { if (null !== $entry) {
Log::debug('Will not store empty strings, delete meta value'); Log::debug('Will not store empty strings, delete meta value');
try { $entry->delete();
$entry->delete();
} catch (QueryException $e) {
Log::error(sprintf('Could not delete transaction journal meta: %s', $e->getMessage()));
}
} }
return null; return null;

View File

@@ -39,8 +39,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
{ {
private Collection $accounts; private Collection $accounts;
private Carbon $end; private Carbon $end;
private array $expenses;
private array $income;
private Carbon $start; private Carbon $start;
private Collection $tags; private Collection $tags;
@@ -49,8 +47,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
*/ */
public function __construct() public function __construct()
{ {
$this->expenses = [];
$this->income = [];
$this->tags = new Collection(); $this->tags = new Collection();
$this->accounts = new Collection(); $this->accounts = new Collection();
} }

View File

@@ -44,6 +44,7 @@ class BillEventHandler
Log::debug(sprintf('Now in %s', __METHOD__)); Log::debug(sprintf('Now in %s', __METHOD__));
$bill = $event->bill; $bill = $event->bill;
/** @var bool $preference */
$preference = Preferences::getForUser($bill->user, 'notification_bill_reminder', true)->data; $preference = Preferences::getForUser($bill->user, 'notification_bill_reminder', true)->data;
if (true === $preference) { if (true === $preference) {

View File

@@ -125,7 +125,7 @@ class UpdatedGroupEventHandler
return; return;
} }
// first journal: // first journal:
/** @var TransactionJournal $first */ /** @var TransactionJournal|null $first */
$first = $group->transactionJournals() $first = $group->transactionJournals()
->orderBy('transaction_journals.date', 'DESC') ->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order', 'ASC') ->orderBy('transaction_journals.order', 'ASC')

View File

@@ -143,7 +143,7 @@ class UserEventHandler
throw new FireflyException('Email address can no longer be used for registrations.'); throw new FireflyException('Email address can no longer be used for registrations.');
} }
} }
/** @var UserRole $role */ /** @var UserRole|null $role */
$role = UserRole::where('title', UserRole::OWNER)->first(); $role = UserRole::where('title', UserRole::OWNER)->first();
if (null === $role) { if (null === $role) {
throw new FireflyException('The user role is unexpectedly empty. Did you run all migrations?'); throw new FireflyException('The user role is unexpectedly empty. Did you run all migrations?');
@@ -366,6 +366,7 @@ class UserEventHandler
]; ];
} }
$preference = array_values($preference); $preference = array_values($preference);
/** @var bool $send */
$send = app('preferences')->getForUser($user, 'notification_user_login', true)->data; $send = app('preferences')->getForUser($user, 'notification_user_login', true)->data;
app('preferences')->setForUser($user, 'login_ip_history', $preference); app('preferences')->setForUser($user, 'login_ip_history', $preference);

View File

@@ -323,9 +323,9 @@ trait AttachmentCollection
foreach ($object['transactions'] as $transaction) { foreach ($object['transactions'] as $transaction) {
/** @var array $attachment */ /** @var array $attachment */
foreach ($transaction['attachments'] as $attachment) { foreach ($transaction['attachments'] as $attachment) {
/** @var Attachment $object */ /** @var Attachment|null $object */
$object = auth()->user()->attachments()->find($attachment['id']); $object = auth()->user()->attachments()->find($attachment['id']);
$notes = (string)$object->notes()?->first()?->text; $notes = (string)$object?->notes()->first()?->text;
return $notes !== '' && $notes === $value; return $notes !== '' && $notes === $value;
} }
} }
@@ -349,9 +349,9 @@ trait AttachmentCollection
foreach ($object['transactions'] as $transaction) { foreach ($object['transactions'] as $transaction) {
/** @var array $attachment */ /** @var array $attachment */
foreach ($transaction['attachments'] as $attachment) { foreach ($transaction['attachments'] as $attachment) {
/** @var Attachment $object */ /** @var Attachment|null $object */
$object = auth()->user()->attachments()->find($attachment['id']); $object = auth()->user()->attachments()->find($attachment['id']);
$notes = (string)$object->notes()?->first()?->text; $notes = (string)$object?->notes()->first()?->text;
return $notes !== '' && $notes !== $value; return $notes !== '' && $notes !== $value;
} }
} }
@@ -375,9 +375,9 @@ trait AttachmentCollection
foreach ($object['transactions'] as $transaction) { foreach ($object['transactions'] as $transaction) {
/** @var array $attachment */ /** @var array $attachment */
foreach ($transaction['attachments'] as $attachment) { foreach ($transaction['attachments'] as $attachment) {
/** @var Attachment $object */ /** @var Attachment|null $object */
$object = auth()->user()->attachments()->find($attachment['id']); $object = auth()->user()->attachments()->find($attachment['id']);
$notes = (string)$object->notes()?->first()?->text; $notes = (string)$object?->notes()->first()?->text;
return $notes !== '' && str_contains(strtolower($notes), strtolower($value)); return $notes !== '' && str_contains(strtolower($notes), strtolower($value));
} }
} }
@@ -401,9 +401,9 @@ trait AttachmentCollection
foreach ($object['transactions'] as $transaction) { foreach ($object['transactions'] as $transaction) {
/** @var array $attachment */ /** @var array $attachment */
foreach ($transaction['attachments'] as $attachment) { foreach ($transaction['attachments'] as $attachment) {
/** @var Attachment $object */ /** @var Attachment|null $object */
$object = auth()->user()->attachments()->find($attachment['id']); $object = auth()->user()->attachments()->find($attachment['id']);
$notes = (string)$object->notes()?->first()?->text; $notes = (string)$object?->notes()->first()?->text;
return $notes !== '' && !str_contains(strtolower($notes), strtolower($value)); return $notes !== '' && !str_contains(strtolower($notes), strtolower($value));
} }
} }
@@ -427,9 +427,9 @@ trait AttachmentCollection
foreach ($object['transactions'] as $transaction) { foreach ($object['transactions'] as $transaction) {
/** @var array $attachment */ /** @var array $attachment */
foreach ($transaction['attachments'] as $attachment) { foreach ($transaction['attachments'] as $attachment) {
/** @var Attachment $object */ /** @var Attachment|null $object */
$object = auth()->user()->attachments()->find($attachment['id']); $object = auth()->user()->attachments()->find($attachment['id']);
$notes = (string)$object->notes()?->first()?->text; $notes = (string)$object?->notes()->first()?->text;
return $notes !== '' && !str_ends_with(strtolower($notes), strtolower($value)); return $notes !== '' && !str_ends_with(strtolower($notes), strtolower($value));
} }
} }
@@ -453,9 +453,9 @@ trait AttachmentCollection
foreach ($object['transactions'] as $transaction) { foreach ($object['transactions'] as $transaction) {
/** @var array $attachment */ /** @var array $attachment */
foreach ($transaction['attachments'] as $attachment) { foreach ($transaction['attachments'] as $attachment) {
/** @var Attachment $object */ /** @var Attachment|null $object */
$object = auth()->user()->attachments()->find($attachment['id']); $object = auth()->user()->attachments()->find($attachment['id']);
$notes = (string)$object->notes()?->first()?->text; $notes = (string)$object?->notes()->first()?->text;
return $notes !== '' && !str_starts_with(strtolower($notes), strtolower($value)); return $notes !== '' && !str_starts_with(strtolower($notes), strtolower($value));
} }
} }
@@ -479,9 +479,9 @@ trait AttachmentCollection
foreach ($object['transactions'] as $transaction) { foreach ($object['transactions'] as $transaction) {
/** @var array $attachment */ /** @var array $attachment */
foreach ($transaction['attachments'] as $attachment) { foreach ($transaction['attachments'] as $attachment) {
/** @var Attachment $object */ /** @var Attachment|null $object */
$object = auth()->user()->attachments()->find($attachment['id']); $object = auth()->user()->attachments()->find($attachment['id']);
$notes = (string)$object->notes()?->first()?->text; $notes = (string)$object?->notes()->first()?->text;
return $notes !== '' && str_ends_with(strtolower($notes), strtolower($value)); return $notes !== '' && str_ends_with(strtolower($notes), strtolower($value));
} }
} }
@@ -505,9 +505,9 @@ trait AttachmentCollection
foreach ($object['transactions'] as $transaction) { foreach ($object['transactions'] as $transaction) {
/** @var array $attachment */ /** @var array $attachment */
foreach ($transaction['attachments'] as $attachment) { foreach ($transaction['attachments'] as $attachment) {
/** @var Attachment $object */ /** @var Attachment|null $object */
$object = auth()->user()->attachments()->find($attachment['id']); $object = auth()->user()->attachments()->find($attachment['id']);
$notes = (string)$object->notes()?->first()?->text; $notes = (string)$object?->notes()->first()?->text;
return $notes !== '' && str_starts_with(strtolower($notes), strtolower($value)); return $notes !== '' && str_starts_with(strtolower($notes), strtolower($value));
} }
} }

View File

@@ -25,6 +25,7 @@ namespace FireflyIII\Helpers\Collector;
use Carbon\Carbon; use Carbon\Carbon;
use Carbon\Exceptions\InvalidDateException; use Carbon\Exceptions\InvalidDateException;
use Carbon\Exceptions\InvalidFormatException;
use Closure; use Closure;
use Exception; use Exception;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
@@ -602,7 +603,7 @@ class GroupCollector implements GroupCollectorInterface
$tagDate = null; $tagDate = null;
try { try {
$tagDate = Carbon::parse($augumentedJournal['tag_date']); $tagDate = Carbon::parse($augumentedJournal['tag_date']);
} catch (InvalidDateException $e) { } catch (InvalidFormatException $e) {
Log::debug(sprintf('Could not parse date: %s', $e->getMessage())); Log::debug(sprintf('Could not parse date: %s', $e->getMessage()));
} }
@@ -682,7 +683,7 @@ class GroupCollector implements GroupCollectorInterface
$tagDate = null; $tagDate = null;
try { try {
$tagDate = Carbon::parse($newArray['tag_date']); $tagDate = Carbon::parse($newArray['tag_date']);
} catch (InvalidDateException $e) { } catch (InvalidFormatException $e) {
Log::debug(sprintf('Could not parse date: %s', $e->getMessage())); Log::debug(sprintf('Could not parse date: %s', $e->getMessage()));
} }
@@ -754,10 +755,7 @@ class GroupCollector implements GroupCollectorInterface
$groups[$groudId]['sums'][$currencyId]['currency_decimal_places'] = $transaction['foreign_currency_decimal_places']; $groups[$groudId]['sums'][$currencyId]['currency_decimal_places'] = $transaction['foreign_currency_decimal_places'];
$groups[$groudId]['sums'][$currencyId]['amount'] = '0'; $groups[$groudId]['sums'][$currencyId]['amount'] = '0';
} }
$groups[$groudId]['sums'][$currencyId]['amount'] = bcadd( $groups[$groudId]['sums'][$currencyId]['amount'] = bcadd($groups[$groudId]['sums'][$currencyId]['amount'], $transaction['foreign_amount']);
$groups[$groudId]['sums'][$currencyId]['amount'],
$transaction['foreign_amount'] ?? '0'
);
} }
} }
} }

View File

@@ -28,7 +28,6 @@ use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\AccountFormRequest; use FireflyIII\Http\Requests\AccountFormRequest;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\Http\Controllers\ModelInformation; use FireflyIII\Support\Http\Controllers\ModelInformation;
use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
@@ -44,9 +43,8 @@ class EditController extends Controller
{ {
use ModelInformation; use ModelInformation;
private AttachmentHelperInterface $attachments; private AttachmentHelperInterface $attachments;
private CurrencyRepositoryInterface $currencyRepos; private AccountRepositoryInterface $repository;
private AccountRepositoryInterface $repository;
/** /**
* EditController constructor. * EditController constructor.
@@ -61,9 +59,8 @@ class EditController extends Controller
app('view')->share('mainTitleIcon', 'fa-credit-card'); app('view')->share('mainTitleIcon', 'fa-credit-card');
app('view')->share('title', (string)trans('firefly.accounts')); app('view')->share('title', (string)trans('firefly.accounts'));
$this->repository = app(AccountRepositoryInterface::class); $this->repository = app(AccountRepositoryInterface::class);
$this->currencyRepos = app(CurrencyRepositoryInterface::class); $this->attachments = app(AttachmentHelperInterface::class);
$this->attachments = app(AttachmentHelperInterface::class);
return $next($request); return $next($request);
} }

View File

@@ -33,7 +33,6 @@ use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\Factory;
@@ -50,12 +49,8 @@ use Psr\Container\NotFoundExceptionInterface;
*/ */
class ReconcileController extends Controller class ReconcileController extends Controller
{ {
/** @var AccountRepositoryInterface The account repository */ private AccountRepositoryInterface $accountRepos;
private $accountRepos; private JournalRepositoryInterface $repository;
/** @var CurrencyRepositoryInterface The currency repository */
private $currencyRepos;
/** @var JournalRepositoryInterface Journals and transactions overview */
private $repository;
/** /**
* ReconcileController constructor. * ReconcileController constructor.
@@ -71,9 +66,8 @@ class ReconcileController extends Controller
function ($request, $next) { function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-credit-card'); app('view')->share('mainTitleIcon', 'fa-credit-card');
app('view')->share('title', (string)trans('firefly.accounts')); app('view')->share('title', (string)trans('firefly.accounts'));
$this->repository = app(JournalRepositoryInterface::class); $this->repository = app(JournalRepositoryInterface::class);
$this->accountRepos = app(AccountRepositoryInterface::class); $this->accountRepos = app(AccountRepositoryInterface::class);
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
return $next($request); return $next($request);
} }

View File

@@ -29,7 +29,6 @@ use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\Http\Controllers\PeriodOverview; use FireflyIII\Support\Http\Controllers\PeriodOverview;
use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
@@ -49,8 +48,7 @@ class ShowController extends Controller
{ {
use PeriodOverview; use PeriodOverview;
private CurrencyRepositoryInterface $currencyRepos; private AccountRepositoryInterface $repository;
private AccountRepositoryInterface $repository;
/** /**
* ShowController constructor. * ShowController constructor.
@@ -69,8 +67,7 @@ class ShowController extends Controller
app('view')->share('mainTitleIcon', 'fa-credit-card'); app('view')->share('mainTitleIcon', 'fa-credit-card');
app('view')->share('title', (string)trans('firefly.accounts')); app('view')->share('title', (string)trans('firefly.accounts'));
$this->repository = app(AccountRepositoryInterface::class); $this->repository = app(AccountRepositoryInterface::class);
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
return $next($request); return $next($request);
} }

View File

@@ -305,6 +305,10 @@ class IndexController extends Controller
} }
} }
// final calculation for 'left': // final calculation for 'left':
/**
* @var int $currencyId
* @var array $info
*/
foreach ($sums['budgeted'] as $currencyId => $info) { foreach ($sums['budgeted'] as $currencyId => $info) {
$spent = $sums['spent'][$currencyId]['amount'] ?? '0'; $spent = $sums['spent'][$currencyId]['amount'] ?? '0';
$budgeted = $sums['budgeted'][$currencyId]['amount'] ?? '0'; $budgeted = $sums['budgeted'][$currencyId]['amount'] ?? '0';

View File

@@ -185,6 +185,7 @@ class ExpenseReportController extends Controller
// remove all empty entries to prevent cluttering: // remove all empty entries to prevent cluttering:
$newSet = []; $newSet = [];
foreach ($chartData as $key => $entry) { foreach ($chartData as $key => $entry) {
// TODO not sure, this is a bad comparison.
if (0 === !array_sum($entry['entries'])) { if (0 === !array_sum($entry['entries'])) {
$newSet[$key] = $entry; $newSet[$key] = $entry;
} }

View File

@@ -83,7 +83,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 $firstEvent */ /** @var PiggyBankEvent|null $firstEvent */
$firstEvent = $set->first(); $firstEvent = $set->first();
$firstDate = null === $firstEvent ? new Carbon() : $firstEvent->date; $firstDate = null === $firstEvent ? new Carbon() : $firstEvent->date;

View File

@@ -30,8 +30,6 @@ use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface; use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\Http\Controllers\DateCalculation; use FireflyIII\Support\Http\Controllers\DateCalculation;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
@@ -42,16 +40,9 @@ class BudgetController extends Controller
{ {
use DateCalculation; use DateCalculation;
/** @var AvailableBudgetRepositoryInterface */ private AvailableBudgetRepositoryInterface $abRepository;
private $abRepository; private BudgetLimitRepositoryInterface $blRepository;
/** @var BudgetLimitRepositoryInterface */ private BudgetRepositoryInterface $repository;
private $blRepository;
/** @var CurrencyRepositoryInterface */
private $currencyRepository;
/** @var OperationsRepositoryInterface */
private $opsRepository;
/** @var BudgetRepositoryInterface The budget repository */
private $repository;
/** /**
* IndexController constructor. * IndexController constructor.
@@ -66,11 +57,9 @@ class BudgetController extends Controller
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.budgets')); app('view')->share('title', (string)trans('firefly.budgets'));
app('view')->share('mainTitleIcon', 'fa-pie-chart'); app('view')->share('mainTitleIcon', 'fa-pie-chart');
$this->repository = app(BudgetRepositoryInterface::class); $this->repository = app(BudgetRepositoryInterface::class);
$this->opsRepository = app(OperationsRepositoryInterface::class); $this->abRepository = app(AvailableBudgetRepositoryInterface::class);
$this->abRepository = app(AvailableBudgetRepositoryInterface::class); $this->blRepository = app(BudgetLimitRepositoryInterface::class);
$this->currencyRepository = app(CurrencyRepositoryInterface::class);
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
$this->repository->cleanupBudgets(); $this->repository->cleanupBudgets();
return $next($request); return $next($request);

View File

@@ -47,8 +47,6 @@ use Throwable;
class ReconcileController extends Controller class ReconcileController extends Controller
{ {
private AccountRepositoryInterface $accountRepos; private AccountRepositoryInterface $accountRepos;
private CurrencyRepositoryInterface $currencyRepos;
private JournalRepositoryInterface $repository;
/** /**
* ReconcileController constructor. * ReconcileController constructor.
@@ -64,9 +62,7 @@ class ReconcileController extends Controller
function ($request, $next) { function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-credit-card'); app('view')->share('mainTitleIcon', 'fa-credit-card');
app('view')->share('title', (string)trans('firefly.accounts')); app('view')->share('title', (string)trans('firefly.accounts'));
$this->repository = app(JournalRepositoryInterface::class);
$this->accountRepos = app(AccountRepositoryInterface::class); $this->accountRepos = app(AccountRepositoryInterface::class);
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
return $next($request); return $next($request);
} }

View File

@@ -88,7 +88,7 @@ class PreferencesController extends Controller
$role = sprintf('opt_group_l_%s', $type); $role = sprintf('opt_group_l_%s', $type);
} }
if ('' === $role || 'opt_group_' === $role) { if ('opt_group_' === $role) {
$role = 'opt_group_defaultAsset'; $role = 'opt_group_defaultAsset';
} }
$groupedAccounts[trans(sprintf('firefly.%s', $role))][$account->id] = $account->name; $groupedAccounts[trans(sprintf('firefly.%s', $role))][$account->id] = $account->name;

View File

@@ -197,9 +197,9 @@ class ProfileController extends Controller
* *
* @param Request $request * @param Request $request
* *
* @return Application|RedirectResponse|Redirector * @return View|RedirectResponse
*/ */
public function deleteAccount(Request $request): Application|RedirectResponse|Redirector public function deleteAccount(Request $request): View|RedirectResponse
{ {
if (!$this->internalAuth || !$this->internalIdentity) { if (!$this->internalAuth || !$this->internalIdentity) {
$request->session()->flash('error', trans('firefly.external_user_mgt_disabled')); $request->session()->flash('error', trans('firefly.external_user_mgt_disabled'));

View File

@@ -28,9 +28,6 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\NoBudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface; use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use FireflyIII\Support\Http\Controllers\BasicDataSupport; use FireflyIII\Support\Http\Controllers\BasicDataSupport;
@@ -49,10 +46,7 @@ class BudgetController extends Controller
{ {
use BasicDataSupport; use BasicDataSupport;
private BudgetLimitRepositoryInterface $blRepository; private OperationsRepositoryInterface $opsRepository;
private NoBudgetRepositoryInterface $nbRepository;
private OperationsRepositoryInterface $opsRepository;
private BudgetRepositoryInterface $repository;
/** /**
* ExpenseReportController constructor. * ExpenseReportController constructor.
@@ -65,9 +59,6 @@ class BudgetController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
$this->opsRepository = app(OperationsRepositoryInterface::class); $this->opsRepository = app(OperationsRepositoryInterface::class);
$this->repository = app(BudgetRepositoryInterface::class);
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
$this->nbRepository = app(NoBudgetRepositoryInterface::class);
return $next($request); return $next($request);
} }

View File

@@ -290,7 +290,7 @@ class ReportController extends Controller
$role = sprintf('opt_group_l_%s', $type); $role = sprintf('opt_group_l_%s', $type);
} }
if ('' === $role || 'opt_group_' === $role) { if ('opt_group_' === $role) {
$role = 'opt_group_defaultAsset'; $role = 'opt_group_defaultAsset';
} }
$groupedAccounts[trans(sprintf('firefly.%s', $role))][$account->id] = $account; $groupedAccounts[trans(sprintf('firefly.%s', $role))][$account->id] = $account;