Code cleanup

This commit is contained in:
James Cole
2021-03-21 09:15:40 +01:00
parent da1751940e
commit 206845575c
317 changed files with 7418 additions and 7362 deletions

View File

@@ -70,7 +70,7 @@ class UpdateRequest extends FormRequest
'currency_code' => ['currency_code', 'string'],
];
$data = $this->getAllData($fields);
$data = $this->appendLocationData($data, null);
$data = $this->appendLocationData($data, null);
if (array_key_exists('account_type', $data) && 'liability' === $data['account_type']) {
$data['opening_balance'] = bcmul($this->nullableString('liability_amount'), '-1');

View File

@@ -44,9 +44,10 @@ class UpdateRequest extends FormRequest
public function getAll(): array
{
$fields = [
'name' => ['name', 'string'],
'notes' => ['notes', 'nlString']
'name' => ['name', 'string'],
'notes' => ['notes', 'nlString'],
];
return $this->getAllData($fields);
}

View File

@@ -44,8 +44,9 @@ class UpdateRequest extends FormRequest
{
$fields = [
'title' => ['title', 'string'],
'order' =>['order', 'integer']
'order' => ['order', 'integer'],
];
return $this->getAllData($fields);
}

View File

@@ -76,29 +76,6 @@ class UpdateRequest extends FormRequest
return $return;
}
/**
* Returns the transaction data as it is found in the submitted data. It's a complex method according to code
* standards but it just has a lot of ??-statements because of the fields that may or may not exist.
*
* @return array|null
*/
private function getTransactionData(): ?array
{
$return = [];
// transaction data:
/** @var array $transactions */
$transactions = $this->get('transactions');
if (null === $transactions) {
return null;
}
/** @var array $transaction */
foreach ($transactions as $transaction) {
$return[] = $this->getSingleTransactionData($transaction);
}
return $return;
}
/**
* Returns the repetition data as it is found in the submitted data.
*
@@ -140,6 +117,29 @@ class UpdateRequest extends FormRequest
return $return;
}
/**
* Returns the transaction data as it is found in the submitted data. It's a complex method according to code
* standards but it just has a lot of ??-statements because of the fields that may or may not exist.
*
* @return array|null
*/
private function getTransactionData(): ?array
{
$return = [];
// transaction data:
/** @var array $transactions */
$transactions = $this->get('transactions');
if (null === $transactions) {
return null;
}
/** @var array $transaction */
foreach ($transactions as $transaction) {
$return[] = $this->getSingleTransactionData($transaction);
}
return $return;
}
/**
* The rules that the incoming request must be matched against.
*

View File

@@ -38,7 +38,6 @@ class TriggerRequest extends FormRequest
use ConvertsDataTypes, ChecksLogin;
/**
* @return array
*/

View File

@@ -59,10 +59,10 @@ class UpdateRequest extends FormRequest
$return = $this->getAllData($fields);
$triggers = $this->getRuleTriggers();
$actions = $this->getRuleActions();
if(null !== $triggers) {
if (null !== $triggers) {
$return['triggers'] = $triggers;
}
if(null !== $actions) {
if (null !== $actions) {
$return['actions'] = $actions;
}
@@ -81,9 +81,9 @@ class UpdateRequest extends FormRequest
$return = [];
if (is_array($triggers)) {
foreach ($triggers as $trigger) {
$active = array_key_exists('active', $trigger) ? $trigger['active'] : true;
$stopProcessing= array_key_exists('stop_processing', $trigger) ? $trigger['stop_processing'] : false;
$return[] = [
$active = array_key_exists('active', $trigger) ? $trigger['active'] : true;
$stopProcessing = array_key_exists('stop_processing', $trigger) ? $trigger['stop_processing'] : false;
$return[] = [
'type' => $trigger['type'],
'value' => $trigger['value'],
'active' => $active,

View File

@@ -29,7 +29,6 @@ use Carbon\Carbon;
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Collection;
/**
* Class TestRequest
@@ -39,7 +38,6 @@ class TestRequest extends FormRequest
use ConvertsDataTypes, ChecksLogin;
/**
* @return array
*/

View File

@@ -38,7 +38,6 @@ class TriggerRequest extends FormRequest
use ConvertsDataTypes, ChecksLogin;
/**
* @return array
*/

View File

@@ -59,6 +59,7 @@ class StoreRequest extends FormRequest
'apply_rules' => $this->boolean('apply_rules', true),
'transactions' => $this->getTransactionData(),
];
// TODO location
return $data;
}
@@ -79,64 +80,64 @@ class StoreRequest extends FormRequest
$return[] = [
'type' => $this->stringFromValue($object['type']),
'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_id' => $this->integerFromValue((string)$object['currency_id']),
'currency_code' => $this->stringFromValue($object['currency_code']),
// 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_id' => $this->integerFromValue((string)$object['foreign_currency_id']),
'foreign_currency_code' => $this->stringFromValue((string)$object['foreign_currency_code']),
// amount and foreign amount. Cannot be 0.
'amount' => $this->stringFromValue((string) $object['amount']),
'foreign_amount' => $this->stringFromValue((string) $object['foreign_amount']),
'amount' => $this->stringFromValue((string)$object['amount']),
'foreign_amount' => $this->stringFromValue((string)$object['foreign_amount']),
// description.
'description' => $this->stringFromValue($object['description']),
// 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_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']),
// 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_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']),
// budget info
'budget_id' => $this->integerFromValue((string) $object['budget_id']),
'budget_name' => $this->stringFromValue((string) $object['budget_name']),
'budget_id' => $this->integerFromValue((string)$object['budget_id']),
'budget_name' => $this->stringFromValue((string)$object['budget_name']),
// category info
'category_id' => $this->integerFromValue((string) $object['category_id']),
'category_name' => $this->stringFromValue((string) $object['category_name']),
'category_id' => $this->integerFromValue((string)$object['category_id']),
'category_name' => $this->stringFromValue((string)$object['category_name']),
// 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_id' => $this->integerFromValue((string)$object['bill_id']),
'bill_name' => $this->stringFromValue((string)$object['bill_name']),
// 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_id' => $this->integerFromValue((string)$object['piggy_bank_id']),
'piggy_bank_name' => $this->stringFromValue((string)$object['piggy_bank_name']),
// some other interesting properties
'reconciled' => $this->convertBoolean((string) $object['reconciled']),
'notes' => $this->nlStringFromValue((string) $object['notes']),
'reconciled' => $this->convertBoolean((string)$object['reconciled']),
'notes' => $this->nlStringFromValue((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->stringFromValue((string)$object['internal_reference']),
'external_id' => $this->stringFromValue((string)$object['external_id']),
'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']),
'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']),

View File

@@ -156,13 +156,13 @@ class UpdateRequest extends FormRequest
*/
foreach ($this->get('transactions') as $transaction) {
// default response is to update nothing in the transaction:
$current = [];
$current = $this->getIntegerData($current, $transaction);
$current = $this->getStringData($current, $transaction);
$current = $this->getNlStringData($current, $transaction);
$current = $this->getDateData($current, $transaction);
$current = $this->getBooleanData($current, $transaction);
$current = $this->getArrayData($current, $transaction);
$current = [];
$current = $this->getIntegerData($current, $transaction);
$current = $this->getStringData($current, $transaction);
$current = $this->getNlStringData($current, $transaction);
$current = $this->getDateData($current, $transaction);
$current = $this->getBooleanData($current, $transaction);
$current = $this->getArrayData($current, $transaction);
$return[] = $current;
}

View File

@@ -102,8 +102,8 @@ class StoreRequest extends FormRequest
$journalRepos->setUser($user);
$data = $validator->getData();
$inwardId = (int) ($data['inward_id'] ?? 0);
$outwardId = (int) ($data['outward_id'] ?? 0);
$inwardId = (int)($data['inward_id'] ?? 0);
$outwardId = (int)($data['outward_id'] ?? 0);
$inward = $journalRepos->findNull($inwardId);
$outward = $journalRepos->findNull($outwardId);

View File

@@ -23,11 +23,9 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests\Models\TransactionLinkType;
use FireflyIII\Models\LinkType;
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
/**
* Class StoreRequest

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests\Models\TransactionLinkType;
use FireflyIII\Models\LinkType;
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Foundation\Http\FormRequest;
@@ -61,7 +60,8 @@ class UpdateRequest extends FormRequest
*/
public function rules(): array
{
$linkType = $this->route()->parameter('linkType');
$linkType = $this->route()->parameter('linkType');
return [
'name' => [Rule::unique('link_types', 'name')->ignore($linkType->id), 'min:1'],
'outward' => ['different:inward', Rule::unique('link_types', 'outward')->ignore($linkType->id), 'min:1'],