mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Compare commits
2 Commits
a380d7f758
...
4d5a5a15a2
Author | SHA1 | Date | |
---|---|---|---|
|
4d5a5a15a2 | ||
|
a8c3aa39b0 |
@ -43,11 +43,6 @@ class StringFieldValidator extends FieldValidator
|
||||
$result->addFieldError($this->name, $message, value: $this->value);
|
||||
return $result;
|
||||
}
|
||||
// TODO this seems non-sensical - should enforce minLength??
|
||||
// Blank strings are valid, even if there's a minLength requirement
|
||||
if ($this->value === '') {
|
||||
return $result;
|
||||
}
|
||||
$len = mb_strlen($this->value);
|
||||
if (!is_null($this->minLength) && $len < $this->minLength) {
|
||||
$message = _t(
|
||||
|
@ -30,7 +30,7 @@ class DBDecimal extends DBField
|
||||
/**
|
||||
* Create a new Decimal field.
|
||||
*/
|
||||
public function __construct(?string $name = null, ?int $wholeSize = 9, ?int $decimalSize = 2, float|int $defaultValue = 0)
|
||||
public function __construct(?string $name = null, ?int $wholeSize = 9, ?int $decimalSize = 2, float|int $defaultValue = 0.0)
|
||||
{
|
||||
$this->wholeSize = is_int($wholeSize) ? $wholeSize : 9;
|
||||
$this->decimalSize = is_int($decimalSize) ? $decimalSize : 2;
|
||||
@ -113,23 +113,23 @@ class DBDecimal extends DBField
|
||||
|
||||
public function nullValue(): int
|
||||
{
|
||||
return 0;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
public function prepValueForDB(mixed $value): array|float|int|null
|
||||
{
|
||||
if ($value === true) {
|
||||
return 1;
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
if (empty($value) || !is_numeric($value)) {
|
||||
return 0;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
if (abs((float) $value - (int) $value) < PHP_FLOAT_EPSILON) {
|
||||
return (int)$value;
|
||||
return (int) $value;
|
||||
}
|
||||
|
||||
return (float)$value;
|
||||
return (float) $value;
|
||||
}
|
||||
}
|
||||
|
@ -26,13 +26,6 @@ class StringFieldValidatorTest extends SapphireTest
|
||||
'exception' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'valid-blank-when-min' => [
|
||||
'value' => '',
|
||||
'minLength' => 5,
|
||||
'maxLength' => null,
|
||||
'exception' => false,
|
||||
'expected' => true,
|
||||
],
|
||||
'valid-max' => [
|
||||
'value' => 'fish',
|
||||
'minLength' => 0,
|
||||
@ -75,6 +68,13 @@ class StringFieldValidatorTest extends SapphireTest
|
||||
'exception' => false,
|
||||
'expected' => false,
|
||||
],
|
||||
'invalid-blank-with-min' => [
|
||||
'value' => '',
|
||||
'minLength' => 5,
|
||||
'maxLength' => null,
|
||||
'exception' => false,
|
||||
'expected' => false,
|
||||
],
|
||||
'invalid-above-min' => [
|
||||
'value' => 'fish',
|
||||
'minLength' => 0,
|
||||
|
Loading…
Reference in New Issue
Block a user