Add some TODO's, refactor some code.

This commit is contained in:
James Cole 2019-08-03 19:17:59 +02:00
parent cf121fea50
commit 0b8427f881
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
13 changed files with 60 additions and 29 deletions

View File

@ -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);

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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()

View File

@ -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) {

View File

@ -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) {

View File

@ -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;

View File

@ -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) {

View File

@ -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
*/

View File

@ -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;

View File

@ -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) {

View File

@ -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',