Skip to content

Firefly III: a personal finances manager

Code cleanup.

James Coleac4e9dcbc59e
diff --git a/app/Models/RuleAction.php b/app/Models/RuleAction.php
index f5cf1bfccf..1c1a96e3c3 100644
--- a/app/Models/RuleAction.php
+++ b/app/Models/RuleAction.php
@@ -69,12 +69,12 @@ class RuleAction extends Model
protected $casts
= [
- 'created_at' => 'datetime',
- 'updated_at' => 'datetime',
- 'active' => 'boolean',
- 'order' => 'int',
- 'stop_processing' => 'boolean',
- ];
+ 'created_at' => 'datetime',
+ 'updated_at' => 'datetime',
+ 'active' => 'boolean',
+ 'order' => 'int',
+ 'stop_processing' => 'boolean',
+ ];
protected $fillable = ['rule_id', 'action_type', 'action_value', 'order', 'active', 'stop_processing'];
diff --git a/app/TransactionRules/Actions/SetAmount.php b/app/TransactionRules/Actions/SetAmount.php
index 54501e6659..f7209ffe53 100644
--- a/app/TransactionRules/Actions/SetAmount.php
+++ b/app/TransactionRules/Actions/SetAmount.php
@@ -28,7 +28,6 @@ use FireflyIII\Events\TriggeredAuditLog;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
-use FireflyIII\Support\Facades\Steam;
use FireflyIII\TransactionRules\Traits\RefreshNotesTrait;
class SetAmount implements ActionInterface
@@ -59,7 +58,7 @@ class SetAmount implements ActionInterface
$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));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_invalid_amount', ['amount' => $value])));
@@ -69,16 +68,14 @@ class SetAmount implements ActionInterface
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
- // doesn't actually do anything!
- $positive = Steam::positive($value);
- $negative = Steam::negative($value);
+ $positive = app('steam')->positive($value);
+ $negative = app('steam')->negative($value);
$this->updatePositive($object, $positive);
$this->updateNegative($object, $negative);
$object->transactionGroup->touch();
// event for audit log entry
-
event(new TriggeredAuditLog(
$this->action->rule,
$object,
diff --git a/app/TransactionRules/Expressions/ActionExpressionLanguageProvider.php b/app/TransactionRules/Expressions/ActionExpressionLanguageProvider.php
index a608fc6848..f871b3390a 100644
--- a/app/TransactionRules/Expressions/ActionExpressionLanguageProvider.php
+++ b/app/TransactionRules/Expressions/ActionExpressionLanguageProvider.php
@@ -27,38 +27,35 @@ namespace FireflyIII\TransactionRules\Expressions;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
+/**
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ */
class ActionExpressionLanguageProvider implements ExpressionFunctionProviderInterface
{
public function getFunctions(): array
{
+ $function = function ($arguments, $str): string {
+ if (!is_string($str)) {
+ return (string) $str;
+ }
+
+ return strtolower($str.'!');
+ };
+
return [
new ExpressionFunction(
- 'constant',
- function ($str): string {
+ 'constant2',
+ static 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)) {
- return (string) $str;
- }
-
- return strtolower($str.'!');
- }
+ $function
),
new ExpressionFunction(
- 'enum',
- function ($str): string {
- return sprintf('(is_string(%1$s) ? strtolower(%1$s) : %1$s)', $str.'?');
+ 'constant',
+ static 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)) {
- return (string) $str;
- }
-
- return strtolower($str).'?';
- }
+ $function
),
ExpressionFunction::fromPhp('substr'),
diff --git a/app/Transformers/V2/AccountTransformer.php b/app/Transformers/V2/AccountTransformer.php
index 4e0fb1e6c0..aef4ba7fe8 100644
--- a/app/Transformers/V2/AccountTransformer.php
+++ b/app/Transformers/V2/AccountTransformer.php
@@ -90,8 +90,9 @@ class AccountTransformer extends AbstractTransformer
}
// TODO needs separate method.
+ /** @var null|array $sort */
$sort = $this->parameters->get('sort');
- if (is_countable($sort) && count($sort) > 0) {
+ if (null !== $sort && count($sort) > 0) {
foreach ($sort as $column => $direction) {
// account_number + iban
if ('iban' === $column) {