@@ -12,6 +12,18 @@ final class FloatSchema extends AbstractSchemaInnerParse implements SchemaInterf
1212 public const string ERROR_TYPE_CODE = 'float.type ' ;
1313 public const string ERROR_TYPE_TEMPLATE = 'Type should be "float", {{given}} given ' ;
1414
15+ public const string ERROR_MINIMUM_CODE = 'float.minimum ' ;
16+ public const string ERROR_MINIMUM_TEMPLATE = 'Value should be greater than or equal {{minimum}}, {{given}} given ' ;
17+
18+ public const string ERROR_EXCLUSIVE_MINIMUM_CODE = 'float.exclusiveMinimum ' ;
19+ public const string ERROR_EXCLUSIVE_MINIMUM_TEMPLATE = 'Value should be greater than {{exclusiveMinimum}}, {{given}} given ' ;
20+
21+ public const string ERROR_EXCLUSIVE_MAXIMUM_CODE = 'float.exclusiveMaximum ' ;
22+ public const string ERROR_EXCLUSIVE_MAXIMUM_TEMPLATE = 'Value should be lesser than {{exclusiveMaximum}}, {{given}} given ' ;
23+
24+ public const string ERROR_MAXIMUM_CODE = 'float.maximum ' ;
25+ public const string ERROR_MAXIMUM_TEMPLATE = 'Value should be lesser than or equal {{maximum}}, {{given}} given ' ;
26+
1527 public const string ERROR_GTE_CODE = 'float.gte ' ;
1628 public const string ERROR_GTE_TEMPLATE = 'Value should be greater than or equal {{gte}}, {{given}} given ' ;
1729
@@ -27,8 +39,78 @@ final class FloatSchema extends AbstractSchemaInnerParse implements SchemaInterf
2739 public const string ERROR_INT_CODE = 'float.int ' ;
2840 public const string ERROR_INT_TEMPLATE = 'Cannot convert {{given}} to int ' ;
2941
42+ public function minimum (float $ minimum ): static
43+ {
44+ return $ this ->postParse (static function (float $ float ) use ($ minimum ) {
45+ if ($ float >= $ minimum ) {
46+ return $ float ;
47+ }
48+
49+ throw new ErrorsException (
50+ new Error (
51+ self ::ERROR_MINIMUM_CODE ,
52+ self ::ERROR_MINIMUM_TEMPLATE ,
53+ ['minimum ' => $ minimum , 'given ' => $ float ]
54+ )
55+ );
56+ });
57+ }
58+
59+ public function exclusiveMinimum (float $ exclusiveMinimum ): static
60+ {
61+ return $ this ->postParse (static function (float $ float ) use ($ exclusiveMinimum ) {
62+ if ($ float > $ exclusiveMinimum ) {
63+ return $ float ;
64+ }
65+
66+ throw new ErrorsException (
67+ new Error (
68+ self ::ERROR_EXCLUSIVE_MINIMUM_CODE ,
69+ self ::ERROR_EXCLUSIVE_MINIMUM_TEMPLATE ,
70+ ['exclusiveMinimum ' => $ exclusiveMinimum , 'given ' => $ float ]
71+ )
72+ );
73+ });
74+ }
75+
76+ public function exclusiveMaximum (float $ exclusiveMaximum ): static
77+ {
78+ return $ this ->postParse (static function (float $ float ) use ($ exclusiveMaximum ) {
79+ if ($ float < $ exclusiveMaximum ) {
80+ return $ float ;
81+ }
82+
83+ throw new ErrorsException (
84+ new Error (
85+ self ::ERROR_EXCLUSIVE_MAXIMUM_CODE ,
86+ self ::ERROR_EXCLUSIVE_MAXIMUM_TEMPLATE ,
87+ ['exclusiveMaximum ' => $ exclusiveMaximum , 'given ' => $ float ]
88+ )
89+ );
90+ });
91+ }
92+
93+ public function maximum (float $ maximum ): static
94+ {
95+ return $ this ->postParse (static function (float $ float ) use ($ maximum ) {
96+ if ($ float <= $ maximum ) {
97+ return $ float ;
98+ }
99+
100+ throw new ErrorsException (
101+ new Error (
102+ self ::ERROR_MAXIMUM_CODE ,
103+ self ::ERROR_MAXIMUM_TEMPLATE ,
104+ ['maximum ' => $ maximum , 'given ' => $ float ]
105+ )
106+ );
107+ });
108+ }
109+
30110 public function gte (float $ gte ): static
31111 {
112+ @trigger_error ('Use minimum instead ' , E_USER_DEPRECATED );
113+
32114 return $ this ->postParse (static function (float $ float ) use ($ gte ) {
33115 if ($ float >= $ gte ) {
34116 return $ float ;
@@ -46,6 +128,8 @@ public function gte(float $gte): static
46128
47129 public function gt (float $ gt ): static
48130 {
131+ @trigger_error ('Use exclusiveMinimum instead ' , E_USER_DEPRECATED );
132+
49133 return $ this ->postParse (static function (float $ float ) use ($ gt ) {
50134 if ($ float > $ gt ) {
51135 return $ float ;
@@ -63,6 +147,8 @@ public function gt(float $gt): static
63147
64148 public function lt (float $ lt ): static
65149 {
150+ @trigger_error ('Use exclusiveMaximum instead ' , E_USER_DEPRECATED );
151+
66152 return $ this ->postParse (static function (float $ float ) use ($ lt ) {
67153 if ($ float < $ lt ) {
68154 return $ float ;
@@ -80,6 +166,8 @@ public function lt(float $lt): static
80166
81167 public function lte (float $ lte ): static
82168 {
169+ @trigger_error ('Use maximum instead ' , E_USER_DEPRECATED );
170+
83171 return $ this ->postParse (static function (float $ float ) use ($ lte ) {
84172 if ($ float <= $ lte ) {
85173 return $ float ;
0 commit comments