mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Various PSR12 code cleanup
This commit is contained in:
@@ -85,73 +85,73 @@ class StoreRequest extends FormRequest
|
||||
$return[] = [
|
||||
'type' => $this->clearString($object['type'], false),
|
||||
'date' => $this->dateFromValue($object['date']),
|
||||
'order' => $this->integerFromValue((string) $object['order']),
|
||||
'order' => $this->integerFromValue((string)$object['order']),
|
||||
|
||||
'currency_id' => $this->integerFromValue((string) $object['currency_id']),
|
||||
'currency_code' => $this->clearString((string) $object['currency_code'], false),
|
||||
'currency_id' => $this->integerFromValue((string)$object['currency_id']),
|
||||
'currency_code' => $this->clearString((string)$object['currency_code'], false),
|
||||
|
||||
// foreign currency info:
|
||||
'foreign_currency_id' => $this->integerFromValue((string) $object['foreign_currency_id']),
|
||||
'foreign_currency_code' => $this->clearString((string) $object['foreign_currency_code'], false),
|
||||
'foreign_currency_id' => $this->integerFromValue((string)$object['foreign_currency_id']),
|
||||
'foreign_currency_code' => $this->clearString((string)$object['foreign_currency_code'], false),
|
||||
|
||||
// amount and foreign amount. Cannot be 0.
|
||||
'amount' => $this->clearString((string) $object['amount'], false),
|
||||
'foreign_amount' => $this->clearString((string) $object['foreign_amount'], false),
|
||||
'amount' => $this->clearString((string)$object['amount'], false),
|
||||
'foreign_amount' => $this->clearString((string)$object['foreign_amount'], false),
|
||||
|
||||
// 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->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),
|
||||
'source_id' => $this->integerFromValue((string)$object['source_id']),
|
||||
'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->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),
|
||||
'destination_id' => $this->integerFromValue((string)$object['destination_id']),
|
||||
'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->clearString((string) $object['budget_name'], false),
|
||||
'budget_id' => $this->integerFromValue((string)$object['budget_id']),
|
||||
'budget_name' => $this->clearString((string)$object['budget_name'], false),
|
||||
|
||||
// category info
|
||||
'category_id' => $this->integerFromValue((string) $object['category_id']),
|
||||
'category_name' => $this->clearString((string) $object['category_name'], false),
|
||||
'category_id' => $this->integerFromValue((string)$object['category_id']),
|
||||
'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->clearString((string) $object['bill_name'], false),
|
||||
'bill_id' => $this->integerFromValue((string)$object['bill_id']),
|
||||
'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->clearString((string) $object['piggy_bank_name'], false),
|
||||
'piggy_bank_id' => $this->integerFromValue((string)$object['piggy_bank_id']),
|
||||
'piggy_bank_name' => $this->clearString((string)$object['piggy_bank_name'], false),
|
||||
|
||||
// some other interesting properties
|
||||
'reconciled' => $this->convertBoolean((string) $object['reconciled']),
|
||||
'notes' => $this->clearString((string) $object['notes']),
|
||||
'reconciled' => $this->convertBoolean((string)$object['reconciled']),
|
||||
'notes' => $this->clearString((string)$object['notes']),
|
||||
'tags' => $this->arrayFromValue($object['tags']),
|
||||
|
||||
// all custom fields:
|
||||
'internal_reference' => $this->clearString((string) $object['internal_reference'], false),
|
||||
'external_id' => $this->clearString((string) $object['external_id'], false),
|
||||
'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->clearString((string) $object['bunq_payment_id'], false),
|
||||
'external_url' => $this->clearString((string) $object['external_url'], false),
|
||||
'bunq_payment_id' => $this->clearString((string)$object['bunq_payment_id'], false),
|
||||
'external_url' => $this->clearString((string)$object['external_url'], false),
|
||||
|
||||
'sepa_cc' => $this->clearString((string) $object['sepa_cc'], false),
|
||||
'sepa_ct_op' => $this->clearString((string) $object['sepa_ct_op'], false),
|
||||
'sepa_ct_id' => $this->clearString((string) $object['sepa_ct_id'], false),
|
||||
'sepa_db' => $this->clearString((string) $object['sepa_db'], false),
|
||||
'sepa_country' => $this->clearString((string) $object['sepa_country'], false),
|
||||
'sepa_ep' => $this->clearString((string) $object['sepa_ep'], false),
|
||||
'sepa_ci' => $this->clearString((string) $object['sepa_ci'], false),
|
||||
'sepa_batch_id' => $this->clearString((string) $object['sepa_batch_id'], false),
|
||||
'sepa_cc' => $this->clearString((string)$object['sepa_cc'], false),
|
||||
'sepa_ct_op' => $this->clearString((string)$object['sepa_ct_op'], false),
|
||||
'sepa_ct_id' => $this->clearString((string)$object['sepa_ct_id'], false),
|
||||
'sepa_db' => $this->clearString((string)$object['sepa_db'], false),
|
||||
'sepa_country' => $this->clearString((string)$object['sepa_country'], false),
|
||||
'sepa_ep' => $this->clearString((string)$object['sepa_ep'], false),
|
||||
'sepa_ci' => $this->clearString((string)$object['sepa_ci'], false),
|
||||
'sepa_batch_id' => $this->clearString((string)$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']),
|
||||
@@ -258,7 +258,7 @@ class StoreRequest extends FormRequest
|
||||
/**
|
||||
* Configure the validator instance.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
@@ -49,9 +49,9 @@ class UpdateRequest extends FormRequest
|
||||
private array $arrayFields;
|
||||
private array $booleanFields;
|
||||
private array $dateFields;
|
||||
private array $floatFields;
|
||||
private array $integerFields;
|
||||
private array $stringFields;
|
||||
private array $floatFields;
|
||||
private array $textareaFields;
|
||||
|
||||
/**
|
||||
@@ -89,8 +89,8 @@ class UpdateRequest extends FormRequest
|
||||
];
|
||||
|
||||
$this->floatFields = [ // not really floats, for validation.
|
||||
'amount',
|
||||
'foreign_amount',
|
||||
'amount',
|
||||
'foreign_amount',
|
||||
];
|
||||
|
||||
$this->stringFields = [
|
||||
@@ -180,8 +180,8 @@ class UpdateRequest extends FormRequest
|
||||
/**
|
||||
* For each field, add it to the array if a reference is present in the request:
|
||||
*
|
||||
* @param array $current
|
||||
* @param array $transaction
|
||||
* @param array $current
|
||||
* @param array $transaction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -189,7 +189,7 @@ class UpdateRequest extends FormRequest
|
||||
{
|
||||
foreach ($this->integerFields as $fieldName) {
|
||||
if (array_key_exists($fieldName, $transaction)) {
|
||||
$current[$fieldName] = $this->integerFromValue((string) $transaction[$fieldName]);
|
||||
$current[$fieldName] = $this->integerFromValue((string)$transaction[$fieldName]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,8 +197,8 @@ class UpdateRequest extends FormRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $current
|
||||
* @param array $transaction
|
||||
* @param array $current
|
||||
* @param array $transaction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -206,7 +206,7 @@ class UpdateRequest extends FormRequest
|
||||
{
|
||||
foreach ($this->stringFields as $fieldName) {
|
||||
if (array_key_exists($fieldName, $transaction)) {
|
||||
$current[$fieldName] = $this->clearString((string) $transaction[$fieldName], false);
|
||||
$current[$fieldName] = $this->clearString((string)$transaction[$fieldName], false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,8 +214,8 @@ class UpdateRequest extends FormRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $current
|
||||
* @param array $transaction
|
||||
* @param array $current
|
||||
* @param array $transaction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -223,7 +223,7 @@ class UpdateRequest extends FormRequest
|
||||
{
|
||||
foreach ($this->textareaFields as $fieldName) {
|
||||
if (array_key_exists($fieldName, $transaction)) {
|
||||
$current[$fieldName] = $this->clearString((string) $transaction[$fieldName]);
|
||||
$current[$fieldName] = $this->clearString((string)$transaction[$fieldName]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,8 +231,8 @@ class UpdateRequest extends FormRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $current
|
||||
* @param array $transaction
|
||||
* @param array $current
|
||||
* @param array $transaction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -241,8 +241,8 @@ class UpdateRequest extends FormRequest
|
||||
foreach ($this->dateFields as $fieldName) {
|
||||
Log::debug(sprintf('Now at date field %s', $fieldName));
|
||||
if (array_key_exists($fieldName, $transaction)) {
|
||||
Log::debug(sprintf('New value: "%s"', (string) $transaction[$fieldName]));
|
||||
$current[$fieldName] = $this->dateFromValue((string) $transaction[$fieldName]);
|
||||
Log::debug(sprintf('New value: "%s"', (string)$transaction[$fieldName]));
|
||||
$current[$fieldName] = $this->dateFromValue((string)$transaction[$fieldName]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,8 +250,8 @@ class UpdateRequest extends FormRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $current
|
||||
* @param array $transaction
|
||||
* @param array $current
|
||||
* @param array $transaction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -259,7 +259,7 @@ class UpdateRequest extends FormRequest
|
||||
{
|
||||
foreach ($this->booleanFields as $fieldName) {
|
||||
if (array_key_exists($fieldName, $transaction)) {
|
||||
$current[$fieldName] = $this->convertBoolean((string) $transaction[$fieldName]);
|
||||
$current[$fieldName] = $this->convertBoolean((string)$transaction[$fieldName]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,8 +267,8 @@ class UpdateRequest extends FormRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $current
|
||||
* @param array $transaction
|
||||
* @param array $current
|
||||
* @param array $transaction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -283,6 +283,28 @@ class UpdateRequest extends FormRequest
|
||||
return $current;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $current
|
||||
* @param array $transaction
|
||||
* @return array
|
||||
*/
|
||||
private function getFloatData(array $current, array $transaction): array
|
||||
{
|
||||
foreach ($this->floatFields as $fieldName) {
|
||||
if (array_key_exists($fieldName, $transaction)) {
|
||||
$value = $transaction[$fieldName];
|
||||
if (is_float($value)) {
|
||||
$current[$fieldName] = sprintf('%.24f', $value);
|
||||
}
|
||||
if (!is_float($value)) {
|
||||
$current[$fieldName] = (string)$value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $current;
|
||||
}
|
||||
|
||||
/**
|
||||
* The rules that the incoming request must be matched against.
|
||||
*
|
||||
@@ -368,7 +390,7 @@ class UpdateRequest extends FormRequest
|
||||
/**
|
||||
* Configure the validator instance.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -396,26 +418,4 @@ class UpdateRequest extends FormRequest
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $current
|
||||
* @param array $transaction
|
||||
* @return array
|
||||
*/
|
||||
private function getFloatData(array $current, array $transaction): array
|
||||
{
|
||||
foreach ($this->floatFields as $fieldName) {
|
||||
if (array_key_exists($fieldName, $transaction)) {
|
||||
$value = $transaction[$fieldName];
|
||||
if (is_float($value)) {
|
||||
$current[$fieldName] = sprintf('%.24f', $value);
|
||||
}
|
||||
if (!is_float($value)) {
|
||||
$current[$fieldName] = (string) $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $current;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user