mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Code cleanup.
This commit is contained in:
parent
d57806f2ba
commit
ac4e9dcbc5
@ -28,7 +28,6 @@ use FireflyIII\Events\TriggeredAuditLog;
|
|||||||
use FireflyIII\Models\RuleAction;
|
use FireflyIII\Models\RuleAction;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Support\Facades\Steam;
|
|
||||||
use FireflyIII\TransactionRules\Traits\RefreshNotesTrait;
|
use FireflyIII\TransactionRules\Traits\RefreshNotesTrait;
|
||||||
|
|
||||||
class SetAmount implements ActionInterface
|
class SetAmount implements ActionInterface
|
||||||
@ -59,7 +58,7 @@ class SetAmount implements ActionInterface
|
|||||||
|
|
||||||
$value = $this->action->getValue($journal);
|
$value = $this->action->getValue($journal);
|
||||||
|
|
||||||
if (!is_numeric($value) || '' === $value || 0 === bccomp((string)$value, '0')) {
|
if (!is_numeric($value) || 0 === bccomp($value, '0')) {
|
||||||
app('log')->debug(sprintf('RuleAction SetAmount, amount "%s" is not a number or is zero, will not continue.', $value));
|
app('log')->debug(sprintf('RuleAction SetAmount, amount "%s" is not a number or is zero, will not continue.', $value));
|
||||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_invalid_amount', ['amount' => $value])));
|
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_invalid_amount', ['amount' => $value])));
|
||||||
|
|
||||||
@ -69,16 +68,14 @@ class SetAmount implements ActionInterface
|
|||||||
/** @var TransactionJournal $object */
|
/** @var TransactionJournal $object */
|
||||||
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
|
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
|
||||||
|
|
||||||
// doesn't actually do anything!
|
$positive = app('steam')->positive($value);
|
||||||
$positive = Steam::positive($value);
|
$negative = app('steam')->negative($value);
|
||||||
$negative = Steam::negative($value);
|
|
||||||
|
|
||||||
$this->updatePositive($object, $positive);
|
$this->updatePositive($object, $positive);
|
||||||
$this->updateNegative($object, $negative);
|
$this->updateNegative($object, $negative);
|
||||||
$object->transactionGroup->touch();
|
$object->transactionGroup->touch();
|
||||||
|
|
||||||
// event for audit log entry
|
// event for audit log entry
|
||||||
|
|
||||||
event(new TriggeredAuditLog(
|
event(new TriggeredAuditLog(
|
||||||
$this->action->rule,
|
$this->action->rule,
|
||||||
$object,
|
$object,
|
||||||
|
@ -27,38 +27,35 @@ namespace FireflyIII\TransactionRules\Expressions;
|
|||||||
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
|
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
|
||||||
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
|
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||||
|
*/
|
||||||
class ActionExpressionLanguageProvider implements ExpressionFunctionProviderInterface
|
class ActionExpressionLanguageProvider implements ExpressionFunctionProviderInterface
|
||||||
{
|
{
|
||||||
public function getFunctions(): array
|
public function getFunctions(): array
|
||||||
{
|
{
|
||||||
return [
|
$function = function ($arguments, $str): string {
|
||||||
new ExpressionFunction(
|
|
||||||
'constant',
|
|
||||||
function ($str): string {
|
|
||||||
return sprintf('(is_string(%1$s) ? strtolower(%1$s) : %1$s)', $str.'!');
|
|
||||||
},
|
|
||||||
// @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
|
||||||
function ($arguments, $str): string {
|
|
||||||
if (!is_string($str)) {
|
if (!is_string($str)) {
|
||||||
return (string) $str;
|
return (string) $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
return strtolower($str.'!');
|
return strtolower($str.'!');
|
||||||
}
|
};
|
||||||
|
|
||||||
|
return [
|
||||||
|
new ExpressionFunction(
|
||||||
|
'constant2',
|
||||||
|
static function ($str): string {
|
||||||
|
return sprintf('(is_string(%1$s) ? strtolower(%1$s) : %1$s)', $str.'!');
|
||||||
|
},
|
||||||
|
$function
|
||||||
),
|
),
|
||||||
new ExpressionFunction(
|
new ExpressionFunction(
|
||||||
'enum',
|
'constant',
|
||||||
function ($str): string {
|
static function ($str): string {
|
||||||
return sprintf('(is_string(%1$s) ? strtolower(%1$s) : %1$s)', $str.'?');
|
return sprintf('(is_string(%1$s) ? strtolower(%1$s) : %1$s)', $str.'!');
|
||||||
},
|
},
|
||||||
// @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
$function
|
||||||
function ($arguments, $str): string {
|
|
||||||
if (!is_string($str)) {
|
|
||||||
return (string) $str;
|
|
||||||
}
|
|
||||||
|
|
||||||
return strtolower($str).'?';
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
|
|
||||||
ExpressionFunction::fromPhp('substr'),
|
ExpressionFunction::fromPhp('substr'),
|
||||||
|
@ -90,8 +90,9 @@ class AccountTransformer extends AbstractTransformer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO needs separate method.
|
// TODO needs separate method.
|
||||||
|
/** @var null|array $sort */
|
||||||
$sort = $this->parameters->get('sort');
|
$sort = $this->parameters->get('sort');
|
||||||
if (is_countable($sort) && count($sort) > 0) {
|
if (null !== $sort && count($sort) > 0) {
|
||||||
foreach ($sort as $column => $direction) {
|
foreach ($sort as $column => $direction) {
|
||||||
// account_number + iban
|
// account_number + iban
|
||||||
if ('iban' === $column) {
|
if ('iban' === $column) {
|
||||||
|
Loading…
Reference in New Issue
Block a user