Update requests to use uniform methods.

This commit is contained in:
James Cole
2017-01-20 19:49:35 +01:00
parent 6b57d4397a
commit 8635fe7ebb
12 changed files with 64 additions and 67 deletions

View File

@@ -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);
}
}