Skip to content

Firefly III: a personal finances manager

Small code cleanup.

James Cole4c2d9e0eee75
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index 3ebecdd310..612661a00f 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -16,4 +16,4 @@ Take the time to read the [installation guide FAQ](https://firefly-iii.github.io
## Pull requests
-I can only accept pull requests against the `develop` branch, never the `master` branch
+I can only accept pull requests against the `develop` branch, never the `master` branch.
diff --git a/app/Generator/Chart/Basic/ChartJsGenerator.php b/app/Generator/Chart/Basic/ChartJsGenerator.php
index 85cff4d4f6..b7588d2da2 100644
--- a/app/Generator/Chart/Basic/ChartJsGenerator.php
+++ b/app/Generator/Chart/Basic/ChartJsGenerator.php
@@ -14,6 +14,7 @@ declare(strict_types = 1);
namespace FireflyIII\Generator\Chart\Basic;
use FireflyIII\Support\ChartColour;
+use Steam;
/**
* Class ChartJsGenerator
@@ -108,11 +109,7 @@ class ChartJsGenerator implements GeneratorInterface
foreach ($data as $key => $value) {
// make larger than 0
- if (bccomp($value, '0') === -1) {
- $value = bcmul($value, '-1');
- }
-
- $chartData['datasets'][0]['data'][] = $value;
+ $chartData['datasets'][0]['data'][] = floatval(Steam::positive($value));
$chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index);
$chartData['labels'][] = $key;
$index++;
diff --git a/app/Helpers/Chart/MetaPieChart.php b/app/Helpers/Chart/MetaPieChart.php
index 4290720405..c2a87fbe95 100644
--- a/app/Helpers/Chart/MetaPieChart.php
+++ b/app/Helpers/Chart/MetaPieChart.php
@@ -21,6 +21,7 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\User;
use Illuminate\Support\Collection;
+use Steam;
/**
* Class MetaPieChart
@@ -268,10 +269,7 @@ class MetaPieChart implements MetaPieChartInterface
$object = $repository->find(intval($objectId));
$names[$objectId] = $object->name;
}
- if (bccomp($amount, '0') === -1) {
- $amount = bcmul($amount, '-1');
- }
-
+ $amount = Steam::positive($amount);
$this->total = bcadd($this->total, $amount);
$chartData[$names[$objectId]] = $amount;
}
diff --git a/app/Import/ImportStorage.php b/app/Import/ImportStorage.php
index 12b5e33a6c..ec68385e0d 100644
--- a/app/Import/ImportStorage.php
+++ b/app/Import/ImportStorage.php
@@ -27,6 +27,7 @@ use FireflyIII\Rules\Processor;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
+use Steam;
/**
* Class ImportStorage
@@ -197,21 +198,6 @@ class ImportStorage
}
- /**
- * @param float $amount
- *
- * @return string
- */
- private function makePositive(float $amount): string
- {
- $amount = strval($amount);
- if (bccomp($amount, '0', 4) === -1) { // left is larger than right
- $amount = bcmul($amount, '-1');
- }
-
- return $amount;
- }
-
/**
* @param $entry
*
@@ -370,7 +356,7 @@ class ImportStorage
$journal = $this->storeJournal($entry);
- $amount = $this->makePositive($entry->fields['amount']);
+ $amount = Steam::positive($entry->fields['amount']);
$accounts = $this->storeAccounts($entry);
// create new transactions. This is something that needs a rewrite for multiple/split transactions.
diff --git a/app/Rules/Triggers/AmountExactly.php b/app/Rules/Triggers/AmountExactly.php
index cef4d8315d..e7984deb02 100644
--- a/app/Rules/Triggers/AmountExactly.php
+++ b/app/Rules/Triggers/AmountExactly.php
@@ -60,7 +60,7 @@ final class AmountExactly extends AbstractTrigger implements TriggerInterface
{
$amount = $journal->destination_amount ?? TransactionJournal::amountPositive($journal);
$compare = $this->triggerValue;
- $result = bccomp($amount, $compare, 4);
+ $result = bccomp($amount, $compare);
if ($result === 0) {
Log::debug(sprintf('RuleTrigger AmountExactly for journal #%d: %d matches %d exactly, so return true', $journal->id, $amount, $compare));
diff --git a/app/Rules/Triggers/AmountLess.php b/app/Rules/Triggers/AmountLess.php
index cbf4e61ac3..1c856c6796 100644
--- a/app/Rules/Triggers/AmountLess.php
+++ b/app/Rules/Triggers/AmountLess.php
@@ -60,7 +60,7 @@ final class AmountLess extends AbstractTrigger implements TriggerInterface
{
$amount = $journal->destination_amount ?? TransactionJournal::amountPositive($journal);
$compare = $this->triggerValue;
- $result = bccomp($amount, $compare, 4);
+ $result = bccomp($amount, $compare);
if ($result === -1) {
Log::debug(sprintf('RuleTrigger AmountLess for journal #%d: %d is less than %d, so return true', $journal->id, $amount, $compare));
diff --git a/app/Rules/Triggers/AmountMore.php b/app/Rules/Triggers/AmountMore.php
index d44cca0071..d8a7ce1643 100644
--- a/app/Rules/Triggers/AmountMore.php
+++ b/app/Rules/Triggers/AmountMore.php
@@ -66,7 +66,7 @@ final class AmountMore extends AbstractTrigger implements TriggerInterface
{
$amount = $journal->destination_amount ?? TransactionJournal::amountPositive($journal);
$compare = $this->triggerValue;
- $result = bccomp($amount, $compare, 4);
+ $result = bccomp($amount, $compare);
if ($result === 1) {
Log::debug(sprintf('RuleTrigger AmountMore for journal #%d: %d is more than %d, so return true', $journal->id, $amount, $compare));
diff --git a/app/Support/Steam.php b/app/Support/Steam.php
index 669c2e468b..870b55566c 100644
--- a/app/Support/Steam.php
+++ b/app/Support/Steam.php
@@ -245,7 +245,7 @@ class Steam
*/
public function positive(string $amount): string
{
- if (bccomp($amount, '0') === 1) {
+ if (bccomp($amount, '0') === -1) {
$amount = bcmul($amount, '-1');
}