Skip to content

Firefly III: a personal finances manager

Refactor old methods.

James Cole69b1769f221a
diff --git a/app/Api/V1/Requests/Models/Account/StoreRequest.php b/app/Api/V1/Requests/Models/Account/StoreRequest.php
index 288bb97080..deb9634225 100644
--- a/app/Api/V1/Requests/Models/Account/StoreRequest.php
+++ b/app/Api/V1/Requests/Models/Account/StoreRequest.php
@@ -73,7 +73,7 @@ class StoreRequest extends FormRequest
'opening_balance_date' => $this->date('opening_balance_date'),
'cc_type' => $this->string('credit_card_type'),
'cc_monthly_payment_date' => $this->string('monthly_payment_date'),
- 'notes' => $this->nlString('notes'),
+ 'notes' => $this->stringWithNewlines('notes'),
'interest' => $this->string('interest'),
'interest_period' => $this->string('interest_period'),
];
diff --git a/app/Api/V1/Requests/Models/Account/UpdateRequest.php b/app/Api/V1/Requests/Models/Account/UpdateRequest.php
index 50218be353..4b30887327 100644
--- a/app/Api/V1/Requests/Models/Account/UpdateRequest.php
+++ b/app/Api/V1/Requests/Models/Account/UpdateRequest.php
@@ -62,7 +62,7 @@ class UpdateRequest extends FormRequest
'opening_balance_date' => ['opening_balance_date', 'date'],
'cc_type' => ['credit_card_type', 'string'],
'cc_monthly_payment_date' => ['monthly_payment_date', 'string'],
- 'notes' => ['notes', 'nlString'],
+ 'notes' => ['notes', 'stringWithNewlines'],
'interest' => ['interest', 'string'],
'interest_period' => ['interest_period', 'string'],
'order' => ['order', 'integer'],
@@ -73,9 +73,9 @@ class UpdateRequest extends FormRequest
$data = $this->appendLocationData($data, null);
if (array_key_exists('account_type_name', $data) && 'liability' === $data['account_type_name']) {
- $data['opening_balance'] = bcmul($this->nullableString('liability_amount'), '-1');
+ $data['opening_balance'] = bcmul($this->string('liability_amount'), '-1');
$data['opening_balance_date'] = $this->date('liability_start_date');
- $data['account_type_name'] = $this->nullableString('liability_type');
+ $data['account_type_name'] = $this->string('liability_type');
$data['account_type_id'] = null;
}
@@ -97,9 +97,9 @@ class UpdateRequest extends FormRequest
$rules = [
'name' => sprintf('min:1|uniqueAccountForUser:%d', $account->id),
'type' => sprintf('in:%s', $types),
- 'iban' => ['iban', 'nullable', new UniqueIban($account, $this->nullableString('type'))],
+ 'iban' => ['iban', 'nullable', new UniqueIban($account, $this->string('type'))],
'bic' => 'bic|nullable',
- 'account_number' => ['between:1,255', 'nullable', new UniqueAccountNumber($account, $this->nullableString('type'))],
+ 'account_number' => ['between:1,255', 'nullable', new UniqueAccountNumber($account, $this->string('type'))],
'opening_balance' => 'numeric|required_with:opening_balance_date|nullable',
'opening_balance_date' => 'date|required_with:opening_balance|nullable',
'virtual_balance' => 'numeric|nullable',
diff --git a/app/Api/V1/Requests/Models/Attachment/StoreRequest.php b/app/Api/V1/Requests/Models/Attachment/StoreRequest.php
index 97c43cd933..be13081ab8 100644
--- a/app/Api/V1/Requests/Models/Attachment/StoreRequest.php
+++ b/app/Api/V1/Requests/Models/Attachment/StoreRequest.php
@@ -47,7 +47,7 @@ class StoreRequest extends FormRequest
return [
'filename' => $this->string('filename'),
'title' => $this->string('title'),
- 'notes' => $this->nlString('notes'),
+ 'notes' => $this->stringWithNewlines('notes'),
'attachable_type' => $this->string('attachable_type'),
'attachable_id' => $this->integer('attachable_id'),
];
diff --git a/app/Api/V1/Requests/Models/Attachment/UpdateRequest.php b/app/Api/V1/Requests/Models/Attachment/UpdateRequest.php
index 3820c7cf79..cb05b390bd 100644
--- a/app/Api/V1/Requests/Models/Attachment/UpdateRequest.php
+++ b/app/Api/V1/Requests/Models/Attachment/UpdateRequest.php
@@ -47,7 +47,7 @@ class UpdateRequest extends FormRequest
$fields = [
'filename' => ['filename', 'string'],
'title' => ['title', 'string'],
- 'notes' => ['notes', 'nlString'],
+ 'notes' => ['notes', 'stringWithNewlines'],
'attachable_type' => ['attachable_type', 'string'],
'attachable_id' => ['attachable_id', 'integer'],
];
diff --git a/app/Api/V1/Requests/Models/Bill/StoreRequest.php b/app/Api/V1/Requests/Models/Bill/StoreRequest.php
index f3f0e1ed6c..88560c1077 100644
--- a/app/Api/V1/Requests/Models/Bill/StoreRequest.php
+++ b/app/Api/V1/Requests/Models/Bill/StoreRequest.php
@@ -59,7 +59,7 @@ class StoreRequest extends FormRequest
'skip' => ['skip', 'integer'],
'active' => ['active', 'boolean'],
'order' => ['order', 'integer'],
- 'notes' => ['notes', 'nlString'],
+ 'notes' => ['notes', 'stringWithNewlines'],
'object_group_id' => ['object_group_id', 'integer'],
'object_group_title' => ['object_group_title', 'string'],
];
diff --git a/app/Api/V1/Requests/Models/Bill/UpdateRequest.php b/app/Api/V1/Requests/Models/Bill/UpdateRequest.php
index 3f01053bba..2a4a89e555 100644
--- a/app/Api/V1/Requests/Models/Bill/UpdateRequest.php
+++ b/app/Api/V1/Requests/Models/Bill/UpdateRequest.php
@@ -57,7 +57,7 @@ class UpdateRequest extends FormRequest
'skip' => ['skip', 'integer'],
'active' => ['active', 'boolean'],
'order' => ['order', 'integer'],
- 'notes' => ['notes', 'nlString'],
+ 'notes' => ['notes', 'stringWithNewlines'],
'object_group_id' => ['object_group_id', 'integer'],
'object_group_title' => ['object_group_title', 'string'],
];
diff --git a/app/Api/V1/Requests/Models/Category/StoreRequest.php b/app/Api/V1/Requests/Models/Category/StoreRequest.php
index ddd5bc3216..b6f96bfdc9 100644
--- a/app/Api/V1/Requests/Models/Category/StoreRequest.php
+++ b/app/Api/V1/Requests/Models/Category/StoreRequest.php
@@ -46,7 +46,7 @@ class StoreRequest extends FormRequest
{
return [
'name' => $this->string('name'),
- 'notes' => $this->nlString('notes'),
+ 'notes' => $this->stringWithNewlines('notes'),
];
}
diff --git a/app/Api/V1/Requests/Models/Category/UpdateRequest.php b/app/Api/V1/Requests/Models/Category/UpdateRequest.php
index ee0b56880c..26b9abf33e 100644
--- a/app/Api/V1/Requests/Models/Category/UpdateRequest.php
+++ b/app/Api/V1/Requests/Models/Category/UpdateRequest.php
@@ -45,7 +45,7 @@ class UpdateRequest extends FormRequest
{
$fields = [
'name' => ['name', 'string'],
- 'notes' => ['notes', 'nlString'],
+ 'notes' => ['notes', 'stringWithNewlines'],
];
return $this->getAllData($fields);
diff --git a/app/Api/V1/Requests/Models/PiggyBank/StoreRequest.php b/app/Api/V1/Requests/Models/PiggyBank/StoreRequest.php
index e42993cea6..082f482412 100644
--- a/app/Api/V1/Requests/Models/PiggyBank/StoreRequest.php
+++ b/app/Api/V1/Requests/Models/PiggyBank/StoreRequest.php
@@ -53,7 +53,7 @@ class StoreRequest extends FormRequest
$data['current_amount'] = $this->string('current_amount');
$data['startdate'] = $this->date('start_date');
$data['targetdate'] = $this->date('target_date');
- $data['notes'] = $this->nlString('notes');
+ $data['notes'] = $this->stringWithNewlines('notes');
$data['object_group_id'] = $this->integer('object_group_id');
$data['object_group_title'] = $this->string('object_group_title');
diff --git a/app/Api/V1/Requests/Models/PiggyBank/UpdateRequest.php b/app/Api/V1/Requests/Models/PiggyBank/UpdateRequest.php
index e5816dc018..e41fc798bf 100644
--- a/app/Api/V1/Requests/Models/PiggyBank/UpdateRequest.php
+++ b/app/Api/V1/Requests/Models/PiggyBank/UpdateRequest.php
@@ -52,7 +52,7 @@ class UpdateRequest extends FormRequest
'current_amount' => ['current_amount', 'string'],
'startdate' => ['start_date', 'date'],
'targetdate' => ['target_date', 'string'],
- 'notes' => ['notes', 'nlString'],
+ 'notes' => ['notes', 'stringWithNewlines'],
'order' => ['order', 'integer'],
'object_group_title' => ['object_group_title', 'string'],
'object_group_id' => ['object_group_id', 'integer'],
diff --git a/app/Api/V1/Requests/Models/Recurrence/StoreRequest.php b/app/Api/V1/Requests/Models/Recurrence/StoreRequest.php
index 044b26106d..972952d600 100644
--- a/app/Api/V1/Requests/Models/Recurrence/StoreRequest.php
+++ b/app/Api/V1/Requests/Models/Recurrence/StoreRequest.php
@@ -58,7 +58,7 @@ class StoreRequest extends FormRequest
'nr_of_repetitions' => ['nr_of_repetitions', 'integer'],
'apply_rules' => ['apply_rules', 'boolean'],
'active' => ['active', 'boolean'],
- 'notes' => ['notes', 'nlString'],
+ 'notes' => ['notes', 'stringWithNewlines'],
];
$recurrence = $this->getAllData($fields);
diff --git a/app/Api/V1/Requests/Models/Rule/UpdateRequest.php b/app/Api/V1/Requests/Models/Rule/UpdateRequest.php
index f047946fcb..01df50719b 100644
--- a/app/Api/V1/Requests/Models/Rule/UpdateRequest.php
+++ b/app/Api/V1/Requests/Models/Rule/UpdateRequest.php
@@ -47,7 +47,7 @@ class UpdateRequest extends FormRequest
{
$fields = [
'title' => ['title', 'string'],
- 'description' => ['description', 'nlString'],
+ 'description' => ['description', 'stringWithNewlines'],
'rule_group_id' => ['rule_group_id', 'integer'],
'trigger' => ['trigger', 'string'],
'strict' => ['strict', 'boolean'],
diff --git a/app/Api/V1/Requests/Models/RuleGroup/UpdateRequest.php b/app/Api/V1/Requests/Models/RuleGroup/UpdateRequest.php
index 8b572a96d8..b6896b891f 100644
--- a/app/Api/V1/Requests/Models/RuleGroup/UpdateRequest.php
+++ b/app/Api/V1/Requests/Models/RuleGroup/UpdateRequest.php
@@ -46,7 +46,7 @@ class UpdateRequest extends FormRequest
// This is the way.
$fields = [
'title' => ['title', 'string'],
- 'description' => ['description', 'nlString'],
+ 'description' => ['description', 'stringWithNewlines'],
'active' => ['active', 'boolean'],
'order' => ['order', 'integer'],
];
diff --git a/app/Api/V1/Requests/Models/Transaction/StoreRequest.php b/app/Api/V1/Requests/Models/Transaction/StoreRequest.php
index 1f442eeaa6..74cb4d6c87 100644
--- a/app/Api/V1/Requests/Models/Transaction/StoreRequest.php
+++ b/app/Api/V1/Requests/Models/Transaction/StoreRequest.php
@@ -78,75 +78,75 @@ class StoreRequest extends FormRequest
foreach ($this->get('transactions') as $transaction) {
$object = new NullArrayObject($transaction);
$return[] = [
- 'type' => $this->stringFromValue($object['type']),
+ 'type' => $this->clearString($object['type'], false),
'date' => $this->dateFromValue($object['date']),
'order' => $this->integerFromValue((string)$object['order']),
'currency_id' => $this->integerFromValue((string)$object['currency_id']),
- 'currency_code' => $this->stringFromValue($object['currency_code']),
+ 'currency_code' => $this->clearString($object['currency_code'], false),
// foreign currency info:
'foreign_currency_id' => $this->integerFromValue((string)$object['foreign_currency_id']),
- 'foreign_currency_code' => $this->stringFromValue((string)$object['foreign_currency_code']),
+ 'foreign_currency_code' => $this->clearString((string)$object['foreign_currency_code'], false),
// amount and foreign amount. Cannot be 0.
- 'amount' => $this->stringFromValue((string)$object['amount']),
- 'foreign_amount' => $this->stringFromValue((string)$object['foreign_amount']),
+ 'amount' => $this->clearString((string)$object['amount'], false),
+ 'foreign_amount' => $this->clearString((string)$object['foreign_amount'], false),
// description.
- 'description' => $this->stringFromValue($object['description']),
+ 'description' => $this->clearString($object['description'], false),
// source of transaction. If everything is null, assume cash account.
'source_id' => $this->integerFromValue((string)$object['source_id']),
- 'source_name' => $this->stringFromValue((string)$object['source_name']),
- 'source_iban' => $this->stringFromValue((string)$object['source_iban']),
- 'source_number' => $this->stringFromValue((string)$object['source_number']),
- 'source_bic' => $this->stringFromValue((string)$object['source_bic']),
+ 'source_name' => $this->clearString((string)$object['source_name'], false),
+ 'source_iban' => $this->clearString((string)$object['source_iban'], false),
+ 'source_number' => $this->clearString((string)$object['source_number'], false),
+ 'source_bic' => $this->clearString((string)$object['source_bic'], false),
// destination of transaction. If everything is null, assume cash account.
'destination_id' => $this->integerFromValue((string)$object['destination_id']),
- 'destination_name' => $this->stringFromValue((string)$object['destination_name']),
- 'destination_iban' => $this->stringFromValue((string)$object['destination_iban']),
- 'destination_number' => $this->stringFromValue((string)$object['destination_number']),
- 'destination_bic' => $this->stringFromValue((string)$object['destination_bic']),
+ 'destination_name' => $this->clearString((string)$object['destination_name'], false),
+ 'destination_iban' => $this->clearString((string)$object['destination_iban'], false),
+ 'destination_number' => $this->clearString((string)$object['destination_number'], false),
+ 'destination_bic' => $this->clearString((string)$object['destination_bic'], false),
// budget info
'budget_id' => $this->integerFromValue((string)$object['budget_id']),
- 'budget_name' => $this->stringFromValue((string)$object['budget_name']),
+ 'budget_name' => $this->clearString((string)$object['budget_name'], false),
// category info
'category_id' => $this->integerFromValue((string)$object['category_id']),
- 'category_name' => $this->stringFromValue((string)$object['category_name']),
+ 'category_name' => $this->clearString((string)$object['category_name'], false),
// journal bill reference. Optional. Will only work for withdrawals
'bill_id' => $this->integerFromValue((string)$object['bill_id']),
- 'bill_name' => $this->stringFromValue((string)$object['bill_name']),
+ 'bill_name' => $this->clearString((string)$object['bill_name'], false),
// piggy bank reference. Optional. Will only work for transfers
'piggy_bank_id' => $this->integerFromValue((string)$object['piggy_bank_id']),
- 'piggy_bank_name' => $this->stringFromValue((string)$object['piggy_bank_name']),
+ 'piggy_bank_name' => $this->clearString((string)$object['piggy_bank_name'], false),
// some other interesting properties
'reconciled' => $this->convertBoolean((string)$object['reconciled']),
- 'notes' => $this->nlStringFromValue((string)$object['notes']),
+ 'notes' => $this->clearString((string)$object['notes']),
'tags' => $this->arrayFromValue($object['tags']),
// all custom fields:
- 'internal_reference' => $this->stringFromValue((string)$object['internal_reference']),
- 'external_id' => $this->stringFromValue((string)$object['external_id']),
+ 'internal_reference' => $this->clearString((string)$object['internal_reference'],false),
+ 'external_id' => $this->clearString((string)$object['external_id'], false),
'original_source' => sprintf('ff3-v%s|api-v%s', config('firefly.version'), config('firefly.api_version')),
'recurrence_id' => $this->integerFromValue($object['recurrence_id']),
- 'bunq_payment_id' => $this->stringFromValue((string)$object['bunq_payment_id']),
- 'external_uri' => $this->stringFromValue((string)$object['external_uri']),
-
- 'sepa_cc' => $this->stringFromValue($object['sepa_cc']),
- 'sepa_ct_op' => $this->stringFromValue($object['sepa_ct_op']),
- 'sepa_ct_id' => $this->stringFromValue($object['sepa_ct_id']),
- 'sepa_db' => $this->stringFromValue($object['sepa_db']),
- 'sepa_country' => $this->stringFromValue($object['sepa_country']),
- 'sepa_ep' => $this->stringFromValue($object['sepa_ep']),
- 'sepa_ci' => $this->stringFromValue($object['sepa_ci']),
- 'sepa_batch_id' => $this->stringFromValue($object['sepa_batch_id']),
+ 'bunq_payment_id' => $this->clearString((string)$object['bunq_payment_id'],false),
+ 'external_uri' => $this->clearString((string)$object['external_uri'], false),
+
+ 'sepa_cc' => $this->clearString($object['sepa_cc'],false),
+ 'sepa_ct_op' => $this->clearString($object['sepa_ct_op'],false),
+ 'sepa_ct_id' => $this->clearString($object['sepa_ct_id'],false),
+ 'sepa_db' => $this->clearString($object['sepa_db'],false),
+ 'sepa_country' => $this->clearString($object['sepa_country'],false),
+ 'sepa_ep' => $this->clearString($object['sepa_ep'],false),
+ 'sepa_ci' => $this->clearString($object['sepa_ci'],false),
+ 'sepa_batch_id' => $this->clearString($object['sepa_batch_id'],false),
// custom date fields. Must be Carbon objects. Presence is optional.
'interest_date' => $this->dateFromValue($object['interest_date']),
'book_date' => $this->dateFromValue($object['book_date']),
diff --git a/app/Api/V1/Requests/Models/Transaction/UpdateRequest.php b/app/Api/V1/Requests/Models/Transaction/UpdateRequest.php
index 68cefec00b..dc4a0593ce 100644
--- a/app/Api/V1/Requests/Models/Transaction/UpdateRequest.php
+++ b/app/Api/V1/Requests/Models/Transaction/UpdateRequest.php
@@ -194,7 +194,7 @@ class UpdateRequest extends FormRequest
{
foreach ($this->stringFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
- $current[$fieldName] = $this->stringFromValue((string)$transaction[$fieldName]);
+ $current[$fieldName] = $this->clearString((string)$transaction[$fieldName], false);
}
}
@@ -211,7 +211,7 @@ class UpdateRequest extends FormRequest
{
foreach ($this->textareaFields as $fieldName) {
if (array_key_exists($fieldName, $transaction)) {
- $current[$fieldName] = $this->nlStringFromValue((string)$transaction[$fieldName]);
+ $current[$fieldName] = $this->clearString((string)$transaction[$fieldName]);
}
}
diff --git a/app/Api/V1/Requests/Models/TransactionLink/StoreRequest.php b/app/Api/V1/Requests/Models/TransactionLink/StoreRequest.php
index fb7c1741b1..eaf55ed30f 100644
--- a/app/Api/V1/Requests/Models/TransactionLink/StoreRequest.php
+++ b/app/Api/V1/Requests/Models/TransactionLink/StoreRequest.php
@@ -50,7 +50,7 @@ class StoreRequest extends FormRequest
'link_type_name' => $this->string('link_type_name'),
'inward_id' => $this->integer('inward_id'),
'outward_id' => $this->integer('outward_id'),
- 'notes' => $this->nlString('notes'),
+ 'notes' => $this->stringWithNewlines('notes'),
];
}
diff --git a/app/Api/V1/Requests/Models/TransactionLink/UpdateRequest.php b/app/Api/V1/Requests/Models/TransactionLink/UpdateRequest.php
index 491782b2de..51937db61a 100644
--- a/app/Api/V1/Requests/Models/TransactionLink/UpdateRequest.php
+++ b/app/Api/V1/Requests/Models/TransactionLink/UpdateRequest.php
@@ -50,7 +50,7 @@ class UpdateRequest extends FormRequest
'link_type_name' => $this->string('link_type_name'),
'inward_id' => $this->integer('inward_id'),
'outward_id' => $this->integer('outward_id'),
- 'notes' => $this->nullableNlString('notes'),
+ 'notes' => $this->stringWithNewlines('notes'),
];
}
diff --git a/app/Factory/TransactionJournalFactory.php b/app/Factory/TransactionJournalFactory.php
index ac981c7984..dc180a7f3b 100644
--- a/app/Factory/TransactionJournalFactory.php
+++ b/app/Factory/TransactionJournalFactory.php
@@ -161,7 +161,7 @@ class TransactionJournalFactory
$foreignCurrency = $this->currencyRepository->findCurrencyNull($row['foreign_currency_id'], $row['foreign_currency_code']);
$bill = $this->billRepository->findBill((int)$row['bill_id'], $row['bill_name']);
$billId = TransactionType::WITHDRAWAL === $type->type && null !== $bill ? $bill->id : null;
- $description = app('steam')->cleanString((string)$row['description']);
+ $description = (string)$row['description'];
/** Manipulate basic fields */
$carbon->setTimezone(config('app.timezone'));
diff --git a/app/Http/Controllers/RuleGroup/EditController.php b/app/Http/Controllers/RuleGroup/EditController.php
index f7ff347786..57157f8a96 100644
--- a/app/Http/Controllers/RuleGroup/EditController.php
+++ b/app/Http/Controllers/RuleGroup/EditController.php
@@ -137,7 +137,7 @@ class EditController extends Controller
{
$data = [
'title' => $request->string('title'),
- 'description' => $request->nlString('description'),
+ 'description' => $request->stringWithNewlines('description'),
'active' => 1 === (int)$request->input('active'),
];
diff --git a/app/Http/Requests/AccountFormRequest.php b/app/Http/Requests/AccountFormRequest.php
index b050d8bbf5..ff6bc71ed6 100644
--- a/app/Http/Requests/AccountFormRequest.php
+++ b/app/Http/Requests/AccountFormRequest.php
@@ -58,7 +58,7 @@ class AccountFormRequest extends FormRequest
'opening_balance_date' => $this->date('opening_balance_date'),
'cc_type' => $this->string('cc_type'),
'cc_monthly_payment_date' => $this->string('cc_monthly_payment_date'),
- 'notes' => $this->nlString('notes'),
+ 'notes' => $this->stringWithNewlines('notes'),
'interest' => $this->string('interest'),
'interest_period' => $this->string('interest_period'),
'include_net_worth' => '1',
diff --git a/app/Http/Requests/BillStoreRequest.php b/app/Http/Requests/BillStoreRequest.php
index 10eb7c88a3..32ae63a4b2 100644
--- a/app/Http/Requests/BillStoreRequest.php
+++ b/app/Http/Requests/BillStoreRequest.php
@@ -49,7 +49,7 @@ class BillStoreRequest extends FormRequest
'date' => $this->date('date'),
'repeat_freq' => $this->string('repeat_freq'),
'skip' => $this->integer('skip'),
- 'notes' => $this->nlString('notes'),
+ 'notes' => $this->stringWithNewlines('notes'),
'active' => $this->boolean('active'),
'object_group_title' => $this->string('object_group'),
];
diff --git a/app/Http/Requests/BillUpdateRequest.php b/app/Http/Requests/BillUpdateRequest.php
index 6d09666903..13431c7d5a 100644
--- a/app/Http/Requests/BillUpdateRequest.php
+++ b/app/Http/Requests/BillUpdateRequest.php
@@ -50,7 +50,7 @@ class BillUpdateRequest extends FormRequest
'date' => $this->date('date'),
'repeat_freq' => $this->string('repeat_freq'),
'skip' => $this->integer('skip'),
- 'notes' => $this->nlString('notes'),
+ 'notes' => $this->stringWithNewlines('notes'),
'active' => $this->boolean('active'),
'object_group_title' => $this->string('object_group'),
];
diff --git a/app/Http/Requests/CategoryFormRequest.php b/app/Http/Requests/CategoryFormRequest.php
index 6b1a3bf7a5..0d1c15b5a7 100644
--- a/app/Http/Requests/CategoryFormRequest.php
+++ b/app/Http/Requests/CategoryFormRequest.php
@@ -43,7 +43,7 @@ class CategoryFormRequest extends FormRequest
{
return [
'name' => $this->string('name'),
- 'notes' => $this->nlString('notes'),
+ 'notes' => $this->stringWithNewlines('notes'),
];
}
diff --git a/app/Http/Requests/PiggyBankStoreRequest.php b/app/Http/Requests/PiggyBankStoreRequest.php
index a0014784a2..b9fee6510b 100644
--- a/app/Http/Requests/PiggyBankStoreRequest.php
+++ b/app/Http/Requests/PiggyBankStoreRequest.php
@@ -46,7 +46,7 @@ class PiggyBankStoreRequest extends FormRequest
'account_id' => $this->integer('account_id'),
'targetamount' => $this->string('targetamount'),
'targetdate' => $this->date('targetdate'),
- 'notes' => $this->nlString('notes'),
+ 'notes' => $this->stringWithNewlines('notes'),
'object_group_title' => $this->string('object_group'),
];
}
diff --git a/app/Http/Requests/PiggyBankUpdateRequest.php b/app/Http/Requests/PiggyBankUpdateRequest.php
index 9719ba8a32..bb35919338 100644
--- a/app/Http/Requests/PiggyBankUpdateRequest.php
+++ b/app/Http/Requests/PiggyBankUpdateRequest.php
@@ -47,7 +47,7 @@ class PiggyBankUpdateRequest extends FormRequest
'account_id' => $this->integer('account_id'),
'targetamount' => $this->string('targetamount'),
'targetdate' => $this->date('targetdate'),
- 'notes' => $this->nlString('notes'),
+ 'notes' => $this->stringWithNewlines('notes'),
'object_group_title' => $this->string('object_group'),
];
}
diff --git a/app/Http/Requests/RuleFormRequest.php b/app/Http/Requests/RuleFormRequest.php
index a207ef96f9..df558c61d2 100644
--- a/app/Http/Requests/RuleFormRequest.php
+++ b/app/Http/Requests/RuleFormRequest.php
@@ -48,7 +48,7 @@ class RuleFormRequest extends FormRequest
'rule_group_id' => $this->integer('rule_group_id'),
'active' => $this->boolean('active'),
'trigger' => $this->string('trigger'),
- 'description' => $this->nlString('description'),
+ 'description' => $this->stringWithNewlines('description'),
'stop_processing' => $this->boolean('stop_processing'),
'strict' => $this->boolean('strict'),
'triggers' => $this->getRuleTriggerData(),
diff --git a/app/Http/Requests/RuleGroupFormRequest.php b/app/Http/Requests/RuleGroupFormRequest.php
index d7a4b0224b..8645e04651 100644
--- a/app/Http/Requests/RuleGroupFormRequest.php
+++ b/app/Http/Requests/RuleGroupFormRequest.php
@@ -49,7 +49,7 @@ class RuleGroupFormRequest extends FormRequest
return [
'title' => $this->string('title'),
- 'description' => $this->nlString('description'),
+ 'description' => $this->stringWithNewlines('description'),
'active' => $active,
];
}
diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php
index e3ceb4e359..0653786ebe 100644
--- a/app/Models/Transaction.php
+++ b/app/Models/Transaction.php
@@ -44,6 +44,10 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property int $transaction_journal_id
* @property string|null $description
* @property int|null $transaction_currency_id
+ * @property string $modified
+ * @property string $modified_foreign
+ * @property string $date
+ * @property string $max_date
* @property string $amount
* @property string|null $foreign_amount
* @property int|null $foreign_currency_id
diff --git a/app/Support/CacheProperties.php b/app/Support/CacheProperties.php
index 4d7c36ab15..7175468e6c 100644
--- a/app/Support/CacheProperties.php
+++ b/app/Support/CacheProperties.php
@@ -23,9 +23,8 @@ declare(strict_types=1);
namespace FireflyIII\Support;
use Cache;
-use Carbon\Carbon;
-use FireflyIII\Models\Category;
use Illuminate\Support\Collection;
+use JsonException;
/**
* Class CacheProperties.
@@ -34,10 +33,8 @@ use Illuminate\Support\Collection;
*/
class CacheProperties
{
- /** @var string */
- protected $hash = '';
- /** @var Collection */
- protected $properties;
+ protected string $hash = '';
+ protected Collection $properties;
/**
*
@@ -52,8 +49,7 @@ class CacheProperties
}
/**
- * @param $property
- * @param Collection|Carbon|Category|array|int|string $property
+ * @param mixed $property
*/
public function addProperty($property): void
{
@@ -90,19 +86,24 @@ class CacheProperties
}
/**
+ * @throws JsonException
*/
private function hash(): void
{
$content = '';
foreach ($this->properties as $property) {
- $content .= json_encode($property, JSON_THROW_ON_ERROR, 512);
+ try {
+ $content .= json_encode($property, JSON_THROW_ON_ERROR, 512);
+ } catch (JsonException $e) {
+ // @ignoreException
+ $content .= md5(time());
+ }
}
$this->hash = substr(hash('sha256', $content), 0, 16);
}
/**
- * @param $data
- * @param (array|mixed)[]|Collection|\Carbon\Carbon|string $data
+ * @param mixed $data
*/
public function store($data): void
{
diff --git a/app/Support/Request/AppendsLocationData.php b/app/Support/Request/AppendsLocationData.php
index 87da9c5c35..4f05f031e7 100644
--- a/app/Support/Request/AppendsLocationData.php
+++ b/app/Support/Request/AppendsLocationData.php
@@ -249,13 +249,4 @@ trait AppendsLocationData
}
- /**
- * Abstract method to ensure filling later.
- *
- * @param string $field
- *
- * @return string|null
- */
- abstract protected function nullableString(string $field): ?string;
-
}
diff --git a/app/Support/Request/ConvertsDataTypes.php b/app/Support/Request/ConvertsDataTypes.php
index 032dd4fbea..d7698ac470 100644
--- a/app/Support/Request/ConvertsDataTypes.php
+++ b/app/Support/Request/ConvertsDataTypes.php
@@ -32,6 +32,70 @@ use Log;
*/
trait ConvertsDataTypes
{
+ /**
+ * Remove weird chars from strings.
+ *
+ * @param string $string
+ * @param bool $keepNewlines
+ *
+ * @return string
+ */
+ public function clearString(string $string, bool $keepNewlines = true): string
+ {
+ $search = [
+ "\u{0001}", // start of heading
+ "\u{0002}", // start of text
+ "\u{0003}", // end of text
+ "\u{0004}", // end of transmission
+ "\u{0005}", // enquiry
+ "\u{0006}", // ACK
+ "\u{0007}", // BEL
+ "\u{0008}", // backspace
+ "\u{000E}", // shift out
+ "\u{000F}", // shift in
+ "\u{0010}", // data link escape
+ "\u{0011}", // DC1
+ "\u{0012}", // DC2
+ "\u{0013}", // DC3
+ "\u{0014}", // DC4
+ "\u{0015}", // NAK
+ "\u{0016}", // SYN
+ "\u{0017}", // ETB
+ "\u{0018}", // CAN
+ "\u{0019}", // EM
+ "\u{001A}", // SUB
+ "\u{001B}", // escape
+ "\u{001C}", // file separator
+ "\u{001D}", // group separator
+ "\u{001E}", // record separator
+ "\u{001F}", // unit separator
+ "\u{007F}", // DEL
+ "\u{00A0}", // non-breaking space
+ "\u{1680}", // ogham space mark
+ "\u{180E}", // mongolian vowel separator
+ "\u{2000}", // en quad
+ "\u{2001}", // em quad
+ "\u{2002}", // en space
+ "\u{2003}", // em space
+ "\u{2004}", // three-per-em space
+ "\u{2005}", // four-per-em space
+ "\u{2006}", // six-per-em space
+ "\u{2007}", // figure space
+ "\u{2008}", // punctuation space
+ "\u{2009}", // thin space
+ "\u{200A}", // hair space
+ "\u{200B}", // zero width space
+ "\u{202F}", // narrow no-break space
+ "\u{3000}", // ideographic space
+ "\u{FEFF}", // zero width no -break space
+ ];
+ $replace = "\x20"; // plain old normal space
+ $string = str_replace($search, $replace, $string);
+ $secondSearch = $keepNewlines ? ["\r"] : ["\r", "\n", "\t", "\036", "\025"];
+ $string = str_replace($secondSearch, '', $string);
+
+ return trim($string);
+ }
/**
* Return integer value.
@@ -46,27 +110,27 @@ trait ConvertsDataTypes
}
/**
- * Return string value, but keep newlines.
+ * Return string value.
*
* @param string $field
*
* @return string
*/
- public function nlString(string $field): string
+ public function string(string $field): string
{
- return app('steam')->nlCleanString((string)($this->get($field) ?? ''));
+ return $this->clearString((string)($this->get($field) ?? ''), false);
}
/**
- * Return string value.
+ * Return string value with newlines.
*
* @param string $field
*
* @return string
*/
- public function string(string $field): string
+ public function stringWithNewlines(string $field): string
{
- return app('steam')->cleanString((string)($this->get($field) ?? ''));
+ return $this->clearString((string)($this->get($field) ?? ''));
}
/**
@@ -222,24 +286,6 @@ trait ConvertsDataTypes
return (int)$string;
}
- /**
- * Parse and clean a string, but keep the newlines.
- *
- * @param string|null $string
- *
- * @return string|null
- */
- protected function nlStringFromValue(?string $string): ?string
- {
- if (null === $string) {
- return null;
- }
- $result = app('steam')->nlCleanString($string);
-
- return '' === $result ? null : $result;
-
- }
-
/**
* Return integer value, or NULL when it's not set.
*
@@ -261,56 +307,4 @@ trait ConvertsDataTypes
return (int)$value;
}
- /**
- * Return string value, but keep newlines, or NULL if empty.
- *
- * @param string $field
- *
- * @return string
- */
- protected function nullableNlString(string $field): ?string
- {
- if (!$this->has($field)) {
- return null;
- }
-
- return app('steam')->nlCleanString((string)($this->get($field) ?? ''));
- }
-
- /**
- * Return string value, or NULL if empty.
- *
- * @param string $field
- *
- * @return string|null
- */
- protected function nullableString(string $field): ?string
- {
- if (!$this->has($field)) {
- return null;
- }
- $res = trim(app('steam')->cleanString((string)($this->get($field) ?? '')));
- if ('' === $res) {
- return null;
- }
-
- return $res;
- }
-
- /**
- * Parse and clean a string.
- *
- * @param string|null $string
- *
- * @return string|null
- */
- protected function stringFromValue(?string $string): ?string
- {
- if (null === $string) {
- return null;
- }
- $result = app('steam')->cleanString($string);
-
- return '' === $result ? null : $result;
- }
}
diff --git a/app/Support/Search/OperatorQuerySearch.php b/app/Support/Search/OperatorQuerySearch.php
index 52a41fa83f..69e3ce241c 100644
--- a/app/Support/Search/OperatorQuerySearch.php
+++ b/app/Support/Search/OperatorQuerySearch.php
@@ -70,14 +70,14 @@ class OperatorQuerySearch implements SearchInterface
private CurrencyRepositoryInterface $currencyRepository;
private Carbon $date;
private int $limit;
-private Collection $modifiers;
+ private Collection $modifiers;
private Collection $operators;
private string $originalQuery;
private int $page;
private ParsedQuery $query;
private float $startTime;
private TagRepositoryInterface $tagRepository;
- private TransactionTypeRepositoryInterface $typeRepository; // obsolete
+ private TransactionTypeRepositoryInterface $typeRepository; // obsolete
private User $user;
private array $validOperators;
private array $words;
@@ -179,7 +179,7 @@ private Collection $modifiers;
public function searchTransactions(): LengthAwarePaginator
{
if (0 === count($this->getWords()) && 0 === count($this->getOperators())) {
- return new LengthAwarePaginator;
+ return new LengthAwarePaginator([],0,5,1);
}
return $this->collector->getPaginatedGroups();
@@ -245,7 +245,9 @@ private Collection $modifiers;
Log::error(sprintf('Cannot handle node %s', $class));
throw new FireflyException(sprintf('Firefly III search cant handle "%s"-nodes', $class));
case Subquery::class:
+ /** @var Subquery $searchNode */
// loop all notes in subquery:
+ /** @var Node $subNode */
foreach ($searchNode->getNodes() as $subNode) {
$this->handleSearchNode($subNode); // lets hope its not too recursive!
}
diff --git a/app/Support/Steam.php b/app/Support/Steam.php
index b10e93f373..0bb1de0400 100644
--- a/app/Support/Steam.php
+++ b/app/Support/Steam.php
@@ -179,8 +179,6 @@ class Steam
$formatted = $start->format('Y-m-d');
$startBalance = $this->balance($account, $start, $currency);
- /** @var AccountRepositoryInterface $repository */
-
$balances[$formatted] = $startBalance;
if (null === $currency) {
$repository = app(AccountRepositoryInterface::class);
@@ -333,136 +331,6 @@ class Steam
return $result;
}
- /**
- * Remove weird chars from strings.
- *
- * @param string $string
- * TODO migrate to trait.
- *
- * @return string
- * @deprecated
- */
- public function cleanString(string $string): string
- {
- $search = [
- "\u{0001}", // start of heading
- "\u{0002}", // start of text
- "\u{0003}", // end of text
- "\u{0004}", // end of transmission
- "\u{0005}", // enquiry
- "\u{0006}", // ACK
- "\u{0007}", // BEL
- "\u{0008}", // backspace
- "\u{000E}", // shift out
- "\u{000F}", // shift in
- "\u{0010}", // data link escape
- "\u{0011}", // DC1
- "\u{0012}", // DC2
- "\u{0013}", // DC3
- "\u{0014}", // DC4
- "\u{0015}", // NAK
- "\u{0016}", // SYN
- "\u{0017}", // ETB
- "\u{0018}", // CAN
- "\u{0019}", // EM
- "\u{001A}", // SUB
- "\u{001B}", // escape
- "\u{001C}", // file separator
- "\u{001D}", // group separator
- "\u{001E}", // record separator
- "\u{001F}", // unit separator
- "\u{007F}", // DEL
- "\u{00A0}", // non-breaking space
- "\u{1680}", // ogham space mark
- "\u{180E}", // mongolian vowel separator
- "\u{2000}", // en quad
- "\u{2001}", // em quad
- "\u{2002}", // en space
- "\u{2003}", // em space
- "\u{2004}", // three-per-em space
- "\u{2005}", // four-per-em space
- "\u{2006}", // six-per-em space
- "\u{2007}", // figure space
- "\u{2008}", // punctuation space
- "\u{2009}", // thin space
- "\u{200A}", // hair space
- "\u{200B}", // zero width space
- "\u{202F}", // narrow no-break space
- "\u{3000}", // ideographic space
- "\u{FEFF}", // zero width no -break space
- ];
- $replace = "\x20"; // plain old normal space
- $string = str_replace($search, $replace, $string);
- $string = str_replace(["\n", "\t", "\r"], "\x20", $string);
-
- return trim($string);
- }
-
- /**
- * Remove weird chars from strings, but keep newlines and tabs.
- *
- * @param string $string
- * TODO migrate to trait.
- *
- * @return string
- * @deprecated
- */
- public function nlCleanString(string $string): string
- {
- $search = [
- "\u{0001}", // start of heading
- "\u{0002}", // start of text
- "\u{0003}", // end of text
- "\u{0004}", // end of transmission
- "\u{0005}", // enquiry
- "\u{0006}", // ACK
- "\u{0007}", // BEL
- "\u{0008}", // backspace
- "\u{000E}", // shift out
- "\u{000F}", // shift in
- "\u{0010}", // data link escape
- "\u{0011}", // DC1
- "\u{0012}", // DC2
- "\u{0013}", // DC3
- "\u{0014}", // DC4
- "\u{0015}", // NAK
- "\u{0016}", // SYN
- "\u{0017}", // ETB
- "\u{0018}", // CAN
- "\u{0019}", // EM
- "\u{001A}", // SUB
- "\u{001B}", // escape
- "\u{001C}", // file separator
- "\u{001D}", // group separator
- "\u{001E}", // record separator
- "\u{001F}", // unit separator
- "\u{007F}", // DEL
- "\u{00A0}", // non-breaking space
- "\u{1680}", // ogham space mark
- "\u{180E}", // mongolian vowel separator
- "\u{2000}", // en quad
- "\u{2001}", // em quad
- "\u{2002}", // en space
- "\u{2003}", // em space
- "\u{2004}", // three-per-em space
- "\u{2005}", // four-per-em space
- "\u{2006}", // six-per-em space
- "\u{2007}", // figure space
- "\u{2008}", // punctuation space
- "\u{2009}", // thin space
- "\u{200A}", // hair space
- "\u{200B}", // zero width space
- "\u{202F}", // narrow no-break space
- "\u{3000}", // ideographic space
- "\u{FEFF}", // zero width no -break space
- ];
- $replace = "\x20"; // plain old normal space
- $string = str_replace($search, $replace, $string);
- $string = str_replace("\r", '', $string);
-
- return trim($string);
- }
-
/**
* @param array $accounts
*
@@ -584,7 +452,6 @@ class Steam
*/
public function getLocale(): string // get preference
{
- /** @var string $language */
$locale = app('preferences')->get('locale', config('firefly.default_locale', 'equal'))->data;
if ('equal' === $locale) {
$locale = $this->getLanguage();
diff --git a/app/Support/Twig/AmountFormat.php b/app/Support/Twig/AmountFormat.php
index 11303f80e0..80d1c17a19 100644
--- a/app/Support/Twig/AmountFormat.php
+++ b/app/Support/Twig/AmountFormat.php
@@ -93,8 +93,7 @@ class AmountFormat extends AbstractExtension
* Will format the amount by the currency related to the given account.
*
* @return TwigFunction
- * @deprecated
- * TODO remove me because it executes a query in a view.
+ * TODO remove me when layout v1 is deprecated.
*/
protected function formatAmountByAccount(): TwigFunction
{
diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.php
index 58da41788b..32b346ef83 100644
--- a/app/Support/Twig/General.php
+++ b/app/Support/Twig/General.php
@@ -355,8 +355,7 @@ class General extends AbstractExtension
/**
* @return TwigFunction
- * @deprecated because it uses a query in a view
- * TODO remove me.
+ * TODO remove me once layout v1 is deprecated.
*/
protected function getMetaField(): TwigFunction
{
diff --git a/app/TransactionRules/Actions/ActionInterface.php b/app/TransactionRules/Actions/ActionInterface.php
index 7da3388e85..0686714f3e 100644
--- a/app/TransactionRules/Actions/ActionInterface.php
+++ b/app/TransactionRules/Actions/ActionInterface.php
@@ -22,20 +22,11 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
-use FireflyIII\Models\RuleAction;
-
/**
* Interface ActionInterface.
*/
interface ActionInterface
{
- /**
- * ActionInterface constructor.
- *
- * @param RuleAction $action
- */
- public function __construct(RuleAction $action);
-
/**
* Execute the action on an array. Returns "true" if the action was a success and the action
* was applied. Returns false if otherwise.
diff --git a/app/TransactionRules/Actions/ClearBudget.php b/app/TransactionRules/Actions/ClearBudget.php
index ebf8e89f88..0890a7ff59 100644
--- a/app/TransactionRules/Actions/ClearBudget.php
+++ b/app/TransactionRules/Actions/ClearBudget.php
@@ -31,15 +31,6 @@ use Log;
*/
class ClearBudget implements ActionInterface
{
- /**
- * TriggerInterface constructor.
- *
- * @param RuleAction $action
- */
- public function __construct(RuleAction $action)
- {
- }
-
/**
* @inheritDoc
*/
diff --git a/app/TransactionRules/Actions/ClearCategory.php b/app/TransactionRules/Actions/ClearCategory.php
index 51133e39e4..4650c09196 100644
--- a/app/TransactionRules/Actions/ClearCategory.php
+++ b/app/TransactionRules/Actions/ClearCategory.php
@@ -31,15 +31,6 @@ use Log;
*/
class ClearCategory implements ActionInterface
{
- /**
- * TriggerInterface constructor.
- *
- * @param RuleAction $action
- */
- public function __construct(RuleAction $action)
- {
- }
-
/**
* @inheritDoc
*/
diff --git a/app/TransactionRules/Actions/ClearNotes.php b/app/TransactionRules/Actions/ClearNotes.php
index 54c55546a4..5e75226a11 100644
--- a/app/TransactionRules/Actions/ClearNotes.php
+++ b/app/TransactionRules/Actions/ClearNotes.php
@@ -32,15 +32,6 @@ use Log;
*/
class ClearNotes implements ActionInterface
{
- /**
- * TriggerInterface constructor.
- *
- * @param RuleAction $action
- */
- public function __construct(RuleAction $action)
- {
- }
-
/**
* @inheritDoc
*/
diff --git a/app/TransactionRules/Actions/ConvertToDeposit.php b/app/TransactionRules/Actions/ConvertToDeposit.php
index cb4fbd3575..70b78f862a 100644
--- a/app/TransactionRules/Actions/ConvertToDeposit.php
+++ b/app/TransactionRules/Actions/ConvertToDeposit.php
@@ -149,7 +149,6 @@ class ConvertToDeposit implements ActionInterface
$revenue = $factory->findOrCreate($revenueName, AccountType::REVENUE);
Log::debug(sprintf('ConvertToDeposit. Action value is "%s", revenue name is "%s"', $this->action->action_value, $journal['source_account_name']));
- unset($source);
// update source transaction(s) to be revenue account
DB::table('transactions')
diff --git a/app/TransactionRules/Actions/DeleteTransaction.php b/app/TransactionRules/Actions/DeleteTransaction.php
index 29c9c7739c..a4108d0baf 100644
--- a/app/TransactionRules/Actions/DeleteTransaction.php
+++ b/app/TransactionRules/Actions/DeleteTransaction.php
@@ -22,7 +22,6 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
-use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
@@ -34,15 +33,6 @@ use Log;
*/
class DeleteTransaction implements ActionInterface
{
- /**
- * TriggerInterface constructor.
- *
- * @param RuleAction $action
- */
- public function __construct(RuleAction $action)
- {
- }
-
/**
* @inheritDoc
*/
diff --git a/app/TransactionRules/Actions/RemoveAllTags.php b/app/TransactionRules/Actions/RemoveAllTags.php
index 1bdff35085..f49ce6e34a 100644
--- a/app/TransactionRules/Actions/RemoveAllTags.php
+++ b/app/TransactionRules/Actions/RemoveAllTags.php
@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
use DB;
-use FireflyIII\Models\RuleAction;
use Log;
/**
@@ -31,15 +30,6 @@ use Log;
*/
class RemoveAllTags implements ActionInterface
{
- /**
- * TriggerInterface constructor.
- *
- * @param RuleAction $action
- */
- public function __construct(RuleAction $action)
- {
- }
-
/**
* @inheritDoc
*/
@@ -50,4 +40,5 @@ class RemoveAllTags implements ActionInterface
return true;
}
+
}
diff --git a/app/TransactionRules/Actions/SetDestinationAccount.php b/app/TransactionRules/Actions/SetDestinationAccount.php
index c219a4fd9d..c530568177 100644
--- a/app/TransactionRules/Actions/SetDestinationAccount.php
+++ b/app/TransactionRules/Actions/SetDestinationAccount.php
@@ -56,12 +56,9 @@ class SetDestinationAccount implements ActionInterface
*/
public function actOnArray(array $journal): bool
{
- /** @var TransactionJournal $object */
- /** @var AccountRepositoryInterface repository */
- /** @var Transaction $source */
-
$user = User::find($journal['user_id']);
$type = $journal['transaction_type_type'];
+ /** @var TransactionJournal|null $object */
$object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']);
$this->repository = app(AccountRepositoryInterface::class);
@@ -86,6 +83,7 @@ class SetDestinationAccount implements ActionInterface
}
// new destination account must be different from the current source account:
+ /** @var Transaction|null $source */
$source = $object->transactions()->where('amount', '<', 0)->first();
if (null === $source) {
Log::error('Could not find source transaction.');
@@ -113,11 +111,6 @@ class SetDestinationAccount implements ActionInterface
if (TransactionType::WITHDRAWAL === $type) {
$newAccount = $this->findExpenseAccount();
}
- if (null === $newAccount) {
- Log::error('New expense account is NULL');
-
- return false;
- }
Log::debug(sprintf('New destination account is #%d ("%s").', $newAccount->id, $newAccount->name));
@@ -150,9 +143,9 @@ class SetDestinationAccount implements ActionInterface
}
/**
- * @return Account|null
+ * @return Account
*/
- private function findExpenseAccount(): ?Account
+ private function findExpenseAccount(): Account
{
$account = $this->repository->findByName($this->action->action_value, [AccountType::EXPENSE]);
if (null === $account) {
diff --git a/app/TransactionRules/Actions/SetSourceAccount.php b/app/TransactionRules/Actions/SetSourceAccount.php
index 4160d6775b..6c1f709c1d 100644
--- a/app/TransactionRules/Actions/SetSourceAccount.php
+++ b/app/TransactionRules/Actions/SetSourceAccount.php
@@ -55,12 +55,9 @@ class SetSourceAccount implements ActionInterface
*/
public function actOnArray(array $journal): bool
{
- /** @var TransactionJournal $object */
- /** @var AccountRepositoryInterface repository */
- /** @var Transaction $destination */
-
$user = User::find($journal['user_id']);
$type = $journal['transaction_type_type'];
+ /** @var TransactionJournal|null $object */
$object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']);
$this->repository = app(AccountRepositoryInterface::class);
@@ -83,6 +80,7 @@ class SetSourceAccount implements ActionInterface
}
// new source account must be different from the current destination account:
+ /** @var Transaction|null $destination */
$destination = $object->transactions()->where('amount', '>', 0)->first();
if (null === $destination) {
Log::error('Could not find destination transaction.');
@@ -110,11 +108,6 @@ class SetSourceAccount implements ActionInterface
if (TransactionType::DEPOSIT === $type) {
$newAccount = $this->findRevenueAccount();
}
- if (null === $newAccount) {
- Log::error('New account is NULL');
-
- return false;
- }
Log::debug(sprintf('New source account is #%d ("%s").', $newAccount->id, $newAccount->name));
@@ -145,9 +138,9 @@ class SetSourceAccount implements ActionInterface
}
/**
- * @return Account|null
+ * @return Account
*/
- private function findRevenueAccount(): ?Account
+ private function findRevenueAccount(): Account
{
$allowed = config('firefly.expected_source_types.source.Deposit');
$account = $this->repository->findByName($this->action->action_value, $allowed);
diff --git a/app/TransactionRules/Engine/SearchRuleEngine.php b/app/TransactionRules/Engine/SearchRuleEngine.php
index 0105e3a48b..e9c8df73bd 100644
--- a/app/TransactionRules/Engine/SearchRuleEngine.php
+++ b/app/TransactionRules/Engine/SearchRuleEngine.php
@@ -390,7 +390,7 @@ class SearchRuleEngine implements RuleEngineInterface
$result = $actionClass->actOnArray($transaction);
$journalId = $transaction['transaction_journal_id'] ?? 0;
if (true === $result) {
- $this->resultCount[$journalId] = isset($this->resultCount[$journalId]) ? $this->resultCount[$journalId]++ : 1;
+ $this->resultCount[$journalId] = array_key_exists($journalId, $this->resultCount) ? $this->resultCount[$journalId]++ : 1;
Log::debug(
sprintf(
'Action "%s" on journal #%d was executed, so count a result. Updated transaction journal count is now %d.',
@@ -514,7 +514,7 @@ class SearchRuleEngine implements RuleEngineInterface
{
$all = false;
Log::debug(sprintf('Going to fire group #%d with %d rule(s)', $group->id, $group->rules->count()));
- /** @var $rule */
+ /** @var Rule $rule */
foreach ($group->rules as $rule) {
Log::debug(sprintf('Going to fire rule #%d from group #%d', $rule->id, $group->id));
$result = $this->fireRule($rule);
diff --git a/app/Transformers/AbstractTransformer.php b/app/Transformers/AbstractTransformer.php
index fe4e8ec761..1e76cf7ac1 100644
--- a/app/Transformers/AbstractTransformer.php
+++ b/app/Transformers/AbstractTransformer.php
@@ -37,7 +37,7 @@ abstract class AbstractTransformer extends TransformerAbstract
/**
* @return ParameterBag
*/
- public function getParameters(): ParameterBag
+ final public function getParameters(): ParameterBag
{
return $this->parameters;
}
@@ -45,7 +45,7 @@ abstract class AbstractTransformer extends TransformerAbstract
/**
* @param ParameterBag $parameters
*/
- public function setParameters(ParameterBag $parameters): void
+ final public function setParameters(ParameterBag $parameters): void
{
$this->parameters = $parameters;
}
diff --git a/app/Transformers/AccountTransformer.php b/app/Transformers/AccountTransformer.php
index ad450c9ec1..97cccf7953 100644
--- a/app/Transformers/AccountTransformer.php
+++ b/app/Transformers/AccountTransformer.php
@@ -206,8 +206,6 @@ class AccountTransformer extends AbstractTransformer
* @param Account $account
* @param string $accountType
*
- * @param int $decimalPlaces
- *
* @return array
*
* TODO refactor call to getOpeningBalanceAmount / Date because its extra queries.
diff --git a/app/Transformers/AvailableBudgetTransformer.php b/app/Transformers/AvailableBudgetTransformer.php
index a85e0e2da6..9ed54128b1 100644
--- a/app/Transformers/AvailableBudgetTransformer.php
+++ b/app/Transformers/AvailableBudgetTransformer.php
@@ -22,11 +22,11 @@
declare(strict_types=1);
namespace FireflyIII\Transformers;
+
use FireflyIII\Models\AvailableBudget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\NoBudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
-use Illuminate\Support\Collection;
/**
* Class AvailableBudgetTransformer
@@ -97,11 +97,9 @@ class AvailableBudgetTransformer extends AbstractTransformer
private function getSpentInBudgets(): array
{
$allActive = $this->repository->getActiveBudgets();
+ $sums = $this->opsRepository->sumExpenses($this->parameters->get('start'), $this->parameters->get('end'), null, $allActive);
- return $this->opsRepository->spentInPeriodMc(
- $allActive, new Collection, $this->parameters->get('start'), $this->parameters->get('end')
- );
-
+ return array_values($sums);
}
/**
@@ -109,7 +107,8 @@ class AvailableBudgetTransformer extends AbstractTransformer
*/
private function spentOutsideBudgets(): array
{
- return $this->noBudgetRepository->spentInPeriodWoBudgetMc(new Collection, $this->parameters->get('start'), $this->parameters->get('end'));
- }
+ $sums = $this->noBudgetRepository->sumExpenses($this->parameters->get('start'), $this->parameters->get('end'));
+ return array_values($sums);
+ }
}
diff --git a/app/Transformers/BillTransformer.php b/app/Transformers/BillTransformer.php
index 61fa145cd9..224287d539 100644
--- a/app/Transformers/BillTransformer.php
+++ b/app/Transformers/BillTransformer.php
@@ -212,7 +212,7 @@ class BillTransformer extends AbstractTransformer
return $default; // @codeCoverageIgnore
}
$latest = $dates->first()->date;
- /** @var TransactionJournal $date */
+ /** @var TransactionJournal $journal */
foreach ($dates as $journal) {
if ($journal->date->gte($latest)) {
$latest = $journal->date;
diff --git a/app/Transformers/CurrencyExchangeRateTransformer.php b/app/Transformers/CurrencyExchangeRateTransformer.php
deleted file mode 100644
index 2f4f72796a..0000000000
--- a/app/Transformers/CurrencyExchangeRateTransformer.php
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-/**
- * CurrencyExchangeRateTransformer.php
- * Copyright (c) 2019 [email protected]
- *
- * This file is part of Firefly III (https://github.com/firefly-iii).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-declare(strict_types=1);
-
-namespace FireflyIII\Transformers;
-use FireflyIII\Models\CurrencyExchangeRate;
-
-/**
- * Class CurrencyExchangeRateTransformer
- */
-class CurrencyExchangeRateTransformer extends AbstractTransformer
-{
- /**
- * @param CurrencyExchangeRate $rate
- *
- * @return array
- */
- public function transform(CurrencyExchangeRate $rate): array
- {
- $result = number_format((float)$rate->rate * (float)$this->parameters->get('amount'), $rate->toCurrency->decimal_places, '.', '');
- $result = 0.0 === $result ? null : $result;
-
- return [
- 'id' => (int)$rate->id,
- 'created_at' => $rate->created_at->toAtomString(),
- 'updated_at' => $rate->updated_at->toAtomString(),
- 'from_currency_id' => (int)$rate->fromCurrency->id,
- 'from_currency_name' => $rate->fromCurrency->name,
- 'from_currency_code' => $rate->fromCurrency->code,
- 'from_currency_symbol' => $rate->fromCurrency->symbol,
- 'from_currency_decimal_places' => (int)$rate->fromCurrency->decimal_places,
- 'to_currency_id' => (int)$rate->toCurrency->id,
- 'to_currency_name' => $rate->toCurrency->name,
- 'to_currency_code' => $rate->toCurrency->code,
- 'to_currency_symbol' => $rate->toCurrency->symbol,
- 'to_currency_decimal_places' => (int)$rate->toCurrency->decimal_places,
- 'date' => $rate->date->format('Y-m-d'),
- 'rate' => (float)$rate->rate,
- 'amount' => $result,
- 'links' => [
- [
- 'rel' => 'self',
- 'uri' => '/currency_exchange_rates/' . $rate->id,
- ],
- ],
- ];
- }
-}
diff --git a/app/Transformers/RecurrenceTransformer.php b/app/Transformers/RecurrenceTransformer.php
index ae69d7de8b..945d97c011 100644
--- a/app/Transformers/RecurrenceTransformer.php
+++ b/app/Transformers/RecurrenceTransformer.php
@@ -276,7 +276,6 @@ class RecurrenceTransformer extends AbstractTransformer
$array['category_name'] = $category->name;
}
break;
- break;
case 'category_name':
$category = $this->factory->findOrCreate(null, $transactionMeta->value);
if (null !== $category) {
diff --git a/app/Transformers/TransactionGroupTransformer.php b/app/Transformers/TransactionGroupTransformer.php
index 2c74cfda85..2429718425 100644
--- a/app/Transformers/TransactionGroupTransformer.php
+++ b/app/Transformers/TransactionGroupTransformer.php
@@ -304,7 +304,7 @@ class TransactionGroupTransformer extends AbstractTransformer
} catch (FireflyException $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
- throw new FireflyException(sprintf('Transaction group #%d is broken. Please check out your log files.', $group->id));
+ throw new FireflyException(sprintf('Transaction group #%d is broken. Please check out your log files.', $group->id), 0, $e);
}
// do something else.
diff --git a/app/User.php b/app/User.php
index 91b37f202d..bfb66bb0b0 100644
--- a/app/User.php
+++ b/app/User.php
@@ -67,17 +67,14 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
*
* @property int $id
* @property string $email
- * @property bool $isAdmin used in admin user
- * controller.
- * @property bool $has2FA used in admin user
- * controller.
- * @property array $prefs used in admin user
- * controller.
- * @property string password
+ * @property bool $isAdmin
+ * @property bool $has2FA
+ * @property array $prefs
+ * @property string $password
* @property string $mfa_secret
- * @property Collection roles
- * @property string blocked_code
- * @property bool blocked
+ * @property Collection $roles
+ * @property string $blocked_code
+ * @property bool $blocked
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property string|null $remember_token
diff --git a/app/Validation/Account/DepositValidation.php b/app/Validation/Account/DepositValidation.php
index c9661a2c33..9f3c57e3aa 100644
--- a/app/Validation/Account/DepositValidation.php
+++ b/app/Validation/Account/DepositValidation.php
@@ -34,7 +34,7 @@ trait DepositValidation
{
/**
* @param int|null $accountId
- * @param $accountName
+ * @param mixed $accountName
*
* @return bool
*/