mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-01 11:47:14 -06:00
Update requests to use uniform methods.
This commit is contained in:
parent
6b57d4397a
commit
8635fe7ebb
@ -51,7 +51,6 @@ final class Entry
|
||||
public $destination_account_id;
|
||||
public $destination_account_name;
|
||||
|
||||
|
||||
public $budget_id;
|
||||
public $budget_name;
|
||||
public $category_id;
|
||||
|
@ -39,21 +39,21 @@ class AccountFormRequest extends Request
|
||||
public function getAccountData(): array
|
||||
{
|
||||
return [
|
||||
'name' => trim(strval($this->input('name'))),
|
||||
'name' => $this->getFieldOrEmptyString('name'),
|
||||
'active' => intval($this->input('active')) === 1,
|
||||
'accountType' => $this->input('what'),
|
||||
'accountType' => $this->getFieldOrEmptyString('what'),
|
||||
'currency_id' => intval($this->input('currency_id')),
|
||||
'virtualBalance' => round($this->input('virtualBalance'), 12),
|
||||
'virtualBalanceCurrency' => intval($this->input('amount_currency_id_virtualBalance')),
|
||||
'iban' => trim(strval($this->input('iban'))),
|
||||
'BIC' => trim(strval($this->input('BIC'))),
|
||||
'accountNumber' => trim(strval($this->input('accountNumber'))),
|
||||
'accountRole' => $this->input('accountRole'),
|
||||
'iban' => $this->getFieldOrEmptyString('iban'),
|
||||
'BIC' => $this->getFieldOrEmptyString('BIC'),
|
||||
'accountNumber' => $this->getFieldOrEmptyString('accountNumber'),
|
||||
'accountRole' => $this->getFieldOrEmptyString('accountRole'),
|
||||
'openingBalance' => round($this->input('openingBalance'), 12),
|
||||
'openingBalanceDate' => new Carbon((string)$this->input('openingBalanceDate')),
|
||||
'openingBalanceCurrency' => intval($this->input('amount_currency_id_openingBalance')),
|
||||
'ccType' => $this->input('ccType'),
|
||||
'ccMonthlyPaymentDate' => $this->input('ccMonthlyPaymentDate'),
|
||||
'ccType' => $this->getFieldOrEmptyString('ccType'),
|
||||
'ccMonthlyPaymentDate' => $this->getFieldOrEmptyString('ccMonthlyPaymentDate'),
|
||||
];
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ class AccountFormRequest extends Request
|
||||
$idRule = '';
|
||||
if (!is_null($repository->find(intval($this->get('id')))->id)) {
|
||||
$idRule = 'belongsToUser:accounts';
|
||||
$nameRule = 'required|min:1|uniqueAccountForUser:' . $this->get('id');
|
||||
$nameRule = 'required|min:1|uniqueAccountForUser:' . intval($this->get('id'));
|
||||
}
|
||||
|
||||
return [
|
||||
|
@ -36,9 +36,9 @@ class AttachmentFormRequest extends Request
|
||||
public function getAttachmentData(): array
|
||||
{
|
||||
return [
|
||||
'title' => trim($this->input('title')),
|
||||
'description' => trim($this->input('description')),
|
||||
'notes' => trim($this->input('notes')),
|
||||
'title' => $this->getFieldOrEmptyString('title'),
|
||||
'description' => $this->getFieldOrEmptyString('description'),
|
||||
'notes' => $this->getFieldOrEmptyString('notes'),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -38,14 +38,14 @@ class BillFormRequest extends Request
|
||||
public function getBillData()
|
||||
{
|
||||
return [
|
||||
'name' => $this->get('name'),
|
||||
'match' => $this->get('match'),
|
||||
'name' => $this->getFieldOrEmptyString('name'),
|
||||
'match' => $this->getFieldOrEmptyString('match'),
|
||||
'amount_min' => round($this->get('amount_min'), 12),
|
||||
'amount_currency_id_amount_min' => intval($this->get('amount_currency_id_amount_min')),
|
||||
'amount_currency_id_amount_max' => intval($this->get('amount_currency_id_amount_max')),
|
||||
'amount_max' => round($this->get('amount_max'), 12),
|
||||
'date' => new Carbon($this->get('date')),
|
||||
'repeat_freq' => $this->get('repeat_freq'),
|
||||
'repeat_freq' => $this->getFieldOrEmptyString('repeat_freq'),
|
||||
'skip' => intval($this->get('skip')),
|
||||
'automatch' => intval($this->get('automatch')) === 1,
|
||||
'active' => intval($this->get('active')) === 1,
|
||||
|
@ -37,7 +37,7 @@ class BudgetFormRequest extends Request
|
||||
public function getBudgetData(): array
|
||||
{
|
||||
return [
|
||||
'name' => trim($this->input('name')),
|
||||
'name' => $this->getFieldOrEmptyString('name'),
|
||||
'active' => intval($this->input('active')) == 1,
|
||||
];
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class CategoryFormRequest extends Request
|
||||
public function getCategoryData(): array
|
||||
{
|
||||
return [
|
||||
'name' => trim($this->input('name')),
|
||||
'name' => $this->getFieldOrEmptyString('name'),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -36,9 +36,9 @@ class CurrencyFormRequest extends Request
|
||||
public function getCurrencyData()
|
||||
{
|
||||
return [
|
||||
'name' => $this->get('name'),
|
||||
'code' => $this->get('code'),
|
||||
'symbol' => $this->get('symbol'),
|
||||
'name' => $this->getFieldOrEmptyString('name'),
|
||||
'code' => $this->getFieldOrEmptyString('code'),
|
||||
'symbol' => $this->getFieldOrEmptyString('symbol'),
|
||||
'decimal_places' => intval($this->get('decimal_places')),
|
||||
];
|
||||
}
|
||||
|
@ -54,8 +54,8 @@ class JournalFormRequest extends Request
|
||||
'due_date' => $this->getDateOrNull('due_date'),
|
||||
'payment_date' => $this->getDateOrNull('payment_date'),
|
||||
'invoice_date' => $this->getDateOrNull('invoice_date'),
|
||||
'internal_reference' => trim(strval($this->get('internal_reference'))),
|
||||
'notes' => trim(strval($this->get('notes'))),
|
||||
'internal_reference' => $this->getFieldOrEmptyString('internal_reference'),
|
||||
'notes' => $this->getFieldOrEmptyString('notes'),
|
||||
|
||||
// transaction / journal data:
|
||||
'description' => $this->getFieldOrEmptyString('description'),
|
||||
@ -152,40 +152,4 @@ class JournalFormRequest extends Request
|
||||
{
|
||||
return $this->get($field) ? new Carbon($this->get($field)) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getFieldOrEmptyString(string $field): string
|
||||
{
|
||||
$string = $this->get($field) ?? '';
|
||||
|
||||
$search = [
|
||||
"\xa0", // 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{205F}", //MEDIUM MATHEMATICAL SPACE
|
||||
"\u{3000}", //IDEOGRAPHIC SPACE
|
||||
"\u{FEFF}", // ZERO WIDTH NO -BREAK SPACE
|
||||
];
|
||||
$replace = "\x20"; // plain old normal space
|
||||
$string = str_replace($search, $replace, $string);
|
||||
|
||||
return trim($string);
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class PiggyBankFormRequest extends Request
|
||||
public function getPiggyBankData(): array
|
||||
{
|
||||
return [
|
||||
'name' => trim($this->get('name')),
|
||||
'name' => $this->getFieldOrEmptyString('name'),
|
||||
'startdate' => new Carbon,
|
||||
'account_id' => intval($this->get('account_id')),
|
||||
'targetamount' => round($this->get('targetamount'), 12),
|
||||
|
@ -20,7 +20,41 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
*
|
||||
* @package FireflyIII\Http\Requests
|
||||
*/
|
||||
abstract class Request extends FormRequest
|
||||
class Request extends FormRequest
|
||||
{
|
||||
//
|
||||
/**
|
||||
* @param string $field
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getFieldOrEmptyString(string $field): string
|
||||
{
|
||||
$string = $this->get($field) ?? '';
|
||||
|
||||
$search = [
|
||||
"\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{205F}", // MEDIUM MATHEMATICAL SPACE
|
||||
"\u{3000}", // IDEOGRAPHIC SPACE
|
||||
"\u{FEFF}", // ZERO WIDTH NO -BREAK SPACE
|
||||
];
|
||||
$replace = "\x20"; // plain old normal space
|
||||
$string = str_replace($search, $replace, $string);
|
||||
|
||||
return trim($string);
|
||||
}
|
||||
}
|
||||
|
@ -38,10 +38,10 @@ class RuleFormRequest extends Request
|
||||
public function getRuleData(): array
|
||||
{
|
||||
return [
|
||||
'title' => trim($this->get('title')),
|
||||
'title' => $this->getFieldOrEmptyString('title'),
|
||||
'active' => intval($this->get('active')) == 1,
|
||||
'trigger' => trim($this->get('trigger')),
|
||||
'description' => trim($this->get('description')),
|
||||
'trigger' => $this->getFieldOrEmptyString('trigger'),
|
||||
'description' => $this->getFieldOrEmptyString('description'),
|
||||
'rule-triggers' => $this->get('rule-trigger'),
|
||||
'rule-trigger-values' => $this->get('rule-trigger-value'),
|
||||
'rule-trigger-stop' => $this->get('rule-trigger-stop'),
|
||||
|
@ -38,8 +38,8 @@ class RuleGroupFormRequest extends Request
|
||||
public function getRuleGroupData(): array
|
||||
{
|
||||
return [
|
||||
'title' => trim($this->input('title')),
|
||||
'description' => trim($this->input('description')),
|
||||
'title' => $this->getFieldOrEmptyString('title'),
|
||||
'description' => $this->getFieldOrEmptyString('description'),
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user