Skip to content

Commit 3a4215e

Browse files
committed
fix: Introduce asFloat in BaseConstraint
1 parent 3ad01f4 commit 3a4215e

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/opnsense/mvc/app/models/OPNsense/Base/Constraints/BaseConstraint.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,19 @@ public function isEmpty($node)
5454
* @param $node
5555
* @return bool
5656
*/
57-
public function isNumeric($node)
58-
{
57+
public function isNumeric($node): bool {
5958
return is_numeric((string)$node->getCurrentValue());
6059
}
6160

61+
/**
62+
* Try to convert to current value as float
63+
* @param $node
64+
* @return float
65+
*/
66+
public function asFloat($node): float {
67+
return floatval((string)$node->getCurrentValue());
68+
}
69+
6270
/**
6371
* @param $validator
6472
* @param $attribute

src/opnsense/mvc/app/models/OPNsense/Base/Constraints/ComparedToFieldConstraint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public function validate($validator, $attribute): bool
6969
if (
7070
!$this->is_constraint_fulfilled(
7171
$operator,
72-
floatval((string)$node->getCurrentValue()),
73-
floatval((string)$other_node_content->getCurrentValue())
72+
$this->asFloat($node),
73+
$this->asFloat($other_node_content)
7474
)
7575
) {
7676
$this->appendMessage($validator, $attribute);

0 commit comments

Comments
 (0)