From 80b8e676d0e8857b72537db77eccd704f701c917 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 7 Nov 2023 20:06:56 +0100 Subject: [PATCH] Fix https://github.com/firefly-iii/firefly-iii/issues/8137 --- .ci/php-cs-fixer/composer.lock | 12 ++++++------ app/Api/V2/Controllers/Controller.php | 4 ++-- app/Console/Commands/Correction/FixUnevenAmount.php | 12 +++++++++++- app/Support/Navigation.php | 4 ++-- app/Transformers/BillTransformer.php | 2 +- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.ci/php-cs-fixer/composer.lock b/.ci/php-cs-fixer/composer.lock index cb9e3f8cad..afaf88abaa 100644 --- a/.ci/php-cs-fixer/composer.lock +++ b/.ci/php-cs-fixer/composer.lock @@ -226,16 +226,16 @@ }, { "name": "friendsofphp/php-cs-fixer", - "version": "v3.37.1", + "version": "v3.38.0", "source": { "type": "git", "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", - "reference": "c3fe76976081ab871aa654e872da588077e19679" + "reference": "7e6070026e76aa09d77a47519625c86593fb8e31" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/c3fe76976081ab871aa654e872da588077e19679", - "reference": "c3fe76976081ab871aa654e872da588077e19679", + "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/7e6070026e76aa09d77a47519625c86593fb8e31", + "reference": "7e6070026e76aa09d77a47519625c86593fb8e31", "shasum": "" }, "require": { @@ -307,7 +307,7 @@ ], "support": { "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", - "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.37.1" + "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.38.0" }, "funding": [ { @@ -315,7 +315,7 @@ "type": "github" } ], - "time": "2023-10-29T20:51:23+00:00" + "time": "2023-11-07T08:44:54+00:00" }, { "name": "psr/container", diff --git a/app/Api/V2/Controllers/Controller.php b/app/Api/V2/Controllers/Controller.php index 5ac9a421b1..0be425bb1e 100644 --- a/app/Api/V2/Controllers/Controller.php +++ b/app/Api/V2/Controllers/Controller.php @@ -108,10 +108,10 @@ class Controller extends BaseController } if (null !== $date) { try { - $obj = Carbon::parse($date, config('app.timezone')); + $obj = Carbon::parse((string) $date, config('app.timezone')); } catch (InvalidDateException | InvalidFormatException $e) { // don't care - app('log')->warning(sprintf('Ignored invalid date "%s" in API v2 controller parameter check: %s', substr($date, 0, 20), $e->getMessage())); + app('log')->warning(sprintf('Ignored invalid date "%s" in API v2 controller parameter check: %s', substr((string) $date, 0, 20), $e->getMessage())); } // out of range? set to null. if (null !== $obj && ($obj->year <= 1900 || $obj->year > 2099)) { diff --git a/app/Console/Commands/Correction/FixUnevenAmount.php b/app/Console/Commands/Correction/FixUnevenAmount.php index 10303cd06a..d0d949cf24 100644 --- a/app/Console/Commands/Correction/FixUnevenAmount.php +++ b/app/Console/Commands/Correction/FixUnevenAmount.php @@ -28,7 +28,9 @@ use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; use Illuminate\Console\Command; +use Illuminate\Support\Facades\Log; use stdClass; +use ValueError; /** * Class FixUnevenAmount @@ -69,7 +71,15 @@ class FixUnevenAmount extends Command $count++; continue; } - if (0 !== bccomp((string)$entry->the_sum, '0')) { + $res = -1; + try { + $res = bccomp($sum, '0'); + } catch (ValueError $e) { + $this->friendlyError(sprintf('Could not bccomp("%s", "0").', $sum)); + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); + } + if (0 !== $res) { $message = sprintf( 'Sum of journal #%d is %s instead of zero.', $entry->transaction_journal_id, diff --git a/app/Support/Navigation.php b/app/Support/Navigation.php index 70a32130b2..4f0b0d2210 100644 --- a/app/Support/Navigation.php +++ b/app/Support/Navigation.php @@ -378,11 +378,11 @@ class Navigation // then correct for quarterly or half-year if ('quarterly' === $period) { Log::debug(sprintf('Q: Corrected %f to %f', $floatDiff, $floatDiff / 3)); - $floatDiff = $floatDiff / 3; + $floatDiff /= 3; } if ('half-year' === $period) { Log::debug(sprintf('H: Corrected %f to %f', $floatDiff, $floatDiff / 6)); - $floatDiff = $floatDiff / 6; + $floatDiff /= 6; } // then do ceil() diff --git a/app/Transformers/BillTransformer.php b/app/Transformers/BillTransformer.php index 143e2f3dc4..5f3b4e35b4 100644 --- a/app/Transformers/BillTransformer.php +++ b/app/Transformers/BillTransformer.php @@ -356,7 +356,7 @@ class BillTransformer extends AbstractTransformer $steps = app('navigation')->diffInPeriods($bill->repeat_freq, $bill->skip, $start, $date); $result = clone $start; if ($steps > 0) { - $steps = $steps - 1; + $steps -= 1; app('log')->debug(sprintf('Steps is %d, because addPeriod already adds 1.', $steps)); $result = app('navigation')->addPeriod($start, $bill->repeat_freq, $steps); }