Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Code cleanup
James Cole101bcc250e69
diff --git a/app/Support/Navigation.php b/app/Support/Navigation.phpindex 1cd90606d7..2ba2956767 100644--- a/app/Support/Navigation.php+++ b/app/Support/Navigation.php@@ -29,10 +29,10 @@ use FireflyIII\Exceptions\IntervalException;use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;use FireflyIII\Support\Calendar\Calculator;use FireflyIII\Support\Calendar\Periodicity;+use Illuminate\Support\Facades\Log;use Psr\Container\ContainerExceptionInterface;use Psr\Container\NotFoundExceptionInterface;use Throwable;-use Illuminate\Support\Facades\Log;/*** Class Navigation.@@ -89,10 +89,10 @@ class Navigationif (!array_key_exists($repeatFreq, $functionMap)) {Log::error(sprintf(- 'The periodicity %s is unknown. Choose one of available periodicity: %s',- $repeatFreq,- join(', ', array_keys($functionMap))- ));+ 'The periodicity %s is unknown. Choose one of available periodicity: %s',+ $repeatFreq,+ join(', ', array_keys($functionMap))+ ));return $theDate;}@@ -352,12 +352,12 @@ class Navigationpublic function diffInPeriods(string $period, int $skip, Carbon $beginning, Carbon $end): int{Log::debug(sprintf(- 'diffInPeriods: %s (skip: %d), between %s and %s.',- $period,- $skip,- $beginning->format('Y-m-d'),- $end->format('Y-m-d')- ));+ 'diffInPeriods: %s (skip: %d), between %s and %s.',+ $period,+ $skip,+ $beginning->format('Y-m-d'),+ $end->format('Y-m-d')+ ));$map = ['daily' => 'floatDiffInDays','weekly' => 'floatDiffInWeeks',@@ -372,32 +372,33 @@ class Navigation}$func = $map[$period];// first do the diff- $diff = $beginning->$func($end);+ $floatDiff = $beginning->$func($end);+// then correct for quarterly or half-yearif ('quarterly' === $period) {- Log::debug(sprintf('Q: Corrected %f to %f', $diff, $diff / 3));- $diff = $diff / 3;+ Log::debug(sprintf('Q: Corrected %f to %f', $floatDiff, $floatDiff / 3));+ $floatDiff = $floatDiff / 3;}if ('half-year' === $period) {- Log::debug(sprintf('H: Corrected %f to %f', $diff, $diff / 6));- $diff = $diff / 6;+ Log::debug(sprintf('H: Corrected %f to %f', $floatDiff, $floatDiff / 6));+ $floatDiff = $floatDiff / 6;}// then do ceil()- $diff = ceil($diff);+ $diff = ceil($floatDiff);- Log::debug(sprintf('Diff is %f (%d)', $beginning->$func($end), $diff));+ Log::debug(sprintf('Diff is %f periods (%d rounded up)', $floatDiff, $diff));if ($skip > 0) {$parameter = $skip + 1;$diff = ceil($diff / $parameter) * $parameter;Log::debug(sprintf(- 'diffInPeriods: skip is %d, so param is %d, and diff becomes %d',- $skip,- $parameter,- $diff- ));+ 'diffInPeriods: skip is %d, so param is %d, and diff becomes %d',+ $skip,+ $parameter,+ $diff+ ));}return (int)$diff;diff --git a/app/Transformers/BillTransformer.php b/app/Transformers/BillTransformer.phpindex 8c6a9b5e14..f5d13ec85a 100644--- a/app/Transformers/BillTransformer.php+++ b/app/Transformers/BillTransformer.php@@ -360,7 +360,7 @@ class BillTransformer extends AbstractTransformerapp('log')->debug(sprintf('Steps is %d, because addPeriod already adds 1.', $steps));$result = app('navigation')->addPeriod($start, $bill->repeat_freq, $steps);}- app('log')->debug(sprintf('Number of steps is %d, result is %s', $steps, $result->format('Y-m-d')));+ app('log')->debug(sprintf('Number of steps is %d, added to %s, result is %s', $steps, $start->format('Y-m-d'), $result->format('Y-m-d')));return $result;}}diff --git a/tests/integration/Support/NavigationCustomEndOfPeriodTest.php b/tests/integration/Support/NavigationCustomEndOfPeriodTest.phpindex 258629f741..bdada89779 100644--- a/tests/integration/Support/NavigationCustomEndOfPeriodTest.php+++ b/tests/integration/Support/NavigationCustomEndOfPeriodTest.php@@ -38,7 +38,7 @@ class NavigationCustomEndOfPeriodTest extends TestCasepublic function testGivenADateAndCustomFrequencyWhenCalculateTheDateThenReturnsTheEndOfMonthSuccessful(){$from = Carbon::parse('2023-08-05');- $expected = Carbon::parse('2023-09-04');+ $expected = Carbon::parse('2023-09-03');$navigation = new Navigation();$period = $navigation->endOfPeriod($from, 'custom');diff --git a/tests/unit/Support/NavigationAddPeriodTest.php b/tests/unit/Support/NavigationAddPeriodTest.phpindex 1b9bb6b3af..a74be42f73 100644--- a/tests/unit/Support/NavigationAddPeriodTest.php+++ b/tests/unit/Support/NavigationAddPeriodTest.php@@ -138,6 +138,9 @@ class NavigationAddPeriodTest extends TestCase'3M' => ['skip' => 1, 'frequency' => '3M', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(6)],'quarter' => ['skip' => 1, 'frequency' => 'quarter', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(6)],'quarterly' => ['skip' => 1, 'frequency' => 'quarterly', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(6)],+ 'quarter_2' => ['skip' => 2, 'frequency' => 'quarter', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(9)],+ 'quarterly_2' => ['skip' => 2, 'frequency' => 'quarterly', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(9)],+ 'quarter_3' => ['skip' => 2, 'frequency' => 'quarter', 'from' => Carbon::parse('2023-01-01'), 'expected' => Carbon::parse('2023-10-01')],'6M' => ['skip' => 1, 'frequency' => '6M', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(12)],'half-year' => ['skip' => 1, 'frequency' => 'half-year', 'from' => Carbon::now(), 'expected' => Carbon::now()->addMonthsNoOverflow(12)],'year' => ['skip' => 1, 'frequency' => 'year', 'from' => Carbon::now(), 'expected' => Carbon::now()->addYears(2)],