@@ -12,12 +12,12 @@ 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_GT_CODE = 'float.gt ' ;
16- public const string ERROR_GT_TEMPLATE = 'Value should be greater than {{gt}}, {{given}} given ' ;
17-
1815 public const string ERROR_GTE_CODE = 'float.gte ' ;
1916 public const string ERROR_GTE_TEMPLATE = 'Value should be greater than or equal {{gte}}, {{given}} given ' ;
2017
18+ public const string ERROR_GT_CODE = 'float.gt ' ;
19+ public const string ERROR_GT_TEMPLATE = 'Value should be greater than {{gt}}, {{given}} given ' ;
20+
2121 public const string ERROR_LT_CODE = 'float.lt ' ;
2222 public const string ERROR_LT_TEMPLATE = 'Value should be lesser than {{lt}}, {{given}} given ' ;
2323
@@ -27,71 +27,71 @@ final class FloatSchema extends AbstractSchemaInnerParse implements SchemaInterf
2727 public const string ERROR_INT_CODE = 'float.int ' ;
2828 public const string ERROR_INT_TEMPLATE = 'Cannot convert {{given}} to int ' ;
2929
30- public function gt (float $ gt ): static
30+ public function gte (float $ gte ): static
3131 {
32- return $ this ->postParse (static function (float $ float ) use ($ gt ) {
33- if ($ float <= $ gt ) {
34- throw new ErrorsException (
35- new Error (
36- self ::ERROR_GT_CODE ,
37- self ::ERROR_GT_TEMPLATE ,
38- ['gt ' => $ gt , 'given ' => $ float ]
39- )
40- );
32+ return $ this ->postParse (static function (float $ float ) use ($ gte ) {
33+ if ($ float >= $ gte ) {
34+ return $ float ;
4135 }
4236
43- return $ float ;
37+ throw new ErrorsException (
38+ new Error (
39+ self ::ERROR_GTE_CODE ,
40+ self ::ERROR_GTE_TEMPLATE ,
41+ ['gte ' => $ gte , 'given ' => $ float ]
42+ )
43+ );
4444 });
4545 }
4646
47- public function gte (float $ gte ): static
47+ public function gt (float $ gt ): static
4848 {
49- return $ this ->postParse (static function (float $ float ) use ($ gte ) {
50- if ($ float < $ gte ) {
51- throw new ErrorsException (
52- new Error (
53- self ::ERROR_GTE_CODE ,
54- self ::ERROR_GTE_TEMPLATE ,
55- ['gte ' => $ gte , 'given ' => $ float ]
56- )
57- );
49+ return $ this ->postParse (static function (float $ float ) use ($ gt ) {
50+ if ($ float > $ gt ) {
51+ return $ float ;
5852 }
5953
60- return $ float ;
54+ throw new ErrorsException (
55+ new Error (
56+ self ::ERROR_GT_CODE ,
57+ self ::ERROR_GT_TEMPLATE ,
58+ ['gt ' => $ gt , 'given ' => $ float ]
59+ )
60+ );
6161 });
6262 }
6363
6464 public function lt (float $ lt ): static
6565 {
6666 return $ this ->postParse (static function (float $ float ) use ($ lt ) {
67- if ($ float >= $ lt ) {
68- throw new ErrorsException (
69- new Error (
70- self ::ERROR_LT_CODE ,
71- self ::ERROR_LT_TEMPLATE ,
72- ['lt ' => $ lt , 'given ' => $ float ]
73- )
74- );
67+ if ($ float < $ lt ) {
68+ return $ float ;
7569 }
7670
77- return $ float ;
71+ throw new ErrorsException (
72+ new Error (
73+ self ::ERROR_LT_CODE ,
74+ self ::ERROR_LT_TEMPLATE ,
75+ ['lt ' => $ lt , 'given ' => $ float ]
76+ )
77+ );
7878 });
7979 }
8080
8181 public function lte (float $ lte ): static
8282 {
8383 return $ this ->postParse (static function (float $ float ) use ($ lte ) {
84- if ($ float > $ lte ) {
85- throw new ErrorsException (
86- new Error (
87- self ::ERROR_LTE_CODE ,
88- self ::ERROR_LTE_TEMPLATE ,
89- ['lte ' => $ lte , 'given ' => $ float ]
90- )
91- );
84+ if ($ float <= $ lte ) {
85+ return $ float ;
9286 }
9387
94- return $ float ;
88+ throw new ErrorsException (
89+ new Error (
90+ self ::ERROR_LTE_CODE ,
91+ self ::ERROR_LTE_TEMPLATE ,
92+ ['lte ' => $ lte , 'given ' => $ float ]
93+ )
94+ );
9595 });
9696 }
9797
@@ -127,17 +127,17 @@ public function toInt(): IntSchema
127127
128128 $ intInput = (int ) $ input ;
129129
130- if ((float ) $ intInput !== $ input ) {
131- throw new ErrorsException (
132- new Error (
133- self ::ERROR_INT_CODE ,
134- self ::ERROR_INT_TEMPLATE ,
135- ['given ' => $ input ]
136- )
137- );
130+ if ((float ) $ intInput === $ input ) {
131+ return $ intInput ;
138132 }
139133
140- return $ intInput ;
134+ throw new ErrorsException (
135+ new Error (
136+ self ::ERROR_INT_CODE ,
137+ self ::ERROR_INT_TEMPLATE ,
138+ ['given ' => $ input ]
139+ )
140+ );
141141 })->nullable ($ this ->nullable );
142142 }
143143
@@ -153,16 +153,16 @@ public function toString(): StringSchema
153153
154154 protected function innerParse (mixed $ input ): mixed
155155 {
156- if (!\is_float ($ input )) {
157- throw new ErrorsException (
158- new Error (
159- self ::ERROR_TYPE_CODE ,
160- self ::ERROR_TYPE_TEMPLATE ,
161- ['given ' => $ this ->getDataType ($ input )]
162- )
163- );
156+ if (\is_float ($ input )) {
157+ return $ input ;
164158 }
165159
166- return $ input ;
160+ throw new ErrorsException (
161+ new Error (
162+ self ::ERROR_TYPE_CODE ,
163+ self ::ERROR_TYPE_TEMPLATE ,
164+ ['given ' => $ this ->getDataType ($ input )]
165+ )
166+ );
167167 }
168168}
0 commit comments