diff --git a/.ci/php-cs-fixer/.php-cs-fixer.php b/.ci/php-cs-fixer/.php-cs-fixer.php index c1462f7fcd..e701db9232 100644 --- a/.ci/php-cs-fixer/.php-cs-fixer.php +++ b/.ci/php-cs-fixer/.php-cs-fixer.php @@ -22,7 +22,7 @@ $current = __DIR__; $paths = [ - $current . '/../../app/Api/V1', + $current . '/../../app/Api', // $current . '/../../config', // $current . '/../../database', // $current . '/../../routes', diff --git a/app/Api/V2/Controllers/Autocomplete/AccountController.php b/app/Api/V2/Controllers/Autocomplete/AccountController.php index 534681eb8e..46082d4c79 100644 --- a/app/Api/V2/Controllers/Autocomplete/AccountController.php +++ b/app/Api/V2/Controllers/Autocomplete/AccountController.php @@ -56,7 +56,7 @@ class AccountController extends Controller $this->repository = app(AccountRepositoryInterface::class); $this->adminRepository = app(AdminAccountRepositoryInterface::class); - $userGroup = $this->validateUserGroup($request); + $userGroup = $this->validateUserGroup($request); if (null !== $userGroup) { $this->adminRepository->setUserGroup($userGroup); } @@ -99,12 +99,12 @@ class AccountController extends Controller $balance = app('steam')->balance($account, $date); $nameWithBalance = sprintf('%s (%s)', $account->name, app('amount')->formatAnything($currency, $balance, false)); } - $type = (string)trans(sprintf('firefly.%s', $account->accountType->type)); + $type = (string)trans(sprintf('firefly.%s', $account->accountType->type)); $groupedResult[$type] ??= [ 'group ' => $type, 'items' => [], ]; - $allItems[] = [ + $allItems[] = [ 'id' => (string)$account->id, 'value' => (string)$account->id, 'name' => $account->name, diff --git a/app/Api/V2/Controllers/Autocomplete/TransactionController.php b/app/Api/V2/Controllers/Autocomplete/TransactionController.php index 5aa81372d3..e255adfe1b 100644 --- a/app/Api/V2/Controllers/Autocomplete/TransactionController.php +++ b/app/Api/V2/Controllers/Autocomplete/TransactionController.php @@ -46,7 +46,7 @@ class TransactionController extends Controller function ($request, $next) { $this->repository = app(JournalRepositoryInterface::class); - $userGroup = $this->validateUserGroup($request); + $userGroup = $this->validateUserGroup($request); if (null !== $userGroup) { $this->repository->setUserGroup($userGroup); } @@ -67,8 +67,8 @@ class TransactionController extends Controller */ public function transactionDescriptions(AutocompleteRequest $request): JsonResponse { - $data = $request->getData(); - $result = $this->repository->searchJournalDescriptions($data['query'], $data['limit']); + $data = $request->getData(); + $result = $this->repository->searchJournalDescriptions($data['query'], $data['limit']); // limit and unique $filtered = $result->unique('description'); diff --git a/app/Api/V2/Controllers/Chart/AccountController.php b/app/Api/V2/Controllers/Chart/AccountController.php index 756e83df4e..27aa842a4a 100644 --- a/app/Api/V2/Controllers/Chart/AccountController.php +++ b/app/Api/V2/Controllers/Chart/AccountController.php @@ -81,15 +81,15 @@ class AccountController extends Controller public function dashboard(DashboardChartRequest $request): JsonResponse { /** @var Carbon $start */ - $start = $this->parameters->get('start'); + $start = $this->parameters->get('start'); /** @var Carbon $end */ - $end = $this->parameters->get('end'); + $end = $this->parameters->get('end'); $end->endOfDay(); /** @var TransactionCurrency $default */ - $default = app('amount')->getDefaultCurrency(); - $params = $request->getAll(); + $default = app('amount')->getDefaultCurrency(); + $params = $request->getAll(); /** @var Collection $accounts */ $accounts = $params['accounts']; @@ -105,7 +105,7 @@ class AccountController extends Controller $frontPage->save(); } - $accounts = $this->repository->getAccountsById($frontPage->data); + $accounts = $this->repository->getAccountsById($frontPage->data); } // both options are overruled by "preselected" @@ -121,48 +121,48 @@ class AccountController extends Controller /** @var Account $account */ foreach ($accounts as $account) { - $currency = $this->repository->getAccountCurrency($account); + $currency = $this->repository->getAccountCurrency($account); if (null === $currency) { $currency = $default; } - $currentSet = [ - 'label' => $account->name, + $currentSet = [ + 'label' => $account->name, // the currency that belongs to the account. - 'currency_id' => (string)$currency->id, - 'currency_code' => $currency->code, - 'currency_symbol' => $currency->symbol, - 'currency_decimal_places' => $currency->decimal_places, + 'currency_id' => (string)$currency->id, + 'currency_code' => $currency->code, + 'currency_symbol' => $currency->symbol, + 'currency_decimal_places' => $currency->decimal_places, // the default currency of the user (could be the same!) 'native_currency_id' => (string)$default->id, 'native_currency_code' => $default->code, 'native_currency_symbol' => $default->symbol, 'native_currency_decimal_places' => $default->decimal_places, - 'start' => $start->toAtomString(), - 'end' => $end->toAtomString(), - 'period' => '1D', - 'entries' => [], - 'native_entries' => [], + 'start' => $start->toAtomString(), + 'end' => $end->toAtomString(), + 'period' => '1D', + 'entries' => [], + 'native_entries' => [], ]; - $currentStart = clone $start; - $range = app('steam')->balanceInRange($account, $start, clone $end, $currency); - $rangeConverted = app('steam')->balanceInRangeConverted($account, $start, clone $end, $default); + $currentStart = clone $start; + $range = app('steam')->balanceInRange($account, $start, clone $end, $currency); + $rangeConverted = app('steam')->balanceInRangeConverted($account, $start, clone $end, $default); $previous = array_values($range)[0]; $previousConverted = array_values($rangeConverted)[0]; while ($currentStart <= $end) { - $format = $currentStart->format('Y-m-d'); - $label = $currentStart->toAtomString(); - $balance = array_key_exists($format, $range) ? $range[$format] : $previous; - $balanceConverted = array_key_exists($format, $rangeConverted) ? $rangeConverted[$format] : $previousConverted; - $previous = $balance; - $previousConverted = $balanceConverted; + $format = $currentStart->format('Y-m-d'); + $label = $currentStart->toAtomString(); + $balance = array_key_exists($format, $range) ? $range[$format] : $previous; + $balanceConverted = array_key_exists($format, $rangeConverted) ? $rangeConverted[$format] : $previousConverted; + $previous = $balance; + $previousConverted = $balanceConverted; $currentStart->addDay(); $currentSet['entries'][$label] = $balance; $currentSet['native_entries'][$label] = $balanceConverted; } - $chartData[] = $currentSet; + $chartData[] = $currentSet; } return response()->json($this->clean($chartData)); diff --git a/app/Api/V2/Controllers/Chart/BalanceController.php b/app/Api/V2/Controllers/Chart/BalanceController.php index cef7ab8dcb..a35e4c8480 100644 --- a/app/Api/V2/Controllers/Chart/BalanceController.php +++ b/app/Api/V2/Controllers/Chart/BalanceController.php @@ -59,13 +59,13 @@ class BalanceController extends Controller */ public function balance(BalanceChartRequest $request): JsonResponse { - $params = $request->getAll(); + $params = $request->getAll(); /** @var Carbon $start */ - $start = $this->parameters->get('start'); + $start = $this->parameters->get('start'); /** @var Carbon $end */ - $end = $this->parameters->get('end'); + $end = $this->parameters->get('end'); $end->endOfDay(); /** @var Collection $accounts */ @@ -76,17 +76,17 @@ class BalanceController extends Controller // prepare for currency conversion and data collection: /** @var TransactionCurrency $default */ - $default = app('amount')->getDefaultCurrency(); + $default = app('amount')->getDefaultCurrency(); // get journals for entire period: /** @var GroupCollectorInterface $collector */ - $collector = app(GroupCollectorInterface::class); + $collector = app(GroupCollectorInterface::class); $collector->setRange($start, $end)->withAccountInformation(); $collector->setXorAccounts($accounts); $collector->setTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::RECONCILIATION, TransactionType::TRANSFER]); - $journals = $collector->getExtractedJournals(); + $journals = $collector->getExtractedJournals(); - $object = new AccountBalanceGrouped(); + $object = new AccountBalanceGrouped(); $object->setPreferredRange($preferredRange); $object->setDefault($default); $object->setAccounts($accounts); @@ -94,7 +94,7 @@ class BalanceController extends Controller $object->setStart($start); $object->setEnd($end); $object->groupByCurrencyAndPeriod(); - $chartData = $object->convertToChartData(); + $chartData = $object->convertToChartData(); return response()->json($this->clean($chartData)); } diff --git a/app/Api/V2/Controllers/Chart/BudgetController.php b/app/Api/V2/Controllers/Chart/BudgetController.php index 9e852addca..a5db2035e0 100644 --- a/app/Api/V2/Controllers/Chart/BudgetController.php +++ b/app/Api/V2/Controllers/Chart/BudgetController.php @@ -65,7 +65,7 @@ class BudgetController extends Controller $this->opsRepository = app(OperationsRepositoryInterface::class); $this->currency = app('amount')->getDefaultCurrency(); - $userGroup = $this->validateUserGroup($request); + $userGroup = $this->validateUserGroup($request); if (null !== $userGroup) { $this->repository->setUserGroup($userGroup); $this->opsRepository->setUserGroup($userGroup); @@ -85,13 +85,13 @@ class BudgetController extends Controller */ public function dashboard(DateRequest $request): JsonResponse { - $params = $request->getAll(); + $params = $request->getAll(); /** @var Carbon $start */ - $start = $params['start']; + $start = $params['start']; /** @var Carbon $end */ - $end = $params['end']; + $end = $params['end']; // code from FrontpageChartGenerator, but not in separate class $budgets = $this->repository->getActiveBudgets(); @@ -212,14 +212,14 @@ class BudgetController extends Controller 'overspent' => '0', 'native_overspent' => '0', ]; - $currentBudgetArray = $block['budgets'][$budgetId]; + $currentBudgetArray = $block['budgets'][$budgetId]; // var_dump($return); /** @var array $journal */ foreach ($currentBudgetArray['transaction_journals'] as $journal) { // convert the amount to the native currency. - $rate = $converter->getCurrencyRate($this->currencies[$currencyId], $this->currency, $journal['date']); - $convertedAmount = bcmul($journal['amount'], $rate); + $rate = $converter->getCurrencyRate($this->currencies[$currencyId], $this->currency, $journal['date']); + $convertedAmount = bcmul($journal['amount'], $rate); if ($journal['foreign_currency_id'] === $this->currency->id) { $convertedAmount = $journal['foreign_amount']; } @@ -262,7 +262,7 @@ class BudgetController extends Controller private function processLimit(Budget $budget, BudgetLimit $limit): array { Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__)); - $end = clone $limit->end_date; + $end = clone $limit->end_date; $end->endOfDay(); $spent = $this->opsRepository->listExpenses($limit->start_date, $end, null, new Collection([$budget])); $limitCurrencyId = $limit->transaction_currency_id; @@ -280,7 +280,7 @@ class BudgetController extends Controller $filtered[$currencyId] = $entry; } } - $result = $this->processExpenses($budget->id, $filtered, $limit->start_date, $end); + $result = $this->processExpenses($budget->id, $filtered, $limit->start_date, $end); if (1 === count($result)) { $compare = bccomp($limit->amount, app('steam')->positive($result[$limitCurrencyId]['spent'])); if (1 === $compare) { diff --git a/app/Api/V2/Controllers/Chart/CategoryController.php b/app/Api/V2/Controllers/Chart/CategoryController.php index 6df4a085d3..f0bad7c828 100644 --- a/app/Api/V2/Controllers/Chart/CategoryController.php +++ b/app/Api/V2/Controllers/Chart/CategoryController.php @@ -80,7 +80,7 @@ class CategoryController extends Controller Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__)); /** @var Carbon $start */ - $start = $this->parameters->get('start'); + $start = $this->parameters->get('start'); /** @var Carbon $end */ $end = $this->parameters->get('end'); @@ -92,49 +92,49 @@ class CategoryController extends Controller // get journals for entire period: /** @var GroupCollectorInterface $collector */ - $collector = app(GroupCollectorInterface::class); + $collector = app(GroupCollectorInterface::class); $collector->setRange($start, $end)->withAccountInformation(); $collector->setXorAccounts($accounts)->withCategoryInformation(); $collector->setTypes([TransactionType::WITHDRAWAL, TransactionType::RECONCILIATION]); - $journals = $collector->getExtractedJournals(); + $journals = $collector->getExtractedJournals(); /** @var array $journal */ foreach ($journals as $journal) { - $currencyId = (int)$journal['currency_id']; - $currency = $currencies[$currencyId] ?? $this->currencyRepos->find($currencyId); - $currencies[$currencyId] = $currency; - $categoryName = null === $journal['category_name'] ? (string)trans('firefly.no_category') : $journal['category_name']; - $amount = app('steam')->positive($journal['amount']); - $nativeAmount = $converter->convert($default, $currency, $journal['date'], $amount); - $key = sprintf('%s-%s', $categoryName, $currency->code); + $currencyId = (int)$journal['currency_id']; + $currency = $currencies[$currencyId] ?? $this->currencyRepos->find($currencyId); + $currencies[$currencyId] = $currency; + $categoryName = null === $journal['category_name'] ? (string)trans('firefly.no_category') : $journal['category_name']; + $amount = app('steam')->positive($journal['amount']); + $nativeAmount = $converter->convert($default, $currency, $journal['date'], $amount); + $key = sprintf('%s-%s', $categoryName, $currency->code); if ((int)$journal['foreign_currency_id'] === $default->id) { $nativeAmount = app('steam')->positive($journal['foreign_amount']); } // create arrays $return[$key] ??= [ - 'label' => $categoryName, - 'currency_id' => (string)$currency->id, - 'currency_code' => $currency->code, - 'currency_name' => $currency->name, - 'currency_symbol' => $currency->symbol, - 'currency_decimal_places' => $currency->decimal_places, + 'label' => $categoryName, + 'currency_id' => (string)$currency->id, + 'currency_code' => $currency->code, + 'currency_name' => $currency->name, + 'currency_symbol' => $currency->symbol, + 'currency_decimal_places' => $currency->decimal_places, 'native_currency_id' => (string)$default->id, 'native_currency_code' => $default->code, 'native_currency_name' => $default->name, 'native_currency_symbol' => $default->symbol, 'native_currency_decimal_places' => $default->decimal_places, - 'period' => null, - 'start' => $start->toAtomString(), - 'end' => $end->toAtomString(), - 'amount' => '0', - 'native_amount' => '0', + 'period' => null, + 'start' => $start->toAtomString(), + 'end' => $end->toAtomString(), + 'amount' => '0', + 'native_amount' => '0', ]; // add monies $return[$key]['amount'] = bcadd($return[$key]['amount'], $amount); $return[$key]['native_amount'] = bcadd($return[$key]['native_amount'], $nativeAmount); } - $return = array_values($return); + $return = array_values($return); // order by native amount usort($return, static function (array $a, array $b) { diff --git a/app/Api/V2/Controllers/Controller.php b/app/Api/V2/Controllers/Controller.php index ea9a2b28c5..13e15d8494 100644 --- a/app/Api/V2/Controllers/Controller.php +++ b/app/Api/V2/Controllers/Controller.php @@ -69,11 +69,11 @@ class Controller extends BaseController final protected function jsonApiList(string $key, LengthAwarePaginator $paginator, AbstractTransformer $transformer): array { - $manager = new Manager(); - $baseUrl = request()->getSchemeAndHttpHost().'/api/v2'; + $manager = new Manager(); + $baseUrl = request()->getSchemeAndHttpHost().'/api/v2'; $manager->setSerializer(new JsonApiSerializer($baseUrl)); - $objects = $paginator->getCollection(); + $objects = $paginator->getCollection(); // the transformer, at this point, needs to collect information that ALL items in the collection // require, like meta-data and stuff like that, and save it for later. @@ -93,8 +93,8 @@ class Controller extends BaseController final protected function jsonApiObject(string $key, array|Model $object, AbstractTransformer $transformer): array { // create some objects: - $manager = new Manager(); - $baseUrl = request()->getSchemeAndHttpHost().'/api/v2'; + $manager = new Manager(); + $baseUrl = request()->getSchemeAndHttpHost().'/api/v2'; $manager->setSerializer(new JsonApiSerializer($baseUrl)); $transformer->collectMetaData(new Collection([$object])); @@ -112,7 +112,7 @@ class Controller extends BaseController */ private function getParameters(): ParameterBag { - $bag = new ParameterBag(); + $bag = new ParameterBag(); $bag->set('limit', 50); try { diff --git a/app/Api/V2/Controllers/Model/Bill/IndexController.php b/app/Api/V2/Controllers/Model/Bill/IndexController.php index 21e544fff2..3ddc846b36 100644 --- a/app/Api/V2/Controllers/Model/Bill/IndexController.php +++ b/app/Api/V2/Controllers/Model/Bill/IndexController.php @@ -48,7 +48,7 @@ class IndexController extends Controller $this->repository = app(BillRepositoryInterface::class); // new way of user group validation - $userGroup = $this->validateUserGroup($request); + $userGroup = $this->validateUserGroup($request); if (null !== $userGroup) { $this->repository->setUserGroup($userGroup); } diff --git a/app/Api/V2/Controllers/Model/Bill/ShowController.php b/app/Api/V2/Controllers/Model/Bill/ShowController.php index 863ed81a25..db6d59e420 100644 --- a/app/Api/V2/Controllers/Model/Bill/ShowController.php +++ b/app/Api/V2/Controllers/Model/Bill/ShowController.php @@ -48,7 +48,7 @@ class ShowController extends Controller $this->repository = app(BillRepositoryInterface::class); // new way of user group validation - $userGroup = $this->validateUserGroup($request); + $userGroup = $this->validateUserGroup($request); if (null !== $userGroup) { $this->repository->setUserGroup($userGroup); } diff --git a/app/Api/V2/Controllers/Model/Bill/SumController.php b/app/Api/V2/Controllers/Model/Bill/SumController.php index c9e9111ca8..76dd2dca96 100644 --- a/app/Api/V2/Controllers/Model/Bill/SumController.php +++ b/app/Api/V2/Controllers/Model/Bill/SumController.php @@ -46,7 +46,7 @@ class SumController extends Controller function ($request, $next) { $this->repository = app(BillRepositoryInterface::class); - $userGroup = $this->validateUserGroup($request); + $userGroup = $this->validateUserGroup($request); if (null !== $userGroup) { $this->repository->setUserGroup($userGroup); } diff --git a/app/Api/V2/Controllers/Model/Budget/IndexController.php b/app/Api/V2/Controllers/Model/Budget/IndexController.php index 845c574863..a1b7ab41c6 100644 --- a/app/Api/V2/Controllers/Model/Budget/IndexController.php +++ b/app/Api/V2/Controllers/Model/Budget/IndexController.php @@ -55,9 +55,9 @@ class IndexController extends Controller */ public function index(): JsonResponse { - $pageSize = $this->parameters->get('limit'); - $collection = $this->repository->getActiveBudgets(); - $total = $collection->count(); + $pageSize = $this->parameters->get('limit'); + $collection = $this->repository->getActiveBudgets(); + $total = $collection->count(); $collection->slice($pageSize * $this->parameters->get('page'), $pageSize); $paginator = new LengthAwarePaginator($collection, $total, $pageSize, $this->parameters->get('page')); diff --git a/app/Api/V2/Controllers/Model/BudgetLimit/IndexController.php b/app/Api/V2/Controllers/Model/BudgetLimit/IndexController.php index 924823a5e5..c0c27c83e0 100644 --- a/app/Api/V2/Controllers/Model/BudgetLimit/IndexController.php +++ b/app/Api/V2/Controllers/Model/BudgetLimit/IndexController.php @@ -52,9 +52,9 @@ class IndexController extends Controller */ public function index(Budget $budget): JsonResponse { - $pageSize = $this->parameters->get('limit'); - $collection = $this->repository->getBudgetLimits($budget); - $total = $collection->count(); + $pageSize = $this->parameters->get('limit'); + $collection = $this->repository->getBudgetLimits($budget); + $total = $collection->count(); $collection->slice($pageSize * $this->parameters->get('page'), $pageSize); $paginator = new LengthAwarePaginator($collection, $total, $pageSize, $this->parameters->get('page')); diff --git a/app/Api/V2/Controllers/Model/PiggyBank/IndexController.php b/app/Api/V2/Controllers/Model/PiggyBank/IndexController.php index a294633eab..bdad3f4cf1 100644 --- a/app/Api/V2/Controllers/Model/PiggyBank/IndexController.php +++ b/app/Api/V2/Controllers/Model/PiggyBank/IndexController.php @@ -47,7 +47,7 @@ class IndexController extends Controller function ($request, $next) { $this->repository = app(PiggyBankRepositoryInterface::class); - $userGroup = $this->validateUserGroup($request); + $userGroup = $this->validateUserGroup($request); if (null !== $userGroup) { $this->repository->setUserGroup($userGroup); } diff --git a/app/Api/V2/Controllers/Model/Transaction/StoreController.php b/app/Api/V2/Controllers/Model/Transaction/StoreController.php index 476f163cde..d41596d714 100644 --- a/app/Api/V2/Controllers/Model/Transaction/StoreController.php +++ b/app/Api/V2/Controllers/Model/Transaction/StoreController.php @@ -97,28 +97,28 @@ class StoreController extends Controller throw new ValidationException($validator); // @phpstan-ignore-line } app('preferences')->mark(); - $applyRules = $data['apply_rules'] ?? true; - $fireWebhooks = $data['fire_webhooks'] ?? true; + $applyRules = $data['apply_rules'] ?? true; + $fireWebhooks = $data['fire_webhooks'] ?? true; event(new StoredTransactionGroup($transactionGroup, $applyRules, $fireWebhooks)); /** @var User $admin */ - $admin = auth()->user(); + $admin = auth()->user(); // use new group collector: /** @var GroupCollectorInterface $collector */ - $collector = app(GroupCollectorInterface::class); + $collector = app(GroupCollectorInterface::class); $collector ->setUser($admin) // filter on transaction group. ->setTransactionGroup($transactionGroup) ; - $selectedGroup = $collector->getGroups()->first(); + $selectedGroup = $collector->getGroups()->first(); if (null === $selectedGroup) { throw new FireflyException('200032: Cannot find transaction. Possibly, a rule deleted this transaction after its creation.'); } - $transformer = new TransactionGroupTransformer(); + $transformer = new TransactionGroupTransformer(); $transformer->setParameters($this->parameters); return response() diff --git a/app/Api/V2/Controllers/Summary/BasicController.php b/app/Api/V2/Controllers/Summary/BasicController.php index a6cc4ddced..41ee356342 100644 --- a/app/Api/V2/Controllers/Summary/BasicController.php +++ b/app/Api/V2/Controllers/Summary/BasicController.php @@ -76,7 +76,7 @@ class BasicController extends Controller $this->currencyRepos = app(CurrencyRepositoryInterface::class); $this->opsRepository = app(OperationsRepositoryInterface::class); - $userGroup = $this->validateUserGroup($request); + $userGroup = $this->validateUserGroup($request); if (null !== $userGroup) { $this->abRepository->setUserGroup($userGroup); $this->accountRepository->setUserGroup($userGroup); @@ -101,8 +101,8 @@ class BasicController extends Controller public function basic(DateRequest $request): JsonResponse { // parameters for boxes: - $start = $this->parameters->get('start'); - $end = $this->parameters->get('end'); + $start = $this->parameters->get('start'); + $end = $this->parameters->get('end'); // balance information: $balanceData = $this->getBalanceInformation($start, $end); @@ -136,13 +136,13 @@ class BasicController extends Controller */ private function getBalanceInformation(Carbon $start, Carbon $end): array { - $object = new SummaryBalanceGrouped(); - $default = app('amount')->getDefaultCurrency(); + $object = new SummaryBalanceGrouped(); + $default = app('amount')->getDefaultCurrency(); $object->setDefault($default); /** @var User $user */ - $user = auth()->user(); + $user = auth()->user(); // collect income of user using the new group collector. /** @var GroupCollectorInterface $collector */ @@ -157,7 +157,7 @@ class BasicController extends Controller ->setRange($start, $end) ; - $set = $collector->getExtractedJournals(); + $set = $collector->getExtractedJournals(); $object->groupTransactions('income', $set); // collect expenses of user using the new group collector. @@ -172,7 +172,7 @@ class BasicController extends Controller ->setTypes([TransactionType::WITHDRAWAL]) ->setRange($start, $end) ; - $set = $collector->getExtractedJournals(); + $set = $collector->getExtractedJournals(); $object->groupTransactions('expense', $set); return $object->groupData(); @@ -187,7 +187,7 @@ class BasicController extends Controller $paidAmount = $this->billRepository->sumPaidInRange($start, $end); $unpaidAmount = $this->billRepository->sumUnpaidInRange($start, $end); - $return = []; + $return = []; /** * @var array $info @@ -247,14 +247,14 @@ class BasicController extends Controller { Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__)); app('log')->debug('Now in getLeftToSpendInfo'); - $return = []; - $today = today(config('app.timezone')); - $available = $this->abRepository->getAvailableBudgetWithCurrency($start, $end); - $budgets = $this->budgetRepository->getActiveBudgets(); - $spent = $this->opsRepository->listExpenses($start, $end, null, $budgets); - $default = app('amount')->getDefaultCurrency(); - $currencies = []; - $converter = new ExchangeRateConverter(); + $return = []; + $today = today(config('app.timezone')); + $available = $this->abRepository->getAvailableBudgetWithCurrency($start, $end); + $budgets = $this->budgetRepository->getActiveBudgets(); + $spent = $this->opsRepository->listExpenses($start, $end, null, $budgets); + $default = app('amount')->getDefaultCurrency(); + $currencies = []; + $converter = new ExchangeRateConverter(); // native info: $nativeLeft = [ @@ -280,8 +280,8 @@ class BasicController extends Controller */ foreach ($spent as $currencyId => $row) { app('log')->debug(sprintf('Processing spent array in currency #%d', $currencyId)); - $spent = '0'; - $spentNative = '0'; + $spent = '0'; + $spentNative = '0'; // get the sum from the array of transactions (double loop but who cares) /** @var array $budget */ @@ -298,8 +298,8 @@ class BasicController extends Controller if ((int)$journal['foreign_currency_id'] === $default->id) { $amountNative = $journal['foreign_amount']; } - $spent = bcadd($spent, $amount); - $spentNative = bcadd($spentNative, $amountNative); + $spent = bcadd($spent, $amount); + $spentNative = bcadd($spentNative, $amountNative); } app('log')->debug(sprintf('Total spent in budget "%s" is %s', $budget['name'], $spent)); } @@ -315,9 +315,9 @@ class BasicController extends Controller app('log')->debug(sprintf('Amount left is %s', $left)); // how much left per day? - $days = $today->diffInDays($end) + 1; - $perDay = '0'; - $perDayNative = '0'; + $days = $today->diffInDays($end) + 1; + $perDay = '0'; + $perDayNative = '0'; if (0 !== $days && bccomp($left, '0') > -1) { $perDay = bcdiv($left, (string)$days); } @@ -326,7 +326,7 @@ class BasicController extends Controller } // left - $return[] = [ + $return[] = [ 'key' => sprintf('left-to-spend-in-%s', $row['currency_code']), 'value' => $left, 'currency_id' => (string)$row['currency_id'], @@ -335,10 +335,10 @@ class BasicController extends Controller 'currency_decimal_places' => (int)$row['currency_decimal_places'], ]; // left (native) - $nativeLeft['value'] = $leftNative; + $nativeLeft['value'] = $leftNative; // left per day: - $return[] = [ + $return[] = [ 'key' => sprintf('left-per-day-to-spend-in-%s', $row['currency_code']), 'value' => $perDay, 'currency_id' => (string)$row['currency_id'], @@ -348,10 +348,10 @@ class BasicController extends Controller ]; // left per day (native) - $nativePerDay['value'] = $perDayNative; + $nativePerDay['value'] = $perDayNative; } - $return[] = $nativeLeft; - $return[] = $nativePerDay; + $return[] = $nativeLeft; + $return[] = $nativePerDay; $converter->summarize(); return $return; @@ -360,8 +360,8 @@ class BasicController extends Controller private function getNetWorthInfo(Carbon $start, Carbon $end): array { /** @var UserGroup $userGroup */ - $userGroup = auth()->user()->userGroup; - $date = today(config('app.timezone'))->startOfDay(); + $userGroup = auth()->user()->userGroup; + $date = today(config('app.timezone'))->startOfDay(); // start and end in the future? use $end if ($this->notInDateRange($date, $start, $end)) { /** @var Carbon $date */ @@ -371,12 +371,12 @@ class BasicController extends Controller /** @var NetWorthInterface $netWorthHelper */ $netWorthHelper = app(NetWorthInterface::class); $netWorthHelper->setUserGroup($userGroup); - $allAccounts = $this->accountRepository->getActiveAccountsByType( + $allAccounts = $this->accountRepository->getActiveAccountsByType( [AccountType::ASSET, AccountType::DEFAULT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::DEBT] ); // filter list on preference of being included. - $filtered = $allAccounts->filter( + $filtered = $allAccounts->filter( function (Account $account) { $includeNetWorth = $this->accountRepository->getMetaValue($account, 'include_net_worth'); @@ -384,10 +384,10 @@ class BasicController extends Controller } ); - $netWorthSet = $netWorthHelper->byAccounts($filtered, $date); - $return = []; + $netWorthSet = $netWorthHelper->byAccounts($filtered, $date); + $return = []; // in native amount - $return[] = [ + $return[] = [ 'key' => 'net-worth-in-native', 'value' => $netWorthSet['native']['balance'], 'currency_id' => (string)$netWorthSet['native']['currency_id'], diff --git a/app/Api/V2/Controllers/Summary/NetWorthController.php b/app/Api/V2/Controllers/Summary/NetWorthController.php index 40ea958419..52921a98f7 100644 --- a/app/Api/V2/Controllers/Summary/NetWorthController.php +++ b/app/Api/V2/Controllers/Summary/NetWorthController.php @@ -51,7 +51,7 @@ class NetWorthController extends Controller $this->netWorth = app(NetWorthInterface::class); $this->repository = app(AccountRepositoryInterface::class); // new way of user group validation - $userGroup = $this->validateUserGroup($request); + $userGroup = $this->validateUserGroup($request); if (null !== $userGroup) { $this->netWorth->setUserGroup($userGroup); $this->repository->setUserGroup($userGroup); @@ -81,7 +81,7 @@ class NetWorthController extends Controller ); // skip accounts that should not be in the net worth - $result = $this->netWorth->byAccounts($filtered, $date); + $result = $this->netWorth->byAccounts($filtered, $date); return response()->api($result); } diff --git a/app/Api/V2/Controllers/Transaction/List/AccountController.php b/app/Api/V2/Controllers/Transaction/List/AccountController.php index d216255e90..56f9c612e1 100644 --- a/app/Api/V2/Controllers/Transaction/List/AccountController.php +++ b/app/Api/V2/Controllers/Transaction/List/AccountController.php @@ -47,9 +47,9 @@ class AccountController extends Controller public function list(ListRequest $request, Account $account): JsonResponse { // collect transactions: - $page = $request->getPage(); - $page = max($page, 1); - $pageSize = $this->parameters->get('limit'); + $page = $request->getPage(); + $page = max($page, 1); + $pageSize = $this->parameters->get('limit'); /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); @@ -60,8 +60,8 @@ class AccountController extends Controller ->setTypes($request->getTransactionTypes()) ; - $start = $request->getStartDate(); - $end = $request->getEndDate(); + $start = $request->getStartDate(); + $end = $request->getEndDate(); if (null !== $start) { app('log')->debug(sprintf('Set start date to %s', $start->toIso8601String())); $collector->setStart($start); diff --git a/app/Api/V2/Controllers/Transaction/List/TransactionController.php b/app/Api/V2/Controllers/Transaction/List/TransactionController.php index db23b4df73..8da62504a0 100644 --- a/app/Api/V2/Controllers/Transaction/List/TransactionController.php +++ b/app/Api/V2/Controllers/Transaction/List/TransactionController.php @@ -37,9 +37,9 @@ class TransactionController extends Controller public function list(ListRequest $request): JsonResponse { // collect transactions: - $pageSize = $this->parameters->get('limit'); - $page = $request->getPage(); - $page = max($page, 1); + $pageSize = $this->parameters->get('limit'); + $page = $request->getPage(); + $page = max($page, 1); /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); @@ -50,8 +50,8 @@ class TransactionController extends Controller ->setTypes($request->getTransactionTypes()) ; - $start = $this->parameters->get('start'); - $end = $this->parameters->get('end'); + $start = $this->parameters->get('start'); + $end = $this->parameters->get('end'); if (null !== $start) { $collector->setStart($start); } diff --git a/app/Api/V2/Controllers/UserGroup/DestroyController.php b/app/Api/V2/Controllers/UserGroup/DestroyController.php index 519b3e1ba1..216d00b9e9 100644 --- a/app/Api/V2/Controllers/UserGroup/DestroyController.php +++ b/app/Api/V2/Controllers/UserGroup/DestroyController.php @@ -54,7 +54,7 @@ class DestroyController extends Controller public function destroy(UserGroup $userGroup): JsonResponse { /** @var User $user */ - $user = auth()->user(); + $user = auth()->user(); // to access this function: must be group owner or sysadmin. // need owner role or system owner role to delete user group. $access = $user->hasSpecificRoleInGroup($userGroup, UserRoleEnum::OWNER) || $user->hasRole('owner'); diff --git a/app/Api/V2/Controllers/UserGroup/ShowController.php b/app/Api/V2/Controllers/UserGroup/ShowController.php index 903a5eed28..3701ab81b4 100644 --- a/app/Api/V2/Controllers/UserGroup/ShowController.php +++ b/app/Api/V2/Controllers/UserGroup/ShowController.php @@ -53,8 +53,8 @@ class ShowController extends Controller public function index(): JsonResponse { - $collection = new Collection(); - $pageSize = $this->parameters->get('limit'); + $collection = new Collection(); + $pageSize = $this->parameters->get('limit'); // if the user has the system owner role, get all. Otherwise, get only the users' groups. if (!auth()->user()->hasRole('owner')) { $collection = $this->repository->get(); @@ -62,8 +62,8 @@ class ShowController extends Controller if (auth()->user()->hasRole('owner')) { $collection = $this->repository->getAll(); } - $count = $collection->count(); - $userGroups = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); + $count = $collection->count(); + $userGroups = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); $paginator = new LengthAwarePaginator($userGroups, $count, $pageSize, $this->parameters->get('page')); $transformer = new UserGroupTransformer(); diff --git a/app/Api/V2/Request/Model/Transaction/StoreRequest.php b/app/Api/V2/Request/Model/Transaction/StoreRequest.php index 271f5fbd9d..3cb6b3c292 100644 --- a/app/Api/V2/Request/Model/Transaction/StoreRequest.php +++ b/app/Api/V2/Request/Model/Transaction/StoreRequest.php @@ -175,7 +175,7 @@ class StoreRequest extends FormRequest public function withValidator(Validator $validator): void { /** @var User $user */ - $user = auth()->user(); + $user = auth()->user(); /** @var UserGroup $userGroup */ $userGroup = $this->getUserGroup(); @@ -223,9 +223,9 @@ class StoreRequest extends FormRequest foreach ($this->get('transactions') as $transaction) { $object = new NullArrayObject($transaction); $return[] = [ - 'type' => $this->clearString($object['type']), - 'date' => $this->dateFromValue($object['date']), - 'order' => $this->integerFromValue((string)$object['order']), + 'type' => $this->clearString($object['type']), + 'date' => $this->dateFromValue($object['date']), + 'order' => $this->integerFromValue((string)$object['order']), 'currency_id' => $this->integerFromValue((string)$object['currency_id']), 'currency_code' => $this->clearString((string)$object['currency_code']), @@ -284,21 +284,21 @@ class StoreRequest extends FormRequest 'bunq_payment_id' => $this->clearString((string)$object['bunq_payment_id']), 'external_url' => $this->clearString((string)$object['external_url']), - 'sepa_cc' => $this->clearString((string)$object['sepa_cc']), - 'sepa_ct_op' => $this->clearString((string)$object['sepa_ct_op']), - 'sepa_ct_id' => $this->clearString((string)$object['sepa_ct_id']), - 'sepa_db' => $this->clearString((string)$object['sepa_db']), - 'sepa_country' => $this->clearString((string)$object['sepa_country']), - 'sepa_ep' => $this->clearString((string)$object['sepa_ep']), - 'sepa_ci' => $this->clearString((string)$object['sepa_ci']), - 'sepa_batch_id' => $this->clearString((string)$object['sepa_batch_id']), + 'sepa_cc' => $this->clearString((string)$object['sepa_cc']), + 'sepa_ct_op' => $this->clearString((string)$object['sepa_ct_op']), + 'sepa_ct_id' => $this->clearString((string)$object['sepa_ct_id']), + 'sepa_db' => $this->clearString((string)$object['sepa_db']), + 'sepa_country' => $this->clearString((string)$object['sepa_country']), + 'sepa_ep' => $this->clearString((string)$object['sepa_ep']), + 'sepa_ci' => $this->clearString((string)$object['sepa_ci']), + 'sepa_batch_id' => $this->clearString((string)$object['sepa_batch_id']), // custom date fields. Must be Carbon objects. Presence is optional. - 'interest_date' => $this->dateFromValue($object['interest_date']), - 'book_date' => $this->dateFromValue($object['book_date']), - 'process_date' => $this->dateFromValue($object['process_date']), - 'due_date' => $this->dateFromValue($object['due_date']), - 'payment_date' => $this->dateFromValue($object['payment_date']), - 'invoice_date' => $this->dateFromValue($object['invoice_date']), + 'interest_date' => $this->dateFromValue($object['interest_date']), + 'book_date' => $this->dateFromValue($object['book_date']), + 'process_date' => $this->dateFromValue($object['process_date']), + 'due_date' => $this->dateFromValue($object['due_date']), + 'payment_date' => $this->dateFromValue($object['payment_date']), + 'invoice_date' => $this->dateFromValue($object['invoice_date']), ]; } diff --git a/app/Api/V2/Response/Sum/AutoSum.php b/app/Api/V2/Response/Sum/AutoSum.php index 6a0903e466..6ed1faa73e 100644 --- a/app/Api/V2/Response/Sum/AutoSum.php +++ b/app/Api/V2/Response/Sum/AutoSum.php @@ -46,10 +46,10 @@ class AutoSum /** @var Model $object */ foreach ($objects as $object) { /** @var TransactionCurrency $currency */ - $currency = $getCurrency($object); + $currency = $getCurrency($object); /** @var string $amount */ - $amount = $getSum($object); + $amount = $getSum($object); $return[$currency->id] ??= [ 'id' => (string)$currency->id,