From b8774a7af3f61f80f5a851e28b23a0f43a653ec6 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 18 Oct 2020 08:00:49 +0200 Subject: [PATCH] Code cleanup [skip ci] --- .../Autocomplete/CurrencyController.php | 2 +- .../Autocomplete/PiggyBankController.php | 8 +- .../Chart/AvailableBudgetController.php | 1 - .../V1/Controllers/Chart/BudgetController.php | 176 ++++++------ .../Controllers/Chart/CategoryController.php | 14 +- .../V1/Controllers/Data/DestroyController.php | 98 +++---- .../Search/TransactionController.php | 2 +- app/Api/V1/Middleware/ApiDemoUser.php | 1 - app/Api/V1/Requests/AccountUpdateRequest.php | 1 + .../V1/Requests/AttachmentStoreRequest.php | 1 + .../V1/Requests/AttachmentUpdateRequest.php | 1 + .../V1/Requests/AvailableBudgetRequest.php | 1 + app/Api/V1/Requests/BillRequest.php | 1 + app/Api/V1/Requests/BudgetStoreRequest.php | 1 + app/Api/V1/Requests/BudgetUpdateRequest.php | 1 + app/Api/V1/Requests/CategoryRequest.php | 1 + app/Api/V1/Requests/ConfigurationRequest.php | 1 + app/Api/V1/Requests/CurrencyRequest.php | 1 + app/Api/V1/Requests/DataDestroyRequest.php | 1 + app/Api/V1/Requests/DateRequest.php | 1 + app/Api/V1/Requests/LinkTypeRequest.php | 1 + .../V1/Requests/ObjectGroupUpdateRequest.php | 1 + app/Api/V1/Requests/PiggyBankStoreRequest.php | 1 + .../V1/Requests/RecurrenceStoreRequest.php | 101 +++---- .../V1/Requests/RecurrenceUpdateRequest.php | 100 +++---- app/Api/V1/Requests/RuleGroupRequest.php | 1 + app/Api/V1/Requests/RuleGroupTestRequest.php | 46 ++- .../V1/Requests/RuleGroupTriggerRequest.php | 29 +- app/Api/V1/Requests/RuleStoreRequest.php | 102 +++---- app/Api/V1/Requests/RuleTestRequest.php | 36 +-- app/Api/V1/Requests/RuleTriggerRequest.php | 36 +-- app/Api/V1/Requests/RuleUpdateRequest.php | 115 ++++---- app/Api/V1/Requests/TagStoreRequest.php | 1 + app/Api/V1/Requests/TagUpdateRequest.php | 1 + .../V1/Requests/TransactionLinkRequest.php | 1 + .../V1/Requests/TransactionStoreRequest.php | 200 ++++++------- .../V1/Requests/TransactionUpdateRequest.php | 266 +++++++++--------- app/Api/V1/Requests/UserStoreRequest.php | 1 + app/Api/V1/Requests/UserUpdateRequest.php | 1 + 39 files changed, 683 insertions(+), 671 deletions(-) diff --git a/app/Api/V1/Controllers/Autocomplete/CurrencyController.php b/app/Api/V1/Controllers/Autocomplete/CurrencyController.php index 1e8f67827d..5f17ca3bb2 100644 --- a/app/Api/V1/Controllers/Autocomplete/CurrencyController.php +++ b/app/Api/V1/Controllers/Autocomplete/CurrencyController.php @@ -89,7 +89,7 @@ class CurrencyController extends Controller */ public function currencies(AutocompleteRequest $request): JsonResponse { - $data = $request->getData(); + $data = $request->getData(); $collection = $this->repository->searchCurrency($data['query'], $data['limit']); $result = []; diff --git a/app/Api/V1/Controllers/Autocomplete/PiggyBankController.php b/app/Api/V1/Controllers/Autocomplete/PiggyBankController.php index 47ef2259c9..fc2c682a91 100644 --- a/app/Api/V1/Controllers/Autocomplete/PiggyBankController.php +++ b/app/Api/V1/Controllers/Autocomplete/PiggyBankController.php @@ -76,7 +76,7 @@ class PiggyBankController extends Controller /** @var PiggyBank $piggy */ foreach ($piggies as $piggy) { - $currency = $this->accountRepository->getAccountCurrency($piggy->account) ?? $defaultCurrency; + $currency = $this->accountRepository->getAccountCurrency($piggy->account) ?? $defaultCurrency; $response[] = [ 'id' => $piggy->id, 'name' => $piggy->name, @@ -103,9 +103,9 @@ class PiggyBankController extends Controller $response = []; /** @var PiggyBank $piggy */ foreach ($piggies as $piggy) { - $currency = $this->accountRepository->getAccountCurrency($piggy->account) ?? $defaultCurrency; - $currentAmount = $this->piggyRepository->getRepetition($piggy)->currentamount ?? '0'; - $response[] = [ + $currency = $this->accountRepository->getAccountCurrency($piggy->account) ?? $defaultCurrency; + $currentAmount = $this->piggyRepository->getRepetition($piggy)->currentamount ?? '0'; + $response[] = [ 'id' => $piggy->id, 'name' => $piggy->name, 'name_with_balance' => sprintf( diff --git a/app/Api/V1/Controllers/Chart/AvailableBudgetController.php b/app/Api/V1/Controllers/Chart/AvailableBudgetController.php index dc05304d6e..e299a504f4 100644 --- a/app/Api/V1/Controllers/Chart/AvailableBudgetController.php +++ b/app/Api/V1/Controllers/Chart/AvailableBudgetController.php @@ -31,7 +31,6 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Budget\OperationsRepositoryInterface; use FireflyIII\User; use Illuminate\Http\JsonResponse; -use Illuminate\Support\Collection; /** * Class AvailableBudgetController diff --git a/app/Api/V1/Controllers/Chart/BudgetController.php b/app/Api/V1/Controllers/Chart/BudgetController.php index 2dd4a953f2..4e153e0161 100644 --- a/app/Api/V1/Controllers/Chart/BudgetController.php +++ b/app/Api/V1/Controllers/Chart/BudgetController.php @@ -131,93 +131,6 @@ class BudgetController extends Controller return $arr; } - /** - * @param array $budgetNames - * @param array $currencyNames - * - * @return array - */ - private function createSets(array $budgetNames, array $currencyNames): array - { - $return = []; - foreach ($currencyNames as $currencyName) { - $entries = []; - foreach ($budgetNames as $budgetName) { - $label = sprintf('%s (%s)', $budgetName, $currencyName); - $entries[$label] = '0'; - } - - // left - $return['left'] = [ - 'label' => sprintf('%s (%s)', trans('firefly.left'), $currencyName), - 'data_type' => 'left', - 'currency_name' => $currencyName, - 'type' => 'bar', - 'yAxisID' => 0, // 0, 1, 2 - 'entries' => $entries, - ]; - - // spent_capped - $return['spent_capped'] = [ - 'label' => sprintf('%s (%s)', trans('firefly.spent'), $currencyName), - 'data_type' => 'spent_capped', - 'currency_name' => $currencyName, - 'type' => 'bar', - 'yAxisID' => 0, // 0, 1, 2 - 'entries' => $entries, - ]; - - // overspent - $return['overspent'] = [ - 'label' => sprintf('%s (%s)', trans('firefly.overspent'), $currencyName), - 'data_type' => 'overspent', - 'currency_name' => $currencyName, - 'type' => 'bar', - 'yAxisID' => 0, // 0, 1, 2 - 'entries' => $entries, - ]; - - } - - return $return; - } - - /** - * @param array $basic - * @param array $sets - * - * @return array - */ - private function fillSets(array $basic, array $sets): array - { - foreach ($sets as $set) { - $label = $set['label']; - $basic['spent_capped']['entries'][$label] = $set['entries']['spent_capped']; - $basic['left']['entries'][$label] = $set['entries']['left']; - $basic['overspent']['entries'][$label] = $set['entries']['overspent']; - } - - return $basic; - } - - /** - * @param array $expenses - * - * @return array - */ - private function filterNulls(array $expenses): array - { - $return = []; - /** @var array|null $arr */ - foreach ($expenses as $arr) { - if ([] !== $arr) { - $return[] = $arr; - } - } - - return $return; - } - /** * @param Budget $budget * @param Carbon $start @@ -288,10 +201,97 @@ class BudgetController extends Controller $return['entries']['spent'] = $sumSpent; $return['entries']['amount'] = $limit->amount; $return['entries']['spent_capped'] = 1 === bccomp($sumSpent, $limit->amount) ? $limit->amount : $sumSpent; - $return['entries']['left'] = 1 === bccomp($limit->amount, $sumSpent) ? bcadd($set['sum'], $limit->amount) : '0'; // left + $return['entries']['left'] = 1 === bccomp($limit->amount, $sumSpent) ? bcadd($set['sum'], $limit->amount) : '0'; // left $return['entries']['overspent'] = 1 === bccomp($limit->amount, $sumSpent) ? '0' : bcmul(bcadd($set['sum'], $limit->amount), '-1'); // overspent return $return; } + /** + * @param array $expenses + * + * @return array + */ + private function filterNulls(array $expenses): array + { + $return = []; + /** @var array|null $arr */ + foreach ($expenses as $arr) { + if ([] !== $arr) { + $return[] = $arr; + } + } + + return $return; + } + + /** + * @param array $budgetNames + * @param array $currencyNames + * + * @return array + */ + private function createSets(array $budgetNames, array $currencyNames): array + { + $return = []; + foreach ($currencyNames as $currencyName) { + $entries = []; + foreach ($budgetNames as $budgetName) { + $label = sprintf('%s (%s)', $budgetName, $currencyName); + $entries[$label] = '0'; + } + + // left + $return['left'] = [ + 'label' => sprintf('%s (%s)', trans('firefly.left'), $currencyName), + 'data_type' => 'left', + 'currency_name' => $currencyName, + 'type' => 'bar', + 'yAxisID' => 0, // 0, 1, 2 + 'entries' => $entries, + ]; + + // spent_capped + $return['spent_capped'] = [ + 'label' => sprintf('%s (%s)', trans('firefly.spent'), $currencyName), + 'data_type' => 'spent_capped', + 'currency_name' => $currencyName, + 'type' => 'bar', + 'yAxisID' => 0, // 0, 1, 2 + 'entries' => $entries, + ]; + + // overspent + $return['overspent'] = [ + 'label' => sprintf('%s (%s)', trans('firefly.overspent'), $currencyName), + 'data_type' => 'overspent', + 'currency_name' => $currencyName, + 'type' => 'bar', + 'yAxisID' => 0, // 0, 1, 2 + 'entries' => $entries, + ]; + + } + + return $return; + } + + /** + * @param array $basic + * @param array $sets + * + * @return array + */ + private function fillSets(array $basic, array $sets): array + { + foreach ($sets as $set) { + $label = $set['label']; + $basic['spent_capped']['entries'][$label] = $set['entries']['spent_capped']; + $basic['left']['entries'][$label] = $set['entries']['left']; + $basic['overspent']['entries'][$label] = $set['entries']['overspent']; + } + + return $basic; + } + } diff --git a/app/Api/V1/Controllers/Chart/CategoryController.php b/app/Api/V1/Controllers/Chart/CategoryController.php index 6b88eb1ad6..bb789bd0cc 100644 --- a/app/Api/V1/Controllers/Chart/CategoryController.php +++ b/app/Api/V1/Controllers/Chart/CategoryController.php @@ -88,17 +88,17 @@ class CategoryController extends Controller $end = $dates['end']; - $tempData = []; - $spentWith = $this->opsRepository->listExpenses($start, $end); - $spentWithout = $this->noCatRepository->listExpenses($start, $end); - $categories = []; + $tempData = []; + $spentWith = $this->opsRepository->listExpenses($start, $end); + $spentWithout = $this->noCatRepository->listExpenses($start, $end); + $categories = []; - foreach ([$spentWith, $spentWithout, ] as $set) { + foreach ([$spentWith, $spentWithout,] as $set) { foreach ($set as $currency) { foreach ($currency['categories'] as $category) { - $categories[] = $category['name']; - $outKey = sprintf('%d-e', $currency['currency_id']); + $categories[] = $category['name']; + $outKey = sprintf('%d-e', $currency['currency_id']); $tempData[$outKey] = $tempData[$outKey] ?? [ 'currency_id' => $currency['currency_id'], 'label' => (string) trans('firefly.box_spent_in_currency', ['currency' => $currency['currency_name']]), diff --git a/app/Api/V1/Controllers/Data/DestroyController.php b/app/Api/V1/Controllers/Data/DestroyController.php index 98bbfabc50..830cda1dc4 100644 --- a/app/Api/V1/Controllers/Data/DestroyController.php +++ b/app/Api/V1/Controllers/Data/DestroyController.php @@ -160,31 +160,6 @@ class DestroyController extends Controller return response()->json([], 204); } - /** - * @param array $types - */ - private function destroyAccounts(array $types): void - { - /** @var AccountRepositoryInterface $repository */ - $repository = app(AccountRepositoryInterface::class); - $collection = $repository->getAccountsByType($types); - $service = app(AccountDestroyService::class); - /** @var Account $account */ - foreach ($collection as $account) { - $service->destroy($account, null); - } - } - - /** - * - */ - private function destroyBills(): void - { - /** @var BillRepositoryInterface $repository */ - $repository = app(BillRepositoryInterface::class); - $repository->destroyAll(); - } - /** * */ @@ -206,18 +181,11 @@ class DestroyController extends Controller /** * */ - private function destroyCategories(): void + private function destroyBills(): void { - /** @var CategoryRepositoryInterface $categoryRepos */ - $categoryRepos = app(CategoryRepositoryInterface::class); - $categoryRepos->destroyAll(); - } - - private function destroyObjectGroups(): void - { - /** @var ObjectGroupRepositoryInterface $repository */ - $repository = app(ObjectGroupRepositoryInterface::class); - $repository->deleteAll(); + /** @var BillRepositoryInterface $repository */ + $repository = app(BillRepositoryInterface::class); + $repository->destroyAll(); } /** @@ -230,16 +198,6 @@ class DestroyController extends Controller $repository->destroyAll(); } - /** - * - */ - private function destroyRecurringTransactions(): void - { - /** @var RecurringRepositoryInterface $repository */ - $repository = app(RecurringRepositoryInterface::class); - $repository->destroyAll(); - } - /** * */ @@ -250,6 +208,26 @@ class DestroyController extends Controller $repository->destroyAll(); } + /** + * + */ + private function destroyRecurringTransactions(): void + { + /** @var RecurringRepositoryInterface $repository */ + $repository = app(RecurringRepositoryInterface::class); + $repository->destroyAll(); + } + + /** + * + */ + private function destroyCategories(): void + { + /** @var CategoryRepositoryInterface $categoryRepos */ + $categoryRepos = app(CategoryRepositoryInterface::class); + $categoryRepos->destroyAll(); + } + /** * */ @@ -260,6 +238,28 @@ class DestroyController extends Controller $tagRepository->destroyAll(); } + private function destroyObjectGroups(): void + { + /** @var ObjectGroupRepositoryInterface $repository */ + $repository = app(ObjectGroupRepositoryInterface::class); + $repository->deleteAll(); + } + + /** + * @param array $types + */ + private function destroyAccounts(array $types): void + { + /** @var AccountRepositoryInterface $repository */ + $repository = app(AccountRepositoryInterface::class); + $collection = $repository->getAccountsByType($types); + $service = app(AccountDestroyService::class); + /** @var Account $account */ + foreach ($collection as $account) { + $service->destroy($account, null); + } + } + /** * @param array $types */ @@ -267,10 +267,10 @@ class DestroyController extends Controller { /** @var JournalRepositoryInterface $repository */ $repository = app(JournalRepositoryInterface::class); - $journals = $repository->findByType($types); - $service = app(JournalDestroyService::class); + $journals = $repository->findByType($types); + $service = app(JournalDestroyService::class); /** @var TransactionJournal $journal */ - foreach($journals as $journal) { + foreach ($journals as $journal) { $service->destroy($journal); } } diff --git a/app/Api/V1/Controllers/Search/TransactionController.php b/app/Api/V1/Controllers/Search/TransactionController.php index 6db862591e..58766005b7 100644 --- a/app/Api/V1/Controllers/Search/TransactionController.php +++ b/app/Api/V1/Controllers/Search/TransactionController.php @@ -45,7 +45,7 @@ class TransactionController extends Controller */ public function search(Request $request, SearchInterface $searcher): JsonResponse { - $manager = $this->getManager(); + $manager = $this->getManager(); $fullQuery = (string) $request->get('query'); $page = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page'); diff --git a/app/Api/V1/Middleware/ApiDemoUser.php b/app/Api/V1/Middleware/ApiDemoUser.php index 14fc2ac314..fd3b1e35b6 100644 --- a/app/Api/V1/Middleware/ApiDemoUser.php +++ b/app/Api/V1/Middleware/ApiDemoUser.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Middleware; use Closure; -use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\User; use Illuminate\Http\Request; diff --git a/app/Api/V1/Requests/AccountUpdateRequest.php b/app/Api/V1/Requests/AccountUpdateRequest.php index c0976a5f38..af8b807c76 100644 --- a/app/Api/V1/Requests/AccountUpdateRequest.php +++ b/app/Api/V1/Requests/AccountUpdateRequest.php @@ -38,6 +38,7 @@ use Illuminate\Foundation\Http\FormRequest; class AccountUpdateRequest extends FormRequest { use ConvertsDataTypes, AppendsLocationData; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/AttachmentStoreRequest.php b/app/Api/V1/Requests/AttachmentStoreRequest.php index 7b0b901daf..d92ad40e40 100644 --- a/app/Api/V1/Requests/AttachmentStoreRequest.php +++ b/app/Api/V1/Requests/AttachmentStoreRequest.php @@ -35,6 +35,7 @@ use Illuminate\Foundation\Http\FormRequest; class AttachmentStoreRequest extends FormRequest { use ConvertsDataTypes; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/AttachmentUpdateRequest.php b/app/Api/V1/Requests/AttachmentUpdateRequest.php index 910d07d53d..ff09081edd 100644 --- a/app/Api/V1/Requests/AttachmentUpdateRequest.php +++ b/app/Api/V1/Requests/AttachmentUpdateRequest.php @@ -34,6 +34,7 @@ use Illuminate\Foundation\Http\FormRequest; class AttachmentUpdateRequest extends FormRequest { use ConvertsDataTypes; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/AvailableBudgetRequest.php b/app/Api/V1/Requests/AvailableBudgetRequest.php index 01b09cd798..328abf0f3c 100644 --- a/app/Api/V1/Requests/AvailableBudgetRequest.php +++ b/app/Api/V1/Requests/AvailableBudgetRequest.php @@ -34,6 +34,7 @@ use Illuminate\Foundation\Http\FormRequest; class AvailableBudgetRequest extends FormRequest { use ConvertsDataTypes; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/BillRequest.php b/app/Api/V1/Requests/BillRequest.php index 79d4d89548..e0a97bc9e8 100644 --- a/app/Api/V1/Requests/BillRequest.php +++ b/app/Api/V1/Requests/BillRequest.php @@ -39,6 +39,7 @@ use Illuminate\Validation\Validator; class BillRequest extends FormRequest { use ConvertsDataTypes; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/BudgetStoreRequest.php b/app/Api/V1/Requests/BudgetStoreRequest.php index 812d7f4f8e..b41ff703ca 100644 --- a/app/Api/V1/Requests/BudgetStoreRequest.php +++ b/app/Api/V1/Requests/BudgetStoreRequest.php @@ -37,6 +37,7 @@ use Illuminate\Validation\Validator; class BudgetStoreRequest extends FormRequest { use ConvertsDataTypes, ValidatesAutoBudgetRequest; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/BudgetUpdateRequest.php b/app/Api/V1/Requests/BudgetUpdateRequest.php index e7bf86c17f..6ccdd9681c 100644 --- a/app/Api/V1/Requests/BudgetUpdateRequest.php +++ b/app/Api/V1/Requests/BudgetUpdateRequest.php @@ -37,6 +37,7 @@ use Illuminate\Validation\Validator; class BudgetUpdateRequest extends FormRequest { use ConvertsDataTypes, ValidatesAutoBudgetRequest; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/CategoryRequest.php b/app/Api/V1/Requests/CategoryRequest.php index ebeae6a766..6360ddc152 100644 --- a/app/Api/V1/Requests/CategoryRequest.php +++ b/app/Api/V1/Requests/CategoryRequest.php @@ -36,6 +36,7 @@ use Illuminate\Foundation\Http\FormRequest; class CategoryRequest extends FormRequest { use ConvertsDataTypes; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/ConfigurationRequest.php b/app/Api/V1/Requests/ConfigurationRequest.php index 93f68c2598..2d86a1bfbc 100644 --- a/app/Api/V1/Requests/ConfigurationRequest.php +++ b/app/Api/V1/Requests/ConfigurationRequest.php @@ -36,6 +36,7 @@ use Illuminate\Foundation\Http\FormRequest; class ConfigurationRequest extends FormRequest { use ConvertsDataTypes; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/CurrencyRequest.php b/app/Api/V1/Requests/CurrencyRequest.php index 7d50a94ed7..1b694114f8 100644 --- a/app/Api/V1/Requests/CurrencyRequest.php +++ b/app/Api/V1/Requests/CurrencyRequest.php @@ -37,6 +37,7 @@ use Illuminate\Foundation\Http\FormRequest; class CurrencyRequest extends FormRequest { use ConvertsDataTypes; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/DataDestroyRequest.php b/app/Api/V1/Requests/DataDestroyRequest.php index 8513099869..f55a645917 100644 --- a/app/Api/V1/Requests/DataDestroyRequest.php +++ b/app/Api/V1/Requests/DataDestroyRequest.php @@ -32,6 +32,7 @@ use Illuminate\Foundation\Http\FormRequest; class DataDestroyRequest extends FormRequest { use ConvertsDataTypes; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/DateRequest.php b/app/Api/V1/Requests/DateRequest.php index 63cd80b69c..a329ae9a18 100644 --- a/app/Api/V1/Requests/DateRequest.php +++ b/app/Api/V1/Requests/DateRequest.php @@ -36,6 +36,7 @@ use Illuminate\Foundation\Http\FormRequest; class DateRequest extends FormRequest { use ConvertsDataTypes; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/LinkTypeRequest.php b/app/Api/V1/Requests/LinkTypeRequest.php index c0d42b3e74..ba55cc964f 100644 --- a/app/Api/V1/Requests/LinkTypeRequest.php +++ b/app/Api/V1/Requests/LinkTypeRequest.php @@ -37,6 +37,7 @@ use Illuminate\Validation\Rule; class LinkTypeRequest extends FormRequest { use ConvertsDataTypes; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/ObjectGroupUpdateRequest.php b/app/Api/V1/Requests/ObjectGroupUpdateRequest.php index cc306ed14e..16ee295312 100644 --- a/app/Api/V1/Requests/ObjectGroupUpdateRequest.php +++ b/app/Api/V1/Requests/ObjectGroupUpdateRequest.php @@ -35,6 +35,7 @@ use Illuminate\Foundation\Http\FormRequest; class ObjectGroupUpdateRequest extends FormRequest { use ConvertsDataTypes; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/PiggyBankStoreRequest.php b/app/Api/V1/Requests/PiggyBankStoreRequest.php index a6d627cccc..9cdf005d94 100644 --- a/app/Api/V1/Requests/PiggyBankStoreRequest.php +++ b/app/Api/V1/Requests/PiggyBankStoreRequest.php @@ -35,6 +35,7 @@ use Illuminate\Foundation\Http\FormRequest; class PiggyBankStoreRequest extends FormRequest { use ConvertsDataTypes; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/RecurrenceStoreRequest.php b/app/Api/V1/Requests/RecurrenceStoreRequest.php index 40da7f863b..01e6d9b344 100644 --- a/app/Api/V1/Requests/RecurrenceStoreRequest.php +++ b/app/Api/V1/Requests/RecurrenceStoreRequest.php @@ -40,6 +40,7 @@ use Illuminate\Validation\Validator; class RecurrenceStoreRequest extends FormRequest { use ConvertsDataTypes, RecurrenceValidation, TransactionValidation, CurrencyValidation, GetRecurrenceData; + /** * Authorize logged in users. * @@ -83,6 +84,56 @@ class RecurrenceStoreRequest extends FormRequest ]; } + /** + * Returns the transaction data as it is found in the submitted data. It's a complex method according to code + * standards but it just has a lot of ??-statements because of the fields that may or may not exist. + * + * @return array + */ + private function getTransactionData(): array + { + $return = []; + // transaction data: + /** @var array $transactions */ + $transactions = $this->get('transactions'); + if (null === $transactions) { + return []; + } + /** @var array $transaction */ + foreach ($transactions as $transaction) { + $return[] = $this->getSingleRecurrenceData($transaction); + } + + return $return; + } + + /** + * Returns the repetition data as it is found in the submitted data. + * + * @return array + */ + private function getRepetitionData(): array + { + $return = []; + // repetition data: + /** @var array $repetitions */ + $repetitions = $this->get('repetitions'); + if (null === $repetitions) { + return []; + } + /** @var array $repetition */ + foreach ($repetitions as $repetition) { + $return[] = [ + 'type' => $repetition['type'], + 'moment' => $repetition['moment'], + 'skip' => (int) $repetition['skip'], + 'weekend' => (int) $repetition['weekend'], + ]; + } + + return $return; + } + /** * The rules that the incoming request must be matched against. * @@ -150,54 +201,4 @@ class RecurrenceStoreRequest extends FormRequest } ); } - - /** - * Returns the repetition data as it is found in the submitted data. - * - * @return array - */ - private function getRepetitionData(): array - { - $return = []; - // repetition data: - /** @var array $repetitions */ - $repetitions = $this->get('repetitions'); - if (null === $repetitions) { - return []; - } - /** @var array $repetition */ - foreach ($repetitions as $repetition) { - $return[] = [ - 'type' => $repetition['type'], - 'moment' => $repetition['moment'], - 'skip' => (int) $repetition['skip'], - 'weekend' => (int) $repetition['weekend'], - ]; - } - - return $return; - } - - /** - * Returns the transaction data as it is found in the submitted data. It's a complex method according to code - * standards but it just has a lot of ??-statements because of the fields that may or may not exist. - * - * @return array - */ - private function getTransactionData(): array - { - $return = []; - // transaction data: - /** @var array $transactions */ - $transactions = $this->get('transactions'); - if (null === $transactions) { - return []; - } - /** @var array $transaction */ - foreach ($transactions as $transaction) { - $return[] = $this->getSingleRecurrenceData($transaction); - } - - return $return; - } } diff --git a/app/Api/V1/Requests/RecurrenceUpdateRequest.php b/app/Api/V1/Requests/RecurrenceUpdateRequest.php index b39f9718fe..bfcccbffdc 100644 --- a/app/Api/V1/Requests/RecurrenceUpdateRequest.php +++ b/app/Api/V1/Requests/RecurrenceUpdateRequest.php @@ -85,6 +85,56 @@ class RecurrenceUpdateRequest extends FormRequest ]; } + /** + * Returns the transaction data as it is found in the submitted data. It's a complex method according to code + * standards but it just has a lot of ??-statements because of the fields that may or may not exist. + * + * @return array + */ + private function getTransactionData(): array + { + $return = []; + // transaction data: + /** @var array $transactions */ + $transactions = $this->get('transactions'); + if (null === $transactions) { + return []; + } + /** @var array $transaction */ + foreach ($transactions as $transaction) { + $return[] = $this->getSingleRecurrenceData($transaction); + } + + return $return; + } + + /** + * Returns the repetition data as it is found in the submitted data. + * + * @return array + */ + private function getRepetitionData(): array + { + $return = []; + // repetition data: + /** @var array $repetitions */ + $repetitions = $this->get('repetitions'); + if (null === $repetitions) { + return []; + } + /** @var array $repetition */ + foreach ($repetitions as $repetition) { + $return[] = [ + 'type' => $repetition['type'], + 'moment' => $repetition['moment'], + 'skip' => (int) $repetition['skip'], + 'weekend' => (int) $repetition['weekend'], + ]; + } + + return $return; + } + /** * The rules that the incoming request must be matched against. * @@ -153,54 +203,4 @@ class RecurrenceUpdateRequest extends FormRequest } ); } - - /** - * Returns the repetition data as it is found in the submitted data. - * - * @return array - */ - private function getRepetitionData(): array - { - $return = []; - // repetition data: - /** @var array $repetitions */ - $repetitions = $this->get('repetitions'); - if (null === $repetitions) { - return []; - } - /** @var array $repetition */ - foreach ($repetitions as $repetition) { - $return[] = [ - 'type' => $repetition['type'], - 'moment' => $repetition['moment'], - 'skip' => (int) $repetition['skip'], - 'weekend' => (int) $repetition['weekend'], - ]; - } - - return $return; - } - - /** - * Returns the transaction data as it is found in the submitted data. It's a complex method according to code - * standards but it just has a lot of ??-statements because of the fields that may or may not exist. - * - * @return array - */ - private function getTransactionData(): array - { - $return = []; - // transaction data: - /** @var array $transactions */ - $transactions = $this->get('transactions'); - if (null === $transactions) { - return []; - } - /** @var array $transaction */ - foreach ($transactions as $transaction) { - $return[] = $this->getSingleRecurrenceData($transaction); - } - - return $return; - } } diff --git a/app/Api/V1/Requests/RuleGroupRequest.php b/app/Api/V1/Requests/RuleGroupRequest.php index 53374a6a88..b55de2194a 100644 --- a/app/Api/V1/Requests/RuleGroupRequest.php +++ b/app/Api/V1/Requests/RuleGroupRequest.php @@ -37,6 +37,7 @@ use Illuminate\Foundation\Http\FormRequest; class RuleGroupRequest extends FormRequest { use ConvertsDataTypes; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/RuleGroupTestRequest.php b/app/Api/V1/Requests/RuleGroupTestRequest.php index bc9f0edf94..25853aa49f 100644 --- a/app/Api/V1/Requests/RuleGroupTestRequest.php +++ b/app/Api/V1/Requests/RuleGroupTestRequest.php @@ -26,13 +26,9 @@ namespace FireflyIII\Api\V1\Requests; use Carbon\Carbon; -use FireflyIII\Models\Account; -use FireflyIII\Models\AccountType; -use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Support\Request\ConvertsDataTypes; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Support\Collection; -use Log; /** * Class RuleGroupTestRequest @@ -64,27 +60,6 @@ class RuleGroupTestRequest extends FormRequest ]; } - /** - * @return array - */ - public function rules(): array - { - return [ - 'start' => 'date', - 'end' => 'date|after:start', - 'accounts' => '', - 'accounts.*' => 'exists:accounts,id|belongsToUser:accounts', - ]; - } - - /** - * @return Collection - */ - private function getAccounts(): string - { - return (string) $this->query('accounts'); - } - /** * @param string $field * @@ -98,4 +73,25 @@ class RuleGroupTestRequest extends FormRequest return $result; } + /** + * @return Collection + */ + private function getAccounts(): string + { + return (string) $this->query('accounts'); + } + + /** + * @return array + */ + public function rules(): array + { + return [ + 'start' => 'date', + 'end' => 'date|after:start', + 'accounts' => '', + 'accounts.*' => 'exists:accounts,id|belongsToUser:accounts', + ]; + } + } diff --git a/app/Api/V1/Requests/RuleGroupTriggerRequest.php b/app/Api/V1/Requests/RuleGroupTriggerRequest.php index 6c2f2b75ea..c14e353ee6 100644 --- a/app/Api/V1/Requests/RuleGroupTriggerRequest.php +++ b/app/Api/V1/Requests/RuleGroupTriggerRequest.php @@ -26,13 +26,8 @@ namespace FireflyIII\Api\V1\Requests; use Carbon\Carbon; -use FireflyIII\Models\Account; -use FireflyIII\Models\AccountType; -use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Support\Request\ConvertsDataTypes; use Illuminate\Foundation\Http\FormRequest; -use Illuminate\Support\Collection; -use Log; /** * Class RuleGroupTriggerRequest @@ -65,14 +60,14 @@ class RuleGroupTriggerRequest extends FormRequest } /** - * @return array + * @param string $field + * + * @return Carbon|null */ - public function rules(): array + private function getDate(string $field): ?Carbon { - return [ - 'start' => 'date', - 'end' => 'date|after:start', - ]; + /** @var Carbon $result */ + return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field)); } /** @@ -84,14 +79,14 @@ class RuleGroupTriggerRequest extends FormRequest } /** - * @param string $field - * - * @return Carbon|null + * @return array */ - private function getDate(string $field): ?Carbon + public function rules(): array { - /** @var Carbon $result */ - return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field)); + return [ + 'start' => 'date', + 'end' => 'date|after:start', + ]; } } diff --git a/app/Api/V1/Requests/RuleStoreRequest.php b/app/Api/V1/Requests/RuleStoreRequest.php index 7a1a06c4a9..fff904c06f 100644 --- a/app/Api/V1/Requests/RuleStoreRequest.php +++ b/app/Api/V1/Requests/RuleStoreRequest.php @@ -83,6 +83,48 @@ class RuleStoreRequest extends FormRequest ]; } + /** + * @return array + */ + private function getRuleTriggers(): array + { + $triggers = $this->get('triggers'); + $return = []; + if (is_array($triggers)) { + foreach ($triggers as $trigger) { + $return[] = [ + 'type' => $trigger['type'], + 'value' => $trigger['value'], + 'active' => $this->convertBoolean((string) ($trigger['active'] ?? 'false')), + 'stop_processing' => $this->convertBoolean((string) ($trigger['stop_processing'] ?? 'false')), + ]; + } + } + + return $return; + } + + /** + * @return array + */ + private function getRuleActions(): array + { + $actions = $this->get('actions'); + $return = []; + if (is_array($actions)) { + foreach ($actions as $action) { + $return[] = [ + 'type' => $action['type'], + 'value' => $action['value'], + 'active' => $this->convertBoolean((string) ($action['active'] ?? 'false')), + 'stop_processing' => $this->convertBoolean((string) ($action['stop_processing'] ?? 'false')), + ]; + } + } + + return $return; + } + /** * The rules that the incoming request must be matched against. * @@ -134,21 +176,6 @@ class RuleStoreRequest extends FormRequest ); } - /** - * Adds an error to the validator when there are no repetitions in the array of data. - * - * @param Validator $validator - */ - protected function atLeastOneAction(Validator $validator): void - { - $data = $validator->getData(); - $actions = $data['actions'] ?? []; - // need at least one trigger - if (0 === count($actions)) { - $validator->errors()->add('title', (string) trans('validation.at_least_one_action')); - } - } - /** * Adds an error to the validator when there are no repetitions in the array of data. * @@ -165,44 +192,17 @@ class RuleStoreRequest extends FormRequest } /** - * @return array + * Adds an error to the validator when there are no repetitions in the array of data. + * + * @param Validator $validator */ - private function getRuleActions(): array + protected function atLeastOneAction(Validator $validator): void { - $actions = $this->get('actions'); - $return = []; - if (is_array($actions)) { - foreach ($actions as $action) { - $return[] = [ - 'type' => $action['type'], - 'value' => $action['value'], - 'active' => $this->convertBoolean((string) ($action['active'] ?? 'false')), - 'stop_processing' => $this->convertBoolean((string) ($action['stop_processing'] ?? 'false')), - ]; - } + $data = $validator->getData(); + $actions = $data['actions'] ?? []; + // need at least one trigger + if (0 === count($actions)) { + $validator->errors()->add('title', (string) trans('validation.at_least_one_action')); } - - return $return; - } - - /** - * @return array - */ - private function getRuleTriggers(): array - { - $triggers = $this->get('triggers'); - $return = []; - if (is_array($triggers)) { - foreach ($triggers as $trigger) { - $return[] = [ - 'type' => $trigger['type'], - 'value' => $trigger['value'], - 'active' => $this->convertBoolean((string) ($trigger['active'] ?? 'false')), - 'stop_processing' => $this->convertBoolean((string) ($trigger['stop_processing'] ?? 'false')), - ]; - } - } - - return $return; } } diff --git a/app/Api/V1/Requests/RuleTestRequest.php b/app/Api/V1/Requests/RuleTestRequest.php index c823b35585..e2b6c9de2c 100644 --- a/app/Api/V1/Requests/RuleTestRequest.php +++ b/app/Api/V1/Requests/RuleTestRequest.php @@ -62,24 +62,12 @@ class RuleTestRequest extends FormRequest } /** - * @return array + * @return int */ - public function rules(): array + private function getPage(): int { - return [ - 'start' => 'date', - 'end' => 'date|after:start', - 'accounts' => '', - 'accounts.*' => 'required|exists:accounts,id|belongsToUser:accounts', - ]; - } + return 0 === (int) $this->query('page') ? 1 : (int) $this->query('page'); - /** - * @return string - */ - private function getAccounts(): string - { - return (string) $this->query('accounts'); } /** @@ -96,12 +84,24 @@ class RuleTestRequest extends FormRequest } /** - * @return int + * @return string */ - private function getPage(): int + private function getAccounts(): string { - return 0 === (int) $this->query('page') ? 1 : (int) $this->query('page'); + return (string) $this->query('accounts'); + } + /** + * @return array + */ + public function rules(): array + { + return [ + 'start' => 'date', + 'end' => 'date|after:start', + 'accounts' => '', + 'accounts.*' => 'required|exists:accounts,id|belongsToUser:accounts', + ]; } } diff --git a/app/Api/V1/Requests/RuleTriggerRequest.php b/app/Api/V1/Requests/RuleTriggerRequest.php index 407d9de810..cbb30c53ab 100644 --- a/app/Api/V1/Requests/RuleTriggerRequest.php +++ b/app/Api/V1/Requests/RuleTriggerRequest.php @@ -59,6 +59,24 @@ class RuleTriggerRequest extends FormRequest ]; } + /** + * @param string $field + * + * @return Carbon|null + */ + private function getDate(string $field): ?Carbon + { + return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field)); + } + + /** + * @return string + */ + private function getAccounts(): string + { + return (string) $this->query('accounts'); + } + /** * @return array */ @@ -72,22 +90,4 @@ class RuleTriggerRequest extends FormRequest ]; } - /** - * @return string - */ - private function getAccounts(): string - { - return (string) $this->query('accounts'); - } - - /** - * @param string $field - * - * @return Carbon|null - */ - private function getDate(string $field): ?Carbon - { - return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', $this->query($field)); - } - } diff --git a/app/Api/V1/Requests/RuleUpdateRequest.php b/app/Api/V1/Requests/RuleUpdateRequest.php index 4e6aeec134..b275b7d52b 100644 --- a/app/Api/V1/Requests/RuleUpdateRequest.php +++ b/app/Api/V1/Requests/RuleUpdateRequest.php @@ -37,6 +37,7 @@ use function is_array; class RuleUpdateRequest extends FormRequest { use ConvertsDataTypes, GetRuleConfiguration; + /** * Authorize logged in users. * @@ -82,6 +83,54 @@ class RuleUpdateRequest extends FormRequest ]; } + /** + * @return array|null + */ + private function getRuleTriggers(): ?array + { + if (!$this->has('triggers')) { + return null; + } + $triggers = $this->get('triggers'); + $return = []; + if (is_array($triggers)) { + foreach ($triggers as $trigger) { + $return[] = [ + 'type' => $trigger['type'], + 'value' => $trigger['value'], + 'active' => $this->convertBoolean((string) ($trigger['active'] ?? 'false')), + 'stop_processing' => $this->convertBoolean((string) ($trigger['stop_processing'] ?? 'false')), + ]; + } + } + + return $return; + } + + /** + * @return array|null + */ + private function getRuleActions(): ?array + { + if (!$this->has('actions')) { + return null; + } + $actions = $this->get('actions'); + $return = []; + if (is_array($actions)) { + foreach ($actions as $action) { + $return[] = [ + 'type' => $action['type'], + 'value' => $action['value'], + 'active' => $this->convertBoolean((string) ($action['active'] ?? 'false')), + 'stop_processing' => $this->convertBoolean((string) ($action['stop_processing'] ?? 'false')), + ]; + } + } + + return $return; + } + /** * The rules that the incoming request must be matched against. * @@ -134,21 +183,6 @@ class RuleUpdateRequest extends FormRequest ); } - /** - * Adds an error to the validator when there are no repetitions in the array of data. - * - * @param Validator $validator - */ - protected function atLeastOneAction(Validator $validator): void - { - $data = $validator->getData(); - $actions = $data['actions'] ?? null; - // need at least one action - if (is_array($actions) && 0 === count($actions)) { - $validator->errors()->add('title', (string) trans('validation.at_least_one_action')); - } - } - /** * Adds an error to the validator when there are no repetitions in the array of data. * @@ -165,50 +199,17 @@ class RuleUpdateRequest extends FormRequest } /** - * @return array|null + * Adds an error to the validator when there are no repetitions in the array of data. + * + * @param Validator $validator */ - private function getRuleActions(): ?array + protected function atLeastOneAction(Validator $validator): void { - if (!$this->has('actions')) { - return null; + $data = $validator->getData(); + $actions = $data['actions'] ?? null; + // need at least one action + if (is_array($actions) && 0 === count($actions)) { + $validator->errors()->add('title', (string) trans('validation.at_least_one_action')); } - $actions = $this->get('actions'); - $return = []; - if (is_array($actions)) { - foreach ($actions as $action) { - $return[] = [ - 'type' => $action['type'], - 'value' => $action['value'], - 'active' => $this->convertBoolean((string) ($action['active'] ?? 'false')), - 'stop_processing' => $this->convertBoolean((string) ($action['stop_processing'] ?? 'false')), - ]; - } - } - - return $return; - } - - /** - * @return array|null - */ - private function getRuleTriggers(): ?array - { - if (!$this->has('triggers')) { - return null; - } - $triggers = $this->get('triggers'); - $return = []; - if (is_array($triggers)) { - foreach ($triggers as $trigger) { - $return[] = [ - 'type' => $trigger['type'], - 'value' => $trigger['value'], - 'active' => $this->convertBoolean((string) ($trigger['active'] ?? 'false')), - 'stop_processing' => $this->convertBoolean((string) ($trigger['stop_processing'] ?? 'false')), - ]; - } - } - - return $return; } } diff --git a/app/Api/V1/Requests/TagStoreRequest.php b/app/Api/V1/Requests/TagStoreRequest.php index c269357078..724ffa052b 100644 --- a/app/Api/V1/Requests/TagStoreRequest.php +++ b/app/Api/V1/Requests/TagStoreRequest.php @@ -35,6 +35,7 @@ use Illuminate\Foundation\Http\FormRequest; class TagStoreRequest extends FormRequest { use ConvertsDataTypes; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/TagUpdateRequest.php b/app/Api/V1/Requests/TagUpdateRequest.php index 08d87d5261..4798a0dfd0 100644 --- a/app/Api/V1/Requests/TagUpdateRequest.php +++ b/app/Api/V1/Requests/TagUpdateRequest.php @@ -36,6 +36,7 @@ use Illuminate\Foundation\Http\FormRequest; class TagUpdateRequest extends FormRequest { use ConvertsDataTypes; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/TransactionLinkRequest.php b/app/Api/V1/Requests/TransactionLinkRequest.php index 02f260e8e9..c52b9902be 100644 --- a/app/Api/V1/Requests/TransactionLinkRequest.php +++ b/app/Api/V1/Requests/TransactionLinkRequest.php @@ -36,6 +36,7 @@ use Illuminate\Validation\Validator; class TransactionLinkRequest extends FormRequest { use ConvertsDataTypes; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/TransactionStoreRequest.php b/app/Api/V1/Requests/TransactionStoreRequest.php index 2ed203bc07..5f57465c5e 100644 --- a/app/Api/V1/Requests/TransactionStoreRequest.php +++ b/app/Api/V1/Requests/TransactionStoreRequest.php @@ -73,6 +73,106 @@ class TransactionStoreRequest extends FormRequest ]; } + /** + * Get transaction data. + * + * @return array + */ + private function getTransactionData(): array + { + $return = []; + /** + * @var int $index + * @var array $transaction + */ + foreach ($this->get('transactions') as $index => $transaction) { + $object = new NullArrayObject($transaction); + $return[] = [ + 'type' => $this->stringFromValue($object['type']), + 'date' => $this->dateFromValue($object['date']), + 'order' => $this->integerFromValue((string) $object['order']), + + 'currency_id' => $this->integerFromValue((string) $object['currency_id']), + 'currency_code' => $this->stringFromValue($object['currency_code']), + + // foreign currency info: + 'foreign_currency_id' => $this->integerFromValue((string) $object['foreign_currency_id']), + 'foreign_currency_code' => $this->stringFromValue((string) $object['foreign_currency_code']), + + // amount and foreign amount. Cannot be 0. + 'amount' => $this->stringFromValue((string) $object['amount']), + 'foreign_amount' => $this->stringFromValue((string) $object['foreign_amount']), + + // description. + 'description' => $this->stringFromValue($object['description']), + + // source of transaction. If everything is null, assume cash account. + 'source_id' => $this->integerFromValue((string) $object['source_id']), + 'source_name' => $this->stringFromValue((string) $object['source_name']), + 'source_iban' => $this->stringFromValue((string) $object['source_iban']), + 'source_number' => $this->stringFromValue((string) $object['source_number']), + 'source_bic' => $this->stringFromValue((string) $object['source_bic']), + + // destination of transaction. If everything is null, assume cash account. + 'destination_id' => $this->integerFromValue((string) $object['destination_id']), + 'destination_name' => $this->stringFromValue((string) $object['destination_name']), + 'destination_iban' => $this->stringFromValue((string) $object['destination_iban']), + 'destination_number' => $this->stringFromValue((string) $object['destination_number']), + 'destination_bic' => $this->stringFromValue((string) $object['destination_bic']), + + // budget info + 'budget_id' => $this->integerFromValue((string) $object['budget_id']), + 'budget_name' => $this->stringFromValue((string) $object['budget_name']), + + // category info + 'category_id' => $this->integerFromValue((string) $object['category_id']), + 'category_name' => $this->stringFromValue((string) $object['category_name']), + + // journal bill reference. Optional. Will only work for withdrawals + 'bill_id' => $this->integerFromValue((string) $object['bill_id']), + 'bill_name' => $this->stringFromValue((string) $object['bill_name']), + + // piggy bank reference. Optional. Will only work for transfers + 'piggy_bank_id' => $this->integerFromValue((string) $object['piggy_bank_id']), + 'piggy_bank_name' => $this->stringFromValue((string) $object['piggy_bank_name']), + + // some other interesting properties + 'reconciled' => $this->convertBoolean((string) $object['reconciled']), + 'notes' => $this->nlStringFromValue((string) $object['notes']), + 'tags' => $this->arrayFromValue($object['tags']), + + // all custom fields: + 'internal_reference' => $this->stringFromValue((string) $object['internal_reference']), + 'external_id' => $this->stringFromValue((string) $object['external_id']), + 'original_source' => sprintf('ff3-v%s|api-v%s', config('firefly.version'), config('firefly.api_version')), + 'recurrence_id' => $this->integerFromValue($object['recurrence_id']), + 'bunq_payment_id' => $this->stringFromValue((string) $object['bunq_payment_id']), + 'external_uri' => $this->stringFromValue((string) $object['external_uri']), + + 'sepa_cc' => $this->stringFromValue($object['sepa_cc']), + 'sepa_ct_op' => $this->stringFromValue($object['sepa_ct_op']), + 'sepa_ct_id' => $this->stringFromValue($object['sepa_ct_id']), + 'sepa_db' => $this->stringFromValue($object['sepa_db']), + 'sepa_country' => $this->stringFromValue($object['sepa_country']), + 'sepa_ep' => $this->stringFromValue($object['sepa_ep']), + 'sepa_ci' => $this->stringFromValue($object['sepa_ci']), + 'sepa_batch_id' => $this->stringFromValue($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']), + + ]; + } + + return $return; + } + /** * The rules that the incoming request must be matched against. * @@ -199,104 +299,4 @@ class TransactionStoreRequest extends FormRequest } ); } - - /** - * Get transaction data. - * - * @return array - */ - private function getTransactionData(): array - { - $return = []; - /** - * @var int $index - * @var array $transaction - */ - foreach ($this->get('transactions') as $index => $transaction) { - $object = new NullArrayObject($transaction); - $return[] = [ - 'type' => $this->stringFromValue($object['type']), - 'date' => $this->dateFromValue($object['date']), - 'order' => $this->integerFromValue((string) $object['order']), - - 'currency_id' => $this->integerFromValue((string) $object['currency_id']), - 'currency_code' => $this->stringFromValue($object['currency_code']), - - // foreign currency info: - 'foreign_currency_id' => $this->integerFromValue((string) $object['foreign_currency_id']), - 'foreign_currency_code' => $this->stringFromValue((string) $object['foreign_currency_code']), - - // amount and foreign amount. Cannot be 0. - 'amount' => $this->stringFromValue((string) $object['amount']), - 'foreign_amount' => $this->stringFromValue((string) $object['foreign_amount']), - - // description. - 'description' => $this->stringFromValue($object['description']), - - // source of transaction. If everything is null, assume cash account. - 'source_id' => $this->integerFromValue((string) $object['source_id']), - 'source_name' => $this->stringFromValue((string) $object['source_name']), - 'source_iban' => $this->stringFromValue((string) $object['source_iban']), - 'source_number' => $this->stringFromValue((string) $object['source_number']), - 'source_bic' => $this->stringFromValue((string) $object['source_bic']), - - // destination of transaction. If everything is null, assume cash account. - 'destination_id' => $this->integerFromValue((string) $object['destination_id']), - 'destination_name' => $this->stringFromValue((string) $object['destination_name']), - 'destination_iban' => $this->stringFromValue((string) $object['destination_iban']), - 'destination_number' => $this->stringFromValue((string) $object['destination_number']), - 'destination_bic' => $this->stringFromValue((string) $object['destination_bic']), - - // budget info - 'budget_id' => $this->integerFromValue((string) $object['budget_id']), - 'budget_name' => $this->stringFromValue((string) $object['budget_name']), - - // category info - 'category_id' => $this->integerFromValue((string) $object['category_id']), - 'category_name' => $this->stringFromValue((string) $object['category_name']), - - // journal bill reference. Optional. Will only work for withdrawals - 'bill_id' => $this->integerFromValue((string) $object['bill_id']), - 'bill_name' => $this->stringFromValue((string) $object['bill_name']), - - // piggy bank reference. Optional. Will only work for transfers - 'piggy_bank_id' => $this->integerFromValue((string) $object['piggy_bank_id']), - 'piggy_bank_name' => $this->stringFromValue((string) $object['piggy_bank_name']), - - // some other interesting properties - 'reconciled' => $this->convertBoolean((string) $object['reconciled']), - 'notes' => $this->nlStringFromValue((string) $object['notes']), - 'tags' => $this->arrayFromValue($object['tags']), - - // all custom fields: - 'internal_reference' => $this->stringFromValue((string) $object['internal_reference']), - 'external_id' => $this->stringFromValue((string) $object['external_id']), - 'original_source' => sprintf('ff3-v%s|api-v%s', config('firefly.version'), config('firefly.api_version')), - 'recurrence_id' => $this->integerFromValue($object['recurrence_id']), - 'bunq_payment_id' => $this->stringFromValue((string) $object['bunq_payment_id']), - 'external_uri' => $this->stringFromValue((string) $object['external_uri']), - - 'sepa_cc' => $this->stringFromValue($object['sepa_cc']), - 'sepa_ct_op' => $this->stringFromValue($object['sepa_ct_op']), - 'sepa_ct_id' => $this->stringFromValue($object['sepa_ct_id']), - 'sepa_db' => $this->stringFromValue($object['sepa_db']), - 'sepa_country' => $this->stringFromValue($object['sepa_country']), - 'sepa_ep' => $this->stringFromValue($object['sepa_ep']), - 'sepa_ci' => $this->stringFromValue($object['sepa_ci']), - 'sepa_batch_id' => $this->stringFromValue($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']), - - ]; - } - - return $return; - } } diff --git a/app/Api/V1/Requests/TransactionUpdateRequest.php b/app/Api/V1/Requests/TransactionUpdateRequest.php index 1cc70a88ea..7e2e94a0cd 100644 --- a/app/Api/V1/Requests/TransactionUpdateRequest.php +++ b/app/Api/V1/Requests/TransactionUpdateRequest.php @@ -146,6 +146,139 @@ class TransactionUpdateRequest extends FormRequest return $data; } + /** + * Get transaction data. + * + * @return array + */ + private function getTransactionData(): array + { + Log::debug('Now in getTransactionData()'); + $return = []; + /** + * @var int $index + * @var array $transaction + */ + foreach ($this->get('transactions') as $transaction) { + // default response is to update nothing in the transaction: + $current = []; + $current = $this->getIntegerData($current, $transaction); + $current = $this->getStringData($current, $transaction); + $current = $this->getNlStringData($current, $transaction); + $current = $this->getDateData($current, $transaction); + $current = $this->getBooleanData($current, $transaction); + $current = $this->getArrayData($current, $transaction); + $return[] = $current; + } + + return $return; + } + + /** + * For each field, add it to the array if a reference is present in the request: + * + * @param array $current + * + * @return array + */ + private function getIntegerData(array $current, array $transaction): array + { + foreach ($this->integerFields as $fieldName) { + if (array_key_exists($fieldName, $transaction)) { + $current[$fieldName] = $this->integerFromValue((string) $transaction[$fieldName]); + } + } + + return $current; + } + + /** + * @param array $current + * @param array $transaction + * + * @return array + */ + private function getStringData(array $current, array $transaction): array + { + foreach ($this->stringFields as $fieldName) { + if (array_key_exists($fieldName, $transaction)) { + $current[$fieldName] = $this->stringFromValue((string) $transaction[$fieldName]); + } + } + + return $current; + } + + /** + * @param array $current + * @param array $transaction + * + * @return array + */ + private function getNlStringData(array $current, array $transaction): array + { + foreach ($this->textareaFields as $fieldName) { + if (array_key_exists($fieldName, $transaction)) { + $current[$fieldName] = $this->nlStringFromValue((string) $transaction[$fieldName]); + } + } + + return $current; + } + + /** + * @param array $current + * @param array $transaction + * + * @return array + */ + private function getDateData(array $current, array $transaction): array + { + foreach ($this->dateFields as $fieldName) { + Log::debug(sprintf('Now at date field %s', $fieldName)); + if (array_key_exists($fieldName, $transaction)) { + Log::debug(sprintf('New value: "%s"', (string) $transaction[$fieldName])); + $current[$fieldName] = $this->dateFromValue((string) $transaction[$fieldName]); + } + } + + return $current; + } + + /** + * @param array $current + * @param array $transaction + * + * @return array + */ + private function getBooleanData(array $current, array $transaction): array + { + foreach ($this->booleanFields as $fieldName) { + if (array_key_exists($fieldName, $transaction)) { + $current[$fieldName] = $this->convertBoolean((string) $transaction[$fieldName]); + } + } + + return $current; + } + + /** + * @param array $current + * @param array $transaction + * + * @return array + */ + private function getArrayData(array $current, array $transaction): array + { + foreach ($this->arrayFields as $fieldName) { + if (array_key_exists($fieldName, $transaction)) { + $current[$fieldName] = $this->arrayFromValue($transaction[$fieldName]); + } + } + + return $current; + } + /** * The rules that the incoming request must be matched against. * @@ -272,137 +405,4 @@ class TransactionUpdateRequest extends FormRequest } ); } - - /** - * @param array $current - * @param array $transaction - * - * @return array - */ - private function getArrayData(array $current, array $transaction): array - { - foreach ($this->arrayFields as $fieldName) { - if (array_key_exists($fieldName, $transaction)) { - $current[$fieldName] = $this->arrayFromValue($transaction[$fieldName]); - } - } - - return $current; - } - - /** - * @param array $current - * @param array $transaction - * - * @return array - */ - private function getBooleanData(array $current, array $transaction): array - { - foreach ($this->booleanFields as $fieldName) { - if (array_key_exists($fieldName, $transaction)) { - $current[$fieldName] = $this->convertBoolean((string) $transaction[$fieldName]); - } - } - - return $current; - } - - /** - * @param array $current - * @param array $transaction - * - * @return array - */ - private function getDateData(array $current, array $transaction): array - { - foreach ($this->dateFields as $fieldName) { - Log::debug(sprintf('Now at date field %s', $fieldName)); - if (array_key_exists($fieldName, $transaction)) { - Log::debug(sprintf('New value: "%s"', (string) $transaction[$fieldName])); - $current[$fieldName] = $this->dateFromValue((string) $transaction[$fieldName]); - } - } - - return $current; - } - - /** - * For each field, add it to the array if a reference is present in the request: - * - * @param array $current - * - * @return array - */ - private function getIntegerData(array $current, array $transaction): array - { - foreach ($this->integerFields as $fieldName) { - if (array_key_exists($fieldName, $transaction)) { - $current[$fieldName] = $this->integerFromValue((string) $transaction[$fieldName]); - } - } - - return $current; - } - - /** - * @param array $current - * @param array $transaction - * - * @return array - */ - private function getNlStringData(array $current, array $transaction): array - { - foreach ($this->textareaFields as $fieldName) { - if (array_key_exists($fieldName, $transaction)) { - $current[$fieldName] = $this->nlStringFromValue((string) $transaction[$fieldName]); - } - } - - return $current; - } - - /** - * @param array $current - * @param array $transaction - * - * @return array - */ - private function getStringData(array $current, array $transaction): array - { - foreach ($this->stringFields as $fieldName) { - if (array_key_exists($fieldName, $transaction)) { - $current[$fieldName] = $this->stringFromValue((string) $transaction[$fieldName]); - } - } - - return $current; - } - - /** - * Get transaction data. - * - * @return array - */ - private function getTransactionData(): array - { - Log::debug('Now in getTransactionData()'); - $return = []; - /** - * @var int $index - * @var array $transaction - */ - foreach ($this->get('transactions') as $transaction) { - // default response is to update nothing in the transaction: - $current = []; - $current = $this->getIntegerData($current, $transaction); - $current = $this->getStringData($current, $transaction); - $current = $this->getNlStringData($current, $transaction); - $current = $this->getDateData($current, $transaction); - $current = $this->getBooleanData($current, $transaction); - $current = $this->getArrayData($current, $transaction); - $return[] = $current; - } - - return $return; - } } diff --git a/app/Api/V1/Requests/UserStoreRequest.php b/app/Api/V1/Requests/UserStoreRequest.php index cff3d97e47..c68558ce05 100644 --- a/app/Api/V1/Requests/UserStoreRequest.php +++ b/app/Api/V1/Requests/UserStoreRequest.php @@ -35,6 +35,7 @@ use Illuminate\Foundation\Http\FormRequest; class UserStoreRequest extends FormRequest { use ConvertsDataTypes; + /** * Authorize logged in users. * diff --git a/app/Api/V1/Requests/UserUpdateRequest.php b/app/Api/V1/Requests/UserUpdateRequest.php index 5fee8f3e24..8e4a0d6eef 100644 --- a/app/Api/V1/Requests/UserUpdateRequest.php +++ b/app/Api/V1/Requests/UserUpdateRequest.php @@ -35,6 +35,7 @@ use Illuminate\Foundation\Http\FormRequest; class UserUpdateRequest extends FormRequest { use ConvertsDataTypes; + /** * Authorize logged in users. *