mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Code cleanup
This commit is contained in:
@@ -80,7 +80,7 @@ class EnableCurrencies extends Command
|
||||
$found = array_values(
|
||||
array_filter(
|
||||
$found,
|
||||
function (int $currencyId) {
|
||||
static function (int $currencyId) {
|
||||
return $currencyId !== 0;
|
||||
}
|
||||
)
|
||||
|
@@ -81,11 +81,11 @@ class FixAccountTypes extends Command
|
||||
->leftJoin('account_types as destination_account_type', 'destination_account.account_type_id', '=', 'destination_account_type.id');
|
||||
|
||||
// list all valid combinations, those are allowed. So we select those which are broken.
|
||||
$query->where(function (Builder $q) use ($expected) {
|
||||
$query->where(static function (Builder $q) use ($expected) {
|
||||
foreach ($expected as $transactionType => $info) {
|
||||
foreach ($info as $source => $destinations) {
|
||||
foreach ($destinations as $destination) {
|
||||
$q->whereNot(function (Builder $q1) use ($transactionType, $source, $destination) {
|
||||
$q->whereNot(static function (Builder $q1) use ($transactionType, $source, $destination) {
|
||||
$q1->where('transaction_types.type', $transactionType);
|
||||
$q1->where('source_account_type.type', $source);
|
||||
$q1->where('destination_account_type.type', $destination);
|
||||
|
@@ -56,7 +56,7 @@ class FixUnevenAmount extends Command
|
||||
foreach ($journals as $entry) {
|
||||
$sum = (string)$entry->the_sum;
|
||||
if (!is_numeric($sum) ||
|
||||
0 === strlen($sum) || // @phpstan-ignore-line
|
||||
'' === $sum || // @phpstan-ignore-line
|
||||
str_contains($sum, 'e') ||
|
||||
str_contains($sum, ',')) {
|
||||
$message = sprintf(
|
||||
|
@@ -136,7 +136,7 @@ class ForceDecimalSize extends Command
|
||||
{
|
||||
// if sqlite, add function?
|
||||
if ('sqlite' === (string)config('database.default')) {
|
||||
DB::connection()->getPdo()->sqliteCreateFunction('REGEXP', function ($pattern, $value) {
|
||||
DB::connection()->getPdo()->sqliteCreateFunction('REGEXP', static function ($pattern, $value) {
|
||||
mb_regex_encoding('UTF-8');
|
||||
$pattern = trim($pattern, '"');
|
||||
|
||||
@@ -259,7 +259,7 @@ class ForceDecimalSize extends Command
|
||||
continue;
|
||||
}
|
||||
// fix $field by rounding it down correctly.
|
||||
$pow = pow(10, (int)$currency->decimal_places);
|
||||
$pow = 10** (int)$currency->decimal_places;
|
||||
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12);
|
||||
$this->friendlyInfo(sprintf('Account #%d has %s with value "%s", this has been corrected to "%s".', $account->id, $field, $value, $correct));
|
||||
Account::find($account->id)->update([$field => $correct]);
|
||||
@@ -310,7 +310,7 @@ class ForceDecimalSize extends Command
|
||||
continue;
|
||||
}
|
||||
// fix $field by rounding it down correctly.
|
||||
$pow = pow(10, (int)$currency->decimal_places);
|
||||
$pow = 10** (int)$currency->decimal_places;
|
||||
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12);
|
||||
$this->friendlyWarning(sprintf('%s #%d has %s with value "%s", this has been corrected to "%s".', $table, $item->id, $field, $value, $correct));
|
||||
$class::find($item->id)->update([$field => $correct]);
|
||||
@@ -362,7 +362,7 @@ class ForceDecimalSize extends Command
|
||||
continue;
|
||||
}
|
||||
// fix $field by rounding it down correctly.
|
||||
$pow = pow(10, (int)$currency->decimal_places);
|
||||
$pow = 10** (int)$currency->decimal_places;
|
||||
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12);
|
||||
$this->friendlyWarning(
|
||||
sprintf('Piggy bank event #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct)
|
||||
@@ -416,7 +416,7 @@ class ForceDecimalSize extends Command
|
||||
continue;
|
||||
}
|
||||
// fix $field by rounding it down correctly.
|
||||
$pow = pow(10, (int)$currency->decimal_places);
|
||||
$pow = 10** (int)$currency->decimal_places;
|
||||
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12);
|
||||
$this->friendlyWarning(
|
||||
sprintf('Piggy bank repetition #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct)
|
||||
@@ -469,7 +469,7 @@ class ForceDecimalSize extends Command
|
||||
continue;
|
||||
}
|
||||
// fix $field by rounding it down correctly.
|
||||
$pow = pow(10, (int)$currency->decimal_places);
|
||||
$pow = 10** (int)$currency->decimal_places;
|
||||
$correct = bcdiv((string)round($value * $pow), (string)$pow, 12);
|
||||
$this->friendlyWarning(sprintf('Piggy bank #%d has %s with value "%s", this has been corrected to "%s".', $item->id, $field, $value, $correct));
|
||||
PiggyBank::find($item->id)->update([$field => $correct]);
|
||||
@@ -506,7 +506,7 @@ class ForceDecimalSize extends Command
|
||||
continue;
|
||||
}
|
||||
// fix $field by rounding it down correctly.
|
||||
$pow = (float)pow(10, (int)$currency->decimal_places);
|
||||
$pow = (float)10** (int)$currency->decimal_places;
|
||||
$correct = bcdiv((string)round((float)$value * $pow), (string)$pow, 12);
|
||||
$this->friendlyWarning(sprintf('Transaction #%d has amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct));
|
||||
Transaction::find($item->id)->update(['amount' => $correct]);
|
||||
@@ -533,7 +533,7 @@ class ForceDecimalSize extends Command
|
||||
continue;
|
||||
}
|
||||
// fix $field by rounding it down correctly.
|
||||
$pow = (float)pow(10, (int)$currency->decimal_places);
|
||||
$pow = (float)10** (int)$currency->decimal_places;
|
||||
$correct = bcdiv((string)round((float)$value * $pow), (string)$pow, 12);
|
||||
$this->friendlyWarning(
|
||||
sprintf('Transaction #%d has foreign amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct)
|
||||
|
Reference in New Issue
Block a user