From 0b8427f8818d4ec648d98d3995d5aa97441be91e Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 3 Aug 2019 19:17:59 +0200 Subject: [PATCH] Add some TODO's, refactor some code. --- .../V1/Requests/TransactionUpdateRequest.php | 3 +- app/Factory/BudgetFactory.php | 1 + app/Factory/CategoryFactory.php | 3 ++ app/Factory/PiggyBankFactory.php | 3 ++ app/Models/ImportJob.php | 2 - .../Account/AccountRepository.php | 8 +++ app/Repositories/Bill/BillRepository.php | 2 + .../Category/CategoryRepository.php | 3 ++ .../PiggyBank/PiggyBankRepository.php | 3 ++ app/Support/Facades/Steam.php | 1 + app/TransactionRules/Actions/SetBudget.php | 3 ++ app/Validation/FireflyValidator.php | 5 ++ resources/lang/en_US/firefly.php | 52 ++++++++++--------- 13 files changed, 60 insertions(+), 29 deletions(-) diff --git a/app/Api/V1/Requests/TransactionUpdateRequest.php b/app/Api/V1/Requests/TransactionUpdateRequest.php index 603490c3a0..128124737e 100644 --- a/app/Api/V1/Requests/TransactionUpdateRequest.php +++ b/app/Api/V1/Requests/TransactionUpdateRequest.php @@ -248,8 +248,7 @@ class TransactionUpdateRequest extends Request // The currency info must match the accounts involved. // Instead will ignore currency info as much as possible. - // TODO if the transaction_journal_id is empty, some fields are mandatory. - // TODO like the amount! + // TODO if the transaction_journal_id is empty, some fields are mandatory, like the amount! // all journals must have a description //$this->validateDescriptions($validator); diff --git a/app/Factory/BudgetFactory.php b/app/Factory/BudgetFactory.php index d8788c409c..3df3134889 100644 --- a/app/Factory/BudgetFactory.php +++ b/app/Factory/BudgetFactory.php @@ -92,6 +92,7 @@ class BudgetFactory { /** @var Collection $collection */ $collection = $this->user->budgets()->get(); + // TODO no longer need to loop like this /** @var Budget $budget */ foreach ($collection as $budget) { if ($budget->name === $name) { diff --git a/app/Factory/CategoryFactory.php b/app/Factory/CategoryFactory.php index fef42fb49a..8379c5a147 100644 --- a/app/Factory/CategoryFactory.php +++ b/app/Factory/CategoryFactory.php @@ -58,6 +58,9 @@ class CategoryFactory $result = null; /** @var Collection $collection */ $collection = $this->user->categories()->get(); + + // TODO no longer need to loop like this + /** @var Category $category */ foreach ($collection as $category) { if ($category->name === $name) { diff --git a/app/Factory/PiggyBankFactory.php b/app/Factory/PiggyBankFactory.php index 663723a7bb..766c4e8d4e 100644 --- a/app/Factory/PiggyBankFactory.php +++ b/app/Factory/PiggyBankFactory.php @@ -91,6 +91,9 @@ class PiggyBankFactory public function findByName(string $name): ?PiggyBank { $set = $this->user->piggyBanks()->get(); + + // TODO no longer need to loop like this + /** @var PiggyBank $piggy */ foreach ($set as $piggy) { if ($piggy->name === $name) { diff --git a/app/Models/ImportJob.php b/app/Models/ImportJob.php index e48df1d461..fb7aae31bd 100644 --- a/app/Models/ImportJob.php +++ b/app/Models/ImportJob.php @@ -48,8 +48,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @property int id * @property Carbon $created_at * @property Carbon $updated_at - * @property int $id - * @property array|null $extended_status * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Attachment[] $attachments * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob newQuery() diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index ce863f788c..33b97f1eb7 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -157,6 +157,9 @@ class AccountRepository implements AccountRepositoryInterface Log::debug(sprintf('Searching for account named "%s" (of user #%d) of the following type(s)', $name, $this->user->id), ['types' => $types]); $accounts = $query->get(['accounts.*']); + + // TODO no longer need to loop like this + /** @var Account $account */ foreach ($accounts as $account) { if ($account->name === $name) { @@ -308,6 +311,8 @@ class AccountRepository implements AccountRepositoryInterface */ public function getMetaValue(Account $account, string $field): ?string { + // TODO no longer need to loop like this + foreach ($account->accountMeta as $meta) { if ($meta->name === $field) { return (string)$meta->data; @@ -406,6 +411,9 @@ class AccountRepository implements AccountRepositoryInterface /** @var AccountType $type */ $type = AccountType::where('type', AccountType::RECONCILIATION)->first(); $accounts = $this->user->accounts()->where('account_type_id', $type->id)->get(); + + // TODO no longer need to loop like this + /** @var Account $current */ foreach ($accounts as $current) { if ($current->name === $name) { diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php index 2bf4680ea7..228193dd05 100644 --- a/app/Repositories/Bill/BillRepository.php +++ b/app/Repositories/Bill/BillRepository.php @@ -128,6 +128,8 @@ class BillRepository implements BillRepositoryInterface { $bills = $this->user->bills()->get(['bills.*']); + // TODO no longer need to loop like this + /** @var Bill $bill */ foreach ($bills as $bill) { if ($bill->name === $name) { diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php index 771482a788..d44fdffe42 100644 --- a/app/Repositories/Category/CategoryRepository.php +++ b/app/Repositories/Category/CategoryRepository.php @@ -272,6 +272,9 @@ class CategoryRepository implements CategoryRepositoryInterface public function findByName(string $name): ?Category { $categories = $this->user->categories()->get(['categories.*']); + + // TODO no longer need to loop like this + foreach ($categories as $category) { if ($category->name === $name) { return $category; diff --git a/app/Repositories/PiggyBank/PiggyBankRepository.php b/app/Repositories/PiggyBank/PiggyBankRepository.php index fbcfdde080..fd80bca177 100644 --- a/app/Repositories/PiggyBank/PiggyBankRepository.php +++ b/app/Repositories/PiggyBank/PiggyBankRepository.php @@ -199,6 +199,9 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface public function findByName(string $name): ?PiggyBank { $set = $this->user->piggyBanks()->get(['piggy_banks.*']); + + // TODO no longer need to loop like this + /** @var PiggyBank $piggy */ foreach ($set as $piggy) { if ($piggy->name === $name) { diff --git a/app/Support/Facades/Steam.php b/app/Support/Facades/Steam.php index e598027bf5..1de7ed92f1 100644 --- a/app/Support/Facades/Steam.php +++ b/app/Support/Facades/Steam.php @@ -40,6 +40,7 @@ use Illuminate\Support\Facades\Facade; * @method string|null opposite(string $amount = null) * @method int phpBytes(string $string) * @method string positive(string $amount) + * @method array balancesPerCurrencyByAccounts(Collection $accounts, Carbon $date) * * @codeCoverageIgnore */ diff --git a/app/TransactionRules/Actions/SetBudget.php b/app/TransactionRules/Actions/SetBudget.php index ca9b317af0..37816cd281 100644 --- a/app/TransactionRules/Actions/SetBudget.php +++ b/app/TransactionRules/Actions/SetBudget.php @@ -63,6 +63,9 @@ class SetBudget implements ActionInterface $repository->setUser($journal->user); $search = $this->action->action_value; $budgets = $repository->getActiveBudgets(); + + // TODO no longer need to loop like this + $budget = $budgets->filter( static function (Budget $current) use ($search) { return $current->name === $search; diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php index d75712fc36..f5e7daa69f 100644 --- a/app/Validation/FireflyValidator.php +++ b/app/Validation/FireflyValidator.php @@ -269,6 +269,7 @@ class FireflyValidator extends Validator $repository = app(BudgetRepositoryInterface::class); $budgets = $repository->getBudgets(); // count budgets, should have at least one + // TODO no longer need to loop like this $count = $budgets->filter( function (Budget $budget) use ($value) { return $budget->name === $value; @@ -540,6 +541,7 @@ class FireflyValidator extends Validator $value = $this->data['name']; $set = $user->accounts()->where('account_type_id', $type->id)->get(); + // TODO no longer need to loop like this /** @var Account $entry */ foreach ($set as $entry) { if ($entry->name === $value) { @@ -565,6 +567,7 @@ class FireflyValidator extends Validator /** @var Collection $set */ $set = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get(); + // TODO no longer need to loop like this /** @var Account $entry */ foreach ($set as $entry) { if ($entry->name === $value) { @@ -588,6 +591,7 @@ class FireflyValidator extends Validator /** @var Collection $set */ $set = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get(); + // TODO no longer need to loop like this /** @var Account $entry */ foreach ($set as $entry) { // TODO no longer need to loop like this. @@ -621,6 +625,7 @@ class FireflyValidator extends Validator $accountTypeIds = $accountTypes->pluck('id')->toArray(); /** @var Collection $set */ $set = auth()->user()->accounts()->whereIn('account_type_id', $accountTypeIds)->where('id', '!=', $ignore)->get(); + // TODO no longer need to loop like this /** @var Account $entry */ foreach ($set as $entry) { if ($entry->name === $value) { diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index 5556b8af0b..4b73be09bd 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -83,7 +83,7 @@ return [ 'help_for_this_page' => 'Help for this page', 'no_help_could_be_found' => 'No help text could be found.', 'no_help_title' => 'Apologies, an error occurred.', - 'two_factor_welcome' => 'Hello, :user!', + 'two_factor_welcome' => 'Hello!', 'two_factor_enter_code' => 'To continue, please enter your two factor authentication code. Your application can generate it for you.', 'two_factor_code_here' => 'Enter code here', 'two_factor_title' => 'Two factor authentication', @@ -478,30 +478,32 @@ return [ 'pref_custom_fiscal_year_help' => 'In countries that use a financial year other than January 1 to December 31, you can switch this on and specify start / end days of the fiscal year', 'pref_fiscal_year_start_label' => 'Fiscal year start date', 'pref_two_factor_auth' => '2-step verification', - 'pref_two_factor_auth_help' => 'When you enable 2-step verification (also known as two-factor authentication), you add an extra layer of security to your account. You sign in with something you know (your password) and something you have (a verification code). Verification codes are generated by an application on your phone, such as Authy or Google Authenticator.', - 'pref_enable_two_factor_auth' => 'Enable 2-step verification', - 'pref_two_factor_auth_disabled' => '2-step verification code removed and disabled', - 'pref_two_factor_auth_remove_it' => 'Don\'t forget to remove the account from your authentication app!', - 'pref_two_factor_auth_code' => 'Verify code', - 'pref_two_factor_auth_code_help' => 'Scan the QR code with an application on your phone such as Authy or Google Authenticator and enter the generated code.', - 'pref_two_factor_auth_reset_code' => 'Reset verification code', - 'pref_two_factor_auth_disable_2fa' => 'Disable 2FA', - '2fa_use_secret_instead' => 'If you cannot scan the QR code, feel free to use the secret instead: :secret.', - 'pref_save_settings' => 'Save settings', - 'saved_preferences' => 'Preferences saved!', - 'preferences_general' => 'General', - 'preferences_frontpage' => 'Home screen', - 'preferences_security' => 'Security', - 'preferences_layout' => 'Layout', - 'pref_home_show_deposits' => 'Show deposits on the home screen', - 'pref_home_show_deposits_info' => 'The home screen already shows your expense accounts. Should it also show your revenue accounts?', - 'pref_home_do_show_deposits' => 'Yes, show them', - 'successful_count' => 'of which :count successful', - 'list_page_size_title' => 'Page size', - 'list_page_size_help' => 'Any list of things (accounts, transactions, etc) shows at most this many per page.', - 'list_page_size_label' => 'Page size', - 'between_dates' => '(:start and :end)', - 'pref_optional_fields_transaction' => 'Optional fields for transactions', + 'pref_two_factor_auth_help' => 'When you enable 2-step verification (also known as two-factor authentication), you add an extra layer of security to your account. You sign in with something you know (your password) and something you have (a verification code). Verification codes are generated by an application on your phone, such as Authy or Google Authenticator.', + 'pref_enable_two_factor_auth' => 'Enable 2-step verification', + 'pref_two_factor_auth_disabled' => '2-step verification code removed and disabled', + 'pref_two_factor_auth_remove_it' => 'Don\'t forget to remove the account from your authentication app!', + 'pref_two_factor_auth_code' => 'Verify code', + 'pref_two_factor_auth_code_help' => 'Scan the QR code with an application on your phone such as Authy or Google Authenticator and enter the generated code.', + 'pref_two_factor_auth_reset_code' => 'Reset verification code', + 'pref_two_factor_auth_disable_2fa' => 'Disable 2FA', + '2fa_use_secret_instead' => 'If you cannot scan the QR code, feel free to use the secret instead: :secret.', + '2fa_backup_codes' => 'Store these backup codes for access in case you lose your device.', + '2fa_already_enabled' => '2-step verification is already enabled.', + 'pref_save_settings' => 'Save settings', + 'saved_preferences' => 'Preferences saved!', + 'preferences_general' => 'General', + 'preferences_frontpage' => 'Home screen', + 'preferences_security' => 'Security', + 'preferences_layout' => 'Layout', + 'pref_home_show_deposits' => 'Show deposits on the home screen', + 'pref_home_show_deposits_info' => 'The home screen already shows your expense accounts. Should it also show your revenue accounts?', + 'pref_home_do_show_deposits' => 'Yes, show them', + 'successful_count' => 'of which :count successful', + 'list_page_size_title' => 'Page size', + 'list_page_size_help' => 'Any list of things (accounts, transactions, etc) shows at most this many per page.', + 'list_page_size_label' => 'Page size', + 'between_dates' => '(:start and :end)', + 'pref_optional_fields_transaction' => 'Optional fields for transactions', 'pref_optional_fields_transaction_help' => 'By default not all fields are enabled when creating a new transaction (because of the clutter). Below, you can enable these fields if you think they could be useful for you. Of course, any field that is disabled, but already filled in, will be visible regardless of the setting.', 'optional_tj_date_fields' => 'Date fields', 'optional_tj_business_fields' => 'Business fields',