From 5eca4048668c8abdd8cba458b84216f29300f042 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 4 Jul 2021 19:19:31 +0200 Subject: [PATCH] Fix issue in number formatting. --- .../Budget/BudgetLimitRepositoryInterface.php | 2 +- app/Support/Form/CurrencyForm.php | 4 +-- .../Http/Controllers/PeriodOverview.php | 16 ++++++------ app/Validation/FireflyValidator.php | 25 +++++++++++-------- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/app/Repositories/Budget/BudgetLimitRepositoryInterface.php b/app/Repositories/Budget/BudgetLimitRepositoryInterface.php index c74adb0db1..1f93291dde 100644 --- a/app/Repositories/Budget/BudgetLimitRepositoryInterface.php +++ b/app/Repositories/Budget/BudgetLimitRepositoryInterface.php @@ -72,7 +72,7 @@ interface BudgetLimitRepositoryInterface public function find(Budget $budget, TransactionCurrency $currency, Carbon $start, Carbon $end): ?BudgetLimit; /** -* See reference nr. 11 + * See reference nr. 11 * * @param Carbon|null $start * @param Carbon|null $end diff --git a/app/Support/Form/CurrencyForm.php b/app/Support/Form/CurrencyForm.php index 7299245058..ac7e10cade 100644 --- a/app/Support/Form/CurrencyForm.php +++ b/app/Support/Form/CurrencyForm.php @@ -34,8 +34,6 @@ use Throwable; * Class CurrencyForm * * All currency related form methods. - * -* See reference nr. 22 */ class CurrencyForm { @@ -61,7 +59,7 @@ class CurrencyForm * * @return string */ - protected function currencyField(string $name, string $view, $value = null, array $options = null): string + protected function currencyField(string $name, string $view, mixed $value = null, array $options = null): string { $label = $this->label($name, $options); $options = $this->expandOptionArray($name, $label, $options); diff --git a/app/Support/Http/Controllers/PeriodOverview.php b/app/Support/Http/Controllers/PeriodOverview.php index 9e26079941..90dfed5d71 100644 --- a/app/Support/Http/Controllers/PeriodOverview.php +++ b/app/Support/Http/Controllers/PeriodOverview.php @@ -38,7 +38,7 @@ use Log; /** * Trait PeriodOverview. * -* See reference nr. 36 + * See reference nr. 36 * * - Always request start date and end date. * - Group expenses, income, etc. under this period. @@ -91,7 +91,7 @@ trait PeriodOverview $cache->addProperty('account-show-period-entries'); $cache->addProperty($account->id); if ($cache->has()) { - return $cache->get(); + return $cache->get(); } /** @var array $dates */ $dates = app('navigation')->blockPeriods($start, $end, $range); @@ -284,7 +284,7 @@ trait PeriodOverview $cache->addProperty($category->id); if ($cache->has()) { - return $cache->get(); + return $cache->get(); } /** @var array $dates */ $dates = app('navigation')->blockPeriods($start, $end, $range); @@ -360,7 +360,7 @@ trait PeriodOverview $cache->addProperty('no-budget-period-entries'); if ($cache->has()) { - return $cache->get(); + return $cache->get(); } /** @var array $dates */ @@ -392,7 +392,7 @@ trait PeriodOverview } /** -* See reference nr. 37 + * See reference nr. 37 * * Show period overview for no category view. * @@ -419,7 +419,7 @@ trait PeriodOverview $cache->addProperty('no-category-period-entries'); if ($cache->has()) { - return $cache->get(); + return $cache->get(); } $dates = app('navigation')->blockPeriods($start, $end, $range); @@ -494,7 +494,7 @@ trait PeriodOverview $cache->addProperty('tag-period-entries'); $cache->addProperty($tag->id); if ($cache->has()) { - return $cache->get(); + return $cache->get(); } /** @var array $dates */ $dates = app('navigation')->blockPeriods($start, $end, $range); @@ -568,7 +568,7 @@ trait PeriodOverview $cache->addProperty('transactions-period-entries'); $cache->addProperty($transactionType); if ($cache->has()) { - return $cache->get(); + return $cache->get(); } /** @var array $dates */ $dates = app('navigation')->blockPeriods($start, $end, $range); diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php index 21c85d620f..3e9c85e708 100644 --- a/app/Validation/FireflyValidator.php +++ b/app/Validation/FireflyValidator.php @@ -179,10 +179,13 @@ class FireflyValidator extends Validator '32', '33', '34', '35',]; // take - $first = substr($value, 0, 4); - $last = substr($value, 4); - $iban = $last . $first; - $iban = str_replace($search, $replace, $iban); + $first = substr($value, 0, 4); + $last = substr($value, 4); + $iban = $last . $first; + $iban = trim(str_replace($search, $replace, $iban)); + if (0 === strlen($iban)) { + return false; + } $checksum = bcmod($iban, '97'); return 1 === (int)$checksum; @@ -265,7 +268,7 @@ class FireflyValidator extends Validator $repository = app(BudgetRepositoryInterface::class); $budgets = $repository->getBudgets(); // count budgets, should have at least one -// See reference nr. 102 + // See reference nr. 102 $count = $budgets->filter( function (Budget $budget) use ($value) { return $budget->name === $value; @@ -439,7 +442,7 @@ class FireflyValidator extends Validator */ private function validateAccountAnonymously(): bool { - if (!array_key_exists('user_id',$this->data)) { + if (!array_key_exists('user_id', $this->data)) { return false; } @@ -448,7 +451,7 @@ class FireflyValidator extends Validator $value = $this->data['name']; $set = $user->accounts()->where('account_type_id', $type->id)->get(); -// See reference nr. 103 + // See reference nr. 103 /** @var Account $entry */ foreach ($set as $entry) { if ($entry->name === $value) { @@ -480,7 +483,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(); -// See reference nr. 104 + // See reference nr. 104 /** @var Account $entry */ foreach ($set as $entry) { if ($entry->name === $value) { @@ -504,10 +507,10 @@ class FireflyValidator extends Validator /** @var Collection $set */ $set = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get(); -// See reference nr. 105 + // See reference nr. 105 /** @var Account $entry */ foreach ($set as $entry) { -// See reference nr. 106 + // See reference nr. 106 if ($entry->name === $value) { return false; } @@ -718,7 +721,7 @@ class FireflyValidator extends Validator * @param mixed $value * @param mixed $parameters * -* See reference nr. 107 + * See reference nr. 107 * * @return bool */