Skip to content

Commit 090e766

Browse files
committed
Better lengths for decimal fields
1 parent 138b0d6 commit 090e766

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/PHPFUI/ORM/Tool/Generate/Base.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ protected function getTypeLength(string &$type) : float
5353
if (false !== $start)
5454
{
5555
$precision = \rtrim(\substr($type, $start + 1), ')');
56+
if (str_contains($precision, ','))
57+
{
58+
$parts = \explode(',', $precision);
59+
$precision = ((int)$parts[0]) + 1;
60+
}
5661
$type = \substr($type, 0, $start);
5762
}
5863
$type = \strtolower($type);

src/PHPFUI/ORM/Validator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,12 @@ private function validate_lte_field(mixed $value) : string
599599

600600
private function validate_maxlength(mixed $value) : string
601601
{
602-
$length = $this->currentParameters[0] ?? $this->currentFieldDefinitions->length;
602+
if ($this->currentFieldDefinitions->length <= 0)
603+
{
604+
return true; // zero length fields can't have a max length test
605+
}
606+
607+
$length = $this->currentParameters[0] ? ? $this->currentFieldDefinitions->length;
603608

604609
return $this->testIt(\strlen((string)$value) <= $length, 'maxlength', ['value' => $value, 'length' => $length]);
605610
}

0 commit comments

Comments
 (0)