mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix various phpstan things
This commit is contained in:
parent
1c3cb85a46
commit
b9feb0aa71
@ -106,12 +106,11 @@ class BudgetLimitController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
|
||||||
* @param BudgetLimit $budgetLimit
|
* @param BudgetLimit $budgetLimit
|
||||||
*
|
*
|
||||||
* @return RedirectResponse|Redirector
|
* @return RedirectResponse|Redirector
|
||||||
*/
|
*/
|
||||||
public function delete(Request $request, BudgetLimit $budgetLimit)
|
public function delete(BudgetLimit $budgetLimit)
|
||||||
{
|
{
|
||||||
$this->blRepository->destroyBudgetLimit($budgetLimit);
|
$this->blRepository->destroyBudgetLimit($budgetLimit);
|
||||||
session()->flash('success', trans('firefly.deleted_bl'));
|
session()->flash('success', trans('firefly.deleted_bl'));
|
||||||
|
@ -87,8 +87,6 @@ class IndexController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Show all budgets.
|
* Show all budgets.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
|
||||||
*
|
|
||||||
* @param Carbon|null $start
|
* @param Carbon|null $start
|
||||||
* @param Carbon|null $end
|
* @param Carbon|null $end
|
||||||
*
|
*
|
||||||
@ -98,7 +96,7 @@ class IndexController extends Controller
|
|||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
* @throws NotFoundExceptionInterface
|
* @throws NotFoundExceptionInterface
|
||||||
*/
|
*/
|
||||||
public function index(Request $request, Carbon $start = null, Carbon $end = null)
|
public function index(Carbon $start = null, Carbon $end = null)
|
||||||
{
|
{
|
||||||
$this->abRepository->cleanup();
|
$this->abRepository->cleanup();
|
||||||
app('log')->debug(sprintf('Start of IndexController::index("%s", "%s")', $start?->format('Y-m-d'), $end?->format('Y-m-d')));
|
app('log')->debug(sprintf('Start of IndexController::index("%s", "%s")', $start?->format('Y-m-d'), $end?->format('Y-m-d')));
|
||||||
@ -137,7 +135,7 @@ class IndexController extends Controller
|
|||||||
|
|
||||||
// get budgeted for default currency:
|
// get budgeted for default currency:
|
||||||
if (0 === count($availableBudgets)) {
|
if (0 === count($availableBudgets)) {
|
||||||
$budgeted = $this->blRepository->budgeted($start, $end, $defaultCurrency, );
|
$budgeted = $this->blRepository->budgeted($start, $end, $defaultCurrency,);
|
||||||
$spentArr = $this->opsRepository->sumExpenses($start, $end, null, null, $defaultCurrency);
|
$spentArr = $this->opsRepository->sumExpenses($start, $end, null, null, $defaultCurrency);
|
||||||
$spent = $spentArr[$defaultCurrency->id]['sum'] ?? '0';
|
$spent = $spentArr[$defaultCurrency->id]['sum'] ?? '0';
|
||||||
unset($spentArr);
|
unset($spentArr);
|
||||||
@ -196,7 +194,7 @@ class IndexController extends Controller
|
|||||||
$array['spent'] = $spentArr[$entry->transaction_currency_id]['sum'] ?? '0';
|
$array['spent'] = $spentArr[$entry->transaction_currency_id]['sum'] ?? '0';
|
||||||
|
|
||||||
// budgeted in period:
|
// budgeted in period:
|
||||||
$budgeted = $this->blRepository->budgeted($entry->start_date, $entry->end_date, $entry->transactionCurrency, );
|
$budgeted = $this->blRepository->budgeted($entry->start_date, $entry->end_date, $entry->transactionCurrency,);
|
||||||
$array['budgeted'] = $budgeted;
|
$array['budgeted'] = $budgeted;
|
||||||
$availableBudgets[] = $array;
|
$availableBudgets[] = $array;
|
||||||
unset($spentArr);
|
unset($spentArr);
|
||||||
@ -320,10 +318,9 @@ class IndexController extends Controller
|
|||||||
}
|
}
|
||||||
// final calculation for 'left':
|
// final calculation for 'left':
|
||||||
/**
|
/**
|
||||||
* @var int $currencyId
|
* @var int $currencyId
|
||||||
* @var array $info
|
|
||||||
*/
|
*/
|
||||||
foreach ($sums['budgeted'] as $currencyId => $info) {
|
foreach (array_keys($sums['budgeted']) as $currencyId) {
|
||||||
$spent = $sums['spent'][$currencyId]['amount'] ?? '0';
|
$spent = $sums['spent'][$currencyId]['amount'] ?? '0';
|
||||||
$budgeted = $sums['budgeted'][$currencyId]['amount'] ?? '0';
|
$budgeted = $sums['budgeted'][$currencyId]['amount'] ?? '0';
|
||||||
$sums['left'][$currencyId]['amount'] = bcadd($spent, $budgeted);
|
$sums['left'][$currencyId]['amount'] = bcadd($spent, $budgeted);
|
||||||
|
@ -115,12 +115,10 @@ class DebugController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Show debug info.
|
* Show debug info.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
|
||||||
*
|
|
||||||
* @return Factory|View
|
* @return Factory|View
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index()
|
||||||
{
|
{
|
||||||
$table = $this->generateTable();
|
$table = $this->generateTable();
|
||||||
$table = str_replace(["\n", "\t", ' '], '', $table);
|
$table = str_replace(["\n", "\t", ' '], '', $table);
|
||||||
|
@ -48,13 +48,12 @@ class JavascriptController extends Controller
|
|||||||
* Show info about accounts.
|
* Show info about accounts.
|
||||||
*
|
*
|
||||||
* @param AccountRepositoryInterface $repository
|
* @param AccountRepositoryInterface $repository
|
||||||
* @param CurrencyRepositoryInterface $currencyRepository
|
|
||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
* @throws NotFoundExceptionInterface
|
* @throws NotFoundExceptionInterface
|
||||||
*/
|
*/
|
||||||
public function accounts(AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository): Response
|
public function accounts(AccountRepositoryInterface $repository): Response
|
||||||
{
|
{
|
||||||
$accounts = $repository->getAccountsByType(
|
$accounts = $repository->getAccountsByType(
|
||||||
[AccountType::DEFAULT, AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD]
|
[AccountType::DEFAULT, AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD]
|
||||||
@ -104,7 +103,6 @@ class JavascriptController extends Controller
|
|||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param AccountRepositoryInterface $repository
|
* @param AccountRepositoryInterface $repository
|
||||||
* @param CurrencyRepositoryInterface $currencyRepository
|
|
||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
@ -112,7 +110,7 @@ class JavascriptController extends Controller
|
|||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
* @throws NotFoundExceptionInterface
|
* @throws NotFoundExceptionInterface
|
||||||
*/
|
*/
|
||||||
public function variables(Request $request, AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository): Response
|
public function variables(Request $request, AccountRepositoryInterface $repository): Response
|
||||||
{
|
{
|
||||||
$account = $repository->find((int)$request->get('account'));
|
$account = $repository->find((int)$request->get('account'));
|
||||||
$currency = app('amount')->getDefaultCurrency();
|
$currency = app('amount')->getDefaultCurrency();
|
||||||
@ -147,11 +145,9 @@ class JavascriptController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Bit of a hack but OK.
|
* Bit of a hack but OK.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
|
||||||
*
|
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function variablesV2(Request $request): Response
|
public function variablesV2(): Response
|
||||||
{
|
{
|
||||||
/** @var Carbon $start */
|
/** @var Carbon $start */
|
||||||
$start = clone session('start', today(config('app.timezone'))->startOfMonth());
|
$start = clone session('start', today(config('app.timezone'))->startOfMonth());
|
||||||
|
@ -74,13 +74,11 @@ class IndexController extends Controller
|
|||||||
*
|
*
|
||||||
* TODO very complicated function.
|
* TODO very complicated function.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
|
||||||
*
|
|
||||||
* @return Factory|View
|
* @return Factory|View
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
* @throws JsonException
|
* @throws JsonException
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index()
|
||||||
{
|
{
|
||||||
$this->cleanupObjectGroups();
|
$this->cleanupObjectGroups();
|
||||||
$this->piggyRepos->resetOrder();
|
$this->piggyRepos->resetOrder();
|
||||||
|
@ -76,13 +76,12 @@ class ShowController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
|
||||||
* @param TransactionGroup $transactionGroup
|
* @param TransactionGroup $transactionGroup
|
||||||
*
|
*
|
||||||
* @return Factory|View
|
* @return Factory|View
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function show(Request $request, TransactionGroup $transactionGroup)
|
public function show( TransactionGroup $transactionGroup)
|
||||||
{
|
{
|
||||||
/** @var TransactionJournal|null $first */
|
/** @var TransactionJournal|null $first */
|
||||||
$first = $transactionGroup->transactionJournals()->first(['transaction_journals.*']);
|
$first = $transactionGroup->transactionJournals()->first(['transaction_journals.*']);
|
||||||
@ -105,7 +104,7 @@ class ShowController extends Controller
|
|||||||
$amounts = $this->getAmounts($groupArray);
|
$amounts = $this->getAmounts($groupArray);
|
||||||
$accounts = $this->getAccounts($groupArray);
|
$accounts = $this->getAccounts($groupArray);
|
||||||
|
|
||||||
foreach ($groupArray['transactions'] as $index => $transaction) {
|
foreach (array_keys($groupArray['transactions']) as $index) {
|
||||||
$groupArray['transactions'][$index]['tags'] = $this->repository->getTagObjects(
|
$groupArray['transactions'][$index]['tags'] = $this->repository->getTagObjects(
|
||||||
$groupArray['transactions'][$index]['transaction_journal_id']
|
$groupArray['transactions'][$index]['transaction_journal_id']
|
||||||
);
|
);
|
||||||
|
@ -53,13 +53,9 @@ class IndexController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show debug info.
|
|
||||||
*
|
|
||||||
* @param Request $request
|
|
||||||
*
|
|
||||||
* @return Factory|View
|
* @return Factory|View
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index()
|
||||||
{
|
{
|
||||||
return view('webhooks.index');
|
return view('webhooks.index');
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,7 @@ class Authenticate
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
* @throws AuthenticationException
|
* @throws AuthenticationException
|
||||||
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
*/
|
*/
|
||||||
protected function authenticate($request, array $guards)
|
protected function authenticate($request, array $guards)
|
||||||
{
|
{
|
||||||
|
@ -324,21 +324,4 @@ class OperationsRepository implements OperationsRepositoryInterface
|
|||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* For now, simply refer to whichever repository holds this function.
|
|
||||||
* TODO perhaps better in the future.
|
|
||||||
*
|
|
||||||
* @param Budget $budget
|
|
||||||
* @param Carbon|null $start
|
|
||||||
* @param Carbon|null $end
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
private function getBudgetLimits(Budget $budget, Carbon $start = null, Carbon $end = null): Collection
|
|
||||||
{
|
|
||||||
/** @var BudgetLimitRepositoryInterface $blRepository */
|
|
||||||
$blRepository = app(BudgetLimitRepositoryInterface::class);
|
|
||||||
|
|
||||||
return $blRepository->getBudgetLimits($budget, $start, $end);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ trait ValidatesUserGroupTrait
|
|||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
if (!$request->has('user_group_id')) {
|
if (!$request->has('user_group_id')) {
|
||||||
$group = $user->userGroup;
|
$group = $user->userGroup;
|
||||||
app('log')->debug(sprintf('validateUserGroup: no user group submitted, return default group #%d.', $group->id));
|
app('log')->debug(sprintf('validateUserGroup: no user group submitted, return default group #%d.', $group?->id));
|
||||||
return $group;
|
return $group;
|
||||||
}
|
}
|
||||||
$groupId = (int)$request->get('user_group_id');
|
$groupId = (int)$request->get('user_group_id');
|
||||||
|
@ -36,6 +36,7 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
|||||||
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
|
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
|
use FireflyIII\Support\Facades\Amount;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -216,9 +217,20 @@ trait AugumentData
|
|||||||
/** @var BudgetLimit $entry */
|
/** @var BudgetLimit $entry */
|
||||||
foreach ($set as $entry) {
|
foreach ($set as $entry) {
|
||||||
$currency = $entry->transactionCurrency;
|
$currency = $entry->transactionCurrency;
|
||||||
|
|
||||||
|
if(null === $currency) {
|
||||||
|
$currency = app('amount')->getDefaultCurrency();
|
||||||
|
}
|
||||||
|
|
||||||
// clone because these objects change each other.
|
// clone because these objects change each other.
|
||||||
$currentStart = clone $entry->start_date;
|
$currentStart = clone $entry->start_date;
|
||||||
$currentEnd = clone $entry->end_date;
|
$currentEnd = null === $entry->end_date ? null : clone $entry->end_date;
|
||||||
|
|
||||||
|
if(null === $currentEnd) {
|
||||||
|
$currentEnd = clone $currentStart;
|
||||||
|
$currentEnd->addMonth();
|
||||||
|
}
|
||||||
|
|
||||||
$expenses = $opsRepository->sumExpenses($currentStart, $currentEnd, null, $budgetCollection, $currency);
|
$expenses = $opsRepository->sumExpenses($currentStart, $currentEnd, null, $budgetCollection, $currency);
|
||||||
$spent = $expenses[$currency->id]['sum'] ?? '0';
|
$spent = $expenses[$currency->id]['sum'] ?? '0';
|
||||||
$entry->spent = $spent;
|
$entry->spent = $spent;
|
||||||
|
@ -220,9 +220,9 @@ trait GetConfigurationData
|
|||||||
protected function verifyRecurringCronJob(): void
|
protected function verifyRecurringCronJob(): void
|
||||||
{
|
{
|
||||||
$config = app('fireflyconfig')->get('last_rt_job', 0);
|
$config = app('fireflyconfig')->get('last_rt_job', 0);
|
||||||
$lastTime = (int)$config->data;
|
$lastTime = (int)$config?->data;
|
||||||
$now = time();
|
$now = time();
|
||||||
app('log')->debug(sprintf('verifyRecurringCronJob: last time is %d ("%s"), now is %d', $lastTime, $config->data, $now));
|
app('log')->debug(sprintf('verifyRecurringCronJob: last time is %d ("%s"), now is %d', $lastTime, $config?->data, $now));
|
||||||
if (0 === $lastTime) {
|
if (0 === $lastTime) {
|
||||||
request()->session()->flash('info', trans('firefly.recurring_never_cron'));
|
request()->session()->flash('info', trans('firefly.recurring_never_cron'));
|
||||||
|
|
||||||
|
@ -79,6 +79,7 @@ trait ModelInformation
|
|||||||
/** @var AccountRepositoryInterface $repository */
|
/** @var AccountRepositoryInterface $repository */
|
||||||
$repository = app(AccountRepositoryInterface::class);
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
// types of liability:
|
// types of liability:
|
||||||
|
/** @var AccountType $debt */
|
||||||
$debt = $repository->getAccountTypeByType(AccountType::DEBT);
|
$debt = $repository->getAccountTypeByType(AccountType::DEBT);
|
||||||
$loan = $repository->getAccountTypeByType(AccountType::LOAN);
|
$loan = $repository->getAccountTypeByType(AccountType::LOAN);
|
||||||
$mortgage = $repository->getAccountTypeByType(AccountType::MORTGAGE);
|
$mortgage = $repository->getAccountTypeByType(AccountType::MORTGAGE);
|
||||||
|
@ -64,6 +64,10 @@ trait RenderPartialViews
|
|||||||
$accountRepos = app(AccountRepositoryInterface::class);
|
$accountRepos = app(AccountRepositoryInterface::class);
|
||||||
$account = $accountRepos->find((int)$attributes['accountId']);
|
$account = $accountRepos->find((int)$attributes['accountId']);
|
||||||
|
|
||||||
|
if(null === $budget || null === $account) {
|
||||||
|
throw new FireflyException('Could not render popup.report.balance-amount because budget or account is null.');
|
||||||
|
}
|
||||||
|
|
||||||
$journals = $popupHelper->balanceForBudget($budget, $account, $attributes);
|
$journals = $popupHelper->balanceForBudget($budget, $account, $attributes);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -330,7 +334,7 @@ trait RenderPartialViews
|
|||||||
if ('user_action' !== $entry->trigger_type) {
|
if ('user_action' !== $entry->trigger_type) {
|
||||||
$count = ($index + 1);
|
$count = ($index + 1);
|
||||||
try {
|
try {
|
||||||
$rootOperator = OperatorQuerySearch::getRootOperator($entry->trigger_type);
|
$rootOperator = OperatorQuerySearch::getRootOperator((string) $entry->trigger_type);
|
||||||
if (str_starts_with($rootOperator, '-')) {
|
if (str_starts_with($rootOperator, '-')) {
|
||||||
$rootOperator = substr($rootOperator, 1);
|
$rootOperator = substr($rootOperator, 1);
|
||||||
}
|
}
|
||||||
@ -340,7 +344,7 @@ trait RenderPartialViews
|
|||||||
'oldTrigger' => $rootOperator,
|
'oldTrigger' => $rootOperator,
|
||||||
'oldValue' => $entry->trigger_value,
|
'oldValue' => $entry->trigger_value,
|
||||||
'oldChecked' => $entry->stop_processing,
|
'oldChecked' => $entry->stop_processing,
|
||||||
'oldProhibited' => str_starts_with($entry->trigger_type, '-'),
|
'oldProhibited' => str_starts_with((string) $entry->trigger_type, '-'),
|
||||||
'count' => $count,
|
'count' => $count,
|
||||||
'triggers' => $triggers,
|
'triggers' => $triggers,
|
||||||
]
|
]
|
||||||
|
@ -63,11 +63,15 @@ trait UserGroupTrait
|
|||||||
* @param Authenticatable|User|null $user
|
* @param Authenticatable|User|null $user
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function setUser(Authenticatable | User | null $user): void
|
public function setUser(Authenticatable | User | null $user): void
|
||||||
{
|
{
|
||||||
if ($user instanceof User) {
|
if ($user instanceof User) {
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
|
if(null === $user->userGroup) {
|
||||||
|
throw new FireflyException(sprintf('User #%d has no user group.', $user->id));
|
||||||
|
}
|
||||||
$this->userGroup = $user->userGroup;
|
$this->userGroup = $user->userGroup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ trait ChecksLogin
|
|||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
app('log')->debug('Now in getUserGroup()');
|
app('log')->debug('Now in getUserGroup()');
|
||||||
/** @var UserGroup|null $userGroup */
|
/** @var UserGroup|null $userGroup */
|
||||||
$userGroup = $this->route()->parameter('userGroup');
|
$userGroup = $this->route()?->parameter('userGroup');
|
||||||
if (null === $userGroup) {
|
if (null === $userGroup) {
|
||||||
app('log')->debug('Request class has no userGroup parameter, but perhaps there is a parameter.');
|
app('log')->debug('Request class has no userGroup parameter, but perhaps there is a parameter.');
|
||||||
$userGroupId = (int)$this->get('user_group_id');
|
$userGroupId = (int)$this->get('user_group_id');
|
||||||
|
@ -70,7 +70,7 @@ trait ConvertsDataTypes
|
|||||||
if (!is_scalar($entry)) {
|
if (!is_scalar($entry)) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
return $this->clearString((string)$entry, false);
|
return (string) $this->clearString((string)$entry, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -199,7 +199,7 @@ trait ConvertsDataTypes
|
|||||||
*/
|
*/
|
||||||
public function stringWithNewlines(string $field): string
|
public function stringWithNewlines(string $field): string
|
||||||
{
|
{
|
||||||
return $this->clearString((string)($this->get($field) ?? ''));
|
return (string) $this->clearString((string)($this->get($field) ?? ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -255,7 +255,7 @@ trait ConvertsDataTypes
|
|||||||
*/
|
*/
|
||||||
protected function convertDateTime(?string $string): ?Carbon
|
protected function convertDateTime(?string $string): ?Carbon
|
||||||
{
|
{
|
||||||
$value = $this->get($string);
|
$value = $this->get((string)$string);
|
||||||
if (null === $value) {
|
if (null === $value) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,6 @@ use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
|||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||||
use FireflyIII\Services\Password\Verifier;
|
use FireflyIII\Services\Password\Verifier;
|
||||||
use FireflyIII\Support\Facades\Preferences;
|
|
||||||
use FireflyIII\Support\ParseDateString;
|
use FireflyIII\Support\ParseDateString;
|
||||||
use FireflyIII\TransactionRules\Triggers\TriggerInterface;
|
use FireflyIII\TransactionRules\Triggers\TriggerInterface;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
@ -49,6 +48,7 @@ use ValueError;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class FireflyValidator.
|
* Class FireflyValidator.
|
||||||
|
* TODO all of these validations must become separate classes.
|
||||||
*/
|
*/
|
||||||
class FireflyValidator extends Validator
|
class FireflyValidator extends Validator
|
||||||
{
|
{
|
||||||
@ -60,6 +60,7 @@ class FireflyValidator extends Validator
|
|||||||
* @throws IncompatibleWithGoogleAuthenticatorException
|
* @throws IncompatibleWithGoogleAuthenticatorException
|
||||||
* @throws InvalidCharactersException
|
* @throws InvalidCharactersException
|
||||||
* @throws SecretKeyTooShortException
|
* @throws SecretKeyTooShortException
|
||||||
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
*/
|
*/
|
||||||
public function validate2faCode($attribute, $value): bool
|
public function validate2faCode($attribute, $value): bool
|
||||||
{
|
{
|
||||||
@ -73,18 +74,18 @@ class FireflyValidator extends Validator
|
|||||||
}
|
}
|
||||||
$secretPreference = app('preferences')->get('temp-mfa-secret');
|
$secretPreference = app('preferences')->get('temp-mfa-secret');
|
||||||
$secret = $secretPreference?->data ?? '';
|
$secret = $secretPreference?->data ?? '';
|
||||||
if(is_array($secret)) {
|
if (is_array($secret)) {
|
||||||
$secret = '';
|
$secret = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return (bool) Google2FA::verifyKey((string) $secret, $value);
|
return (bool)Google2FA::verifyKey((string)$secret, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $attribute
|
* @param mixed $attribute
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param mixed $parameters
|
* @param mixed $parameters
|
||||||
*
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function validateBelongsToUser($attribute, $value, $parameters): bool
|
public function validateBelongsToUser($attribute, $value, $parameters): bool
|
||||||
@ -102,7 +103,7 @@ class FireflyValidator extends Validator
|
|||||||
/**
|
/**
|
||||||
* @param mixed $attribute
|
* @param mixed $attribute
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
*
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function validateBic($attribute, $value): bool
|
public function validateBic($attribute, $value): bool
|
||||||
@ -122,7 +123,7 @@ class FireflyValidator extends Validator
|
|||||||
/**
|
/**
|
||||||
* @param mixed $attribute
|
* @param mixed $attribute
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
*
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function validateIban(mixed $attribute, mixed $value): bool
|
public function validateIban(mixed $attribute, mixed $value): bool
|
||||||
@ -186,7 +187,7 @@ class FireflyValidator extends Validator
|
|||||||
$value = strtoupper($value);
|
$value = strtoupper($value);
|
||||||
|
|
||||||
// replace characters outside of ASCI range.
|
// replace characters outside of ASCI range.
|
||||||
$value = (string) iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $value);
|
$value = (string)iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $value);
|
||||||
$search = [' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
|
$search = [' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
|
||||||
$replace = [
|
$replace = [
|
||||||
'',
|
'',
|
||||||
@ -228,7 +229,8 @@ class FireflyValidator extends Validator
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$checksum = bcmod($iban, '97');
|
$checksum = bcmod($iban, '97');
|
||||||
} catch (ValueError $e) { /** @phpstan-ignore-line */
|
} catch (ValueError $e) {
|
||||||
|
/** @phpstan-ignore-line */
|
||||||
$message = sprintf('Could not validate IBAN check value "%s" (IBAN "%s")', $iban, $value);
|
$message = sprintf('Could not validate IBAN check value "%s" (IBAN "%s")', $iban, $value);
|
||||||
app('log')->error($message);
|
app('log')->error($message);
|
||||||
app('log')->error($e->getTraceAsString());
|
app('log')->error($e->getTraceAsString());
|
||||||
@ -243,7 +245,7 @@ class FireflyValidator extends Validator
|
|||||||
* @param mixed $attribute
|
* @param mixed $attribute
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param mixed $parameters
|
* @param mixed $parameters
|
||||||
*
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function validateLess($attribute, $value, $parameters): bool
|
public function validateLess($attribute, $value, $parameters): bool
|
||||||
@ -258,7 +260,7 @@ class FireflyValidator extends Validator
|
|||||||
* @param mixed $attribute
|
* @param mixed $attribute
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param mixed $parameters
|
* @param mixed $parameters
|
||||||
*
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function validateMore($attribute, $value, $parameters): bool
|
public function validateMore($attribute, $value, $parameters): bool
|
||||||
@ -273,7 +275,7 @@ class FireflyValidator extends Validator
|
|||||||
* @param mixed $attribute
|
* @param mixed $attribute
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param mixed $parameters
|
* @param mixed $parameters
|
||||||
*
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function validateMustExist($attribute, $value, $parameters): bool
|
public function validateMustExist($attribute, $value, $parameters): bool
|
||||||
@ -444,7 +446,7 @@ class FireflyValidator extends Validator
|
|||||||
/**
|
/**
|
||||||
* @param mixed $attribute
|
* @param mixed $attribute
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
*
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function validateSecurePassword($attribute, $value): bool
|
public function validateSecurePassword($attribute, $value): bool
|
||||||
@ -467,6 +469,7 @@ class FireflyValidator extends Validator
|
|||||||
* @param mixed $attribute
|
* @param mixed $attribute
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param mixed $parameters
|
* @param mixed $parameters
|
||||||
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -512,7 +515,7 @@ class FireflyValidator extends Validator
|
|||||||
if (!array_key_exists('user_id', $this->data)) {
|
if (!array_key_exists('user_id', $this->data)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
$user = User::find($this->data['user_id']);
|
$user = User::find($this->data['user_id']);
|
||||||
$type = AccountType::find($this->data['account_type_id'])->first();
|
$type = AccountType::find($this->data['account_type_id'])->first();
|
||||||
@ -624,6 +627,7 @@ class FireflyValidator extends Validator
|
|||||||
* @param mixed $attribute
|
* @param mixed $attribute
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param mixed $parameters
|
* @param mixed $parameters
|
||||||
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -676,10 +680,11 @@ class FireflyValidator extends Validator
|
|||||||
/**
|
/**
|
||||||
* @param string|null $attribute
|
* @param string|null $attribute
|
||||||
* @param string|null $value
|
* @param string|null $value
|
||||||
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function validateUniqueCurrencyCode(string|null $attribute, string|null $value): bool
|
public function validateUniqueCurrencyCode(string | null $attribute, string | null $value): bool
|
||||||
{
|
{
|
||||||
return $this->validateUniqueCurrency('code', (string)$attribute, (string)$value);
|
return $this->validateUniqueCurrency('code', (string)$attribute, (string)$value);
|
||||||
}
|
}
|
||||||
@ -688,6 +693,7 @@ class FireflyValidator extends Validator
|
|||||||
* @param string $field
|
* @param string $field
|
||||||
* @param string $attribute
|
* @param string $attribute
|
||||||
* @param string $value
|
* @param string $value
|
||||||
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -702,7 +708,7 @@ class FireflyValidator extends Validator
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function validateUniqueCurrencyName(string|null $attribute, string|null $value): bool
|
public function validateUniqueCurrencyName(string | null $attribute, string | null $value): bool
|
||||||
{
|
{
|
||||||
return $this->validateUniqueCurrency('name', (string)$attribute, (string)$value);
|
return $this->validateUniqueCurrency('name', (string)$attribute, (string)$value);
|
||||||
}
|
}
|
||||||
@ -713,7 +719,7 @@ class FireflyValidator extends Validator
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function validateUniqueCurrencySymbol(string|null $attribute, string|null $value): bool
|
public function validateUniqueCurrencySymbol(string | null $attribute, string | null $value): bool
|
||||||
{
|
{
|
||||||
return $this->validateUniqueCurrency('symbol', (string)$attribute, (string)$value);
|
return $this->validateUniqueCurrency('symbol', (string)$attribute, (string)$value);
|
||||||
}
|
}
|
||||||
@ -722,6 +728,7 @@ class FireflyValidator extends Validator
|
|||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param mixed $parameters
|
* @param mixed $parameters
|
||||||
* @param mixed $something
|
* @param mixed $something
|
||||||
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -777,6 +784,7 @@ class FireflyValidator extends Validator
|
|||||||
* @param mixed $attribute
|
* @param mixed $attribute
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param mixed $parameters
|
* @param mixed $parameters
|
||||||
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -809,6 +817,7 @@ class FireflyValidator extends Validator
|
|||||||
* @param mixed $attribute
|
* @param mixed $attribute
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param mixed $parameters
|
* @param mixed $parameters
|
||||||
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -830,6 +839,7 @@ class FireflyValidator extends Validator
|
|||||||
* @param mixed $attribute
|
* @param mixed $attribute
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param mixed $parameters
|
* @param mixed $parameters
|
||||||
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -849,6 +859,7 @@ class FireflyValidator extends Validator
|
|||||||
/**
|
/**
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param mixed $parameters
|
* @param mixed $parameters
|
||||||
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@ -488,7 +488,7 @@ trait TransactionValidation
|
|||||||
*/
|
*/
|
||||||
private function getTransactionType(TransactionGroup $group, array $transactions): string
|
private function getTransactionType(TransactionGroup $group, array $transactions): string
|
||||||
{
|
{
|
||||||
return $transactions[0]['type'] ?? strtolower($group->transactionJournals()->first()->transactionType->type);
|
return $transactions[0]['type'] ?? strtolower((string) $group->transactionJournals()->first()?->transactionType->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -502,13 +502,13 @@ trait TransactionValidation
|
|||||||
if (1 === $transactionGroup->transactionJournals->count()) {
|
if (1 === $transactionGroup->transactionJournals->count()) {
|
||||||
$journal = $transactionGroup->transactionJournals->first();
|
$journal = $transactionGroup->transactionJournals->first();
|
||||||
|
|
||||||
return $journal->transactions()->where('amount', '<', 0)->first()->account;
|
return $journal?->transactions()->where('amount', '<', 0)->first()?->account;
|
||||||
}
|
}
|
||||||
/** @var TransactionJournal $journal */
|
/** @var TransactionJournal $journal */
|
||||||
foreach ($transactionGroup->transactionJournals as $journal) {
|
foreach ($transactionGroup->transactionJournals as $journal) {
|
||||||
$journalId = (int)($transaction['transaction_journal_id'] ?? 0);
|
$journalId = (int)($transaction['transaction_journal_id'] ?? 0);
|
||||||
if ($journal->id === $journalId) {
|
if ($journal->id === $journalId) {
|
||||||
return $journal->transactions()->where('amount', '<', 0)->first()->account;
|
return $journal->transactions()->where('amount', '<', 0)->first()?->account;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -785,7 +785,7 @@ trait TransactionValidation
|
|||||||
}
|
}
|
||||||
/** @var Transaction|null $destination */
|
/** @var Transaction|null $destination */
|
||||||
$destination = Transaction::where('transaction_journal_id', $journalId)->where('amount', '>', 0)->with(['account'])->first();
|
$destination = Transaction::where('transaction_journal_id', $journalId)->where('amount', '>', 0)->with(['account'])->first();
|
||||||
if (null !== $source) {
|
if (null !== $destination) {
|
||||||
$return['destination_id'] = $destination->account_id;
|
$return['destination_id'] = $destination->account_id;
|
||||||
$return['destination_name'] = $destination->account->name;
|
$return['destination_name'] = $destination->account->name;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user