Small code cleanup.

This commit is contained in:
James Cole 2017-02-11 15:52:55 +01:00
parent fb73baca6a
commit 4c2d9e0eee
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
8 changed files with 11 additions and 30 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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