Various PSR12 code cleanup

This commit is contained in:
James Cole
2022-12-29 19:42:26 +01:00
parent dbf3e76ecc
commit 6cfdc58cb1
415 changed files with 7462 additions and 6874 deletions

View File

@@ -33,6 +33,8 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Support\Collection;
use JsonException;
use Log;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use stdClass;
use Str;
use ValueError;
@@ -95,38 +97,6 @@ class Steam
return $sum;
}
/**
* https://stackoverflow.com/questions/1642614/how-to-ceil-floor-and-round-bcmath-numbers
*
* @param null|string $number
* @param int $precision
* @return string
*/
public function bcround(?string $number, int $precision = 0): string
{
if (null === $number) {
return '0';
}
if ('' === trim($number)) {
return '0';
}
// if the number contains "E", it's in scientific notation, so we need to convert it to a normal number first.
if (false !== stripos($number, 'e')) {
$number = sprintf('%.24f', $number);
}
Log::debug(sprintf('Trying bcround("%s",%d)', $number, $precision));
if (str_contains($number, '.')) {
if ($number[0] !== '-') {
return bcadd($number, '0.'.str_repeat('0', $precision).'5', $precision);
}
return bcsub($number, '0.'.str_repeat('0', $precision).'5', $precision);
}
return $number;
}
/**
* Gets the balance for the given account during the whole range, using this format:.
*
@@ -182,11 +152,11 @@ class Steam
->whereNull('transaction_journals.deleted_at')
->get(
[
'transaction_journals.date',
'transactions.transaction_currency_id',
DB::raw('SUM(transactions.amount) AS modified'),
'transactions.foreign_currency_id',
DB::raw('SUM(transactions.foreign_amount) AS modified_foreign'),
'transaction_journals.date',
'transactions.transaction_currency_id',
DB::raw('SUM(transactions.amount) AS modified'),
'transactions.foreign_currency_id',
DB::raw('SUM(transactions.foreign_amount) AS modified_foreign'),
]
);
@@ -363,6 +333,38 @@ class Steam
return $return;
}
/**
* https://stackoverflow.com/questions/1642614/how-to-ceil-floor-and-round-bcmath-numbers
*
* @param null|string $number
* @param int $precision
* @return string
*/
public function bcround(?string $number, int $precision = 0): string
{
if (null === $number) {
return '0';
}
if ('' === trim($number)) {
return '0';
}
// if the number contains "E", it's in scientific notation, so we need to convert it to a normal number first.
if (false !== stripos($number, 'e')) {
$number = sprintf('%.24f', $number);
}
Log::debug(sprintf('Trying bcround("%s",%d)', $number, $precision));
if (str_contains($number, '.')) {
if ($number[0] !== '-') {
return bcadd($number, '0.'.str_repeat('0', $precision).'5', $precision);
}
return bcsub($number, '0.'.str_repeat('0', $precision).'5', $precision);
}
return $number;
}
/**
* @param string $string
*
@@ -453,8 +455,8 @@ class Steam
*
* @return string
* @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getLocale(): string // get preference
{
@@ -476,8 +478,8 @@ class Steam
*
* @return string
* @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getLanguage(): string // get preference
{