@@ -13,16 +13,10 @@ final class IntSchema extends AbstractSchemaInnerParse implements SchemaInterfac
1313 public const string ERROR_TYPE_TEMPLATE = 'Type should be "int", {{given}} given ' ;
1414
1515 public const string ERROR_MINIMUM_CODE = 'int.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 = 'int.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 = 'int.exclusiveMaximum ' ;
22- public const string ERROR_EXCLUSIVE_MAXIMUM_TEMPLATE = 'Value should be lesser than {{exclusiveMaximum}}, {{given}} given ' ;
16+ public const string ERROR_MINIMUM_TEMPLATE = 'Value should be minimum {{minimum}} {{exclusiveMinimum}}, {{given}} given ' ;
2317
2418 public const string ERROR_MAXIMUM_CODE = 'int.maximum ' ;
25- public const string ERROR_MAXIMUM_TEMPLATE = 'Value should be lesser than or equal {{maximum}}, {{given}} given ' ;
19+ public const string ERROR_MAXIMUM_TEMPLATE = 'Value should be maximum {{maximum}} {{exclusiveMaximum }}, {{given}} given ' ;
2620
2721 public const string ERROR_GTE_CODE = 'int.gte ' ;
2822 public const string ERROR_GTE_TEMPLATE = 'Value should be greater than or equal {{gte}}, {{given}} given ' ;
@@ -36,80 +30,46 @@ final class IntSchema extends AbstractSchemaInnerParse implements SchemaInterfac
3630 public const string ERROR_LTE_CODE = 'int.lte ' ;
3731 public const string ERROR_LTE_TEMPLATE = 'Value should be lesser than or equal {{lte}}, {{given}} given ' ;
3832
39- public function minimum (int $ minimum ): static
33+ public function minimum (int $ minimum, bool $ exclusiveMinimum = false ): static
4034 {
41- return $ this ->postParse (static function (int $ int ) use ($ minimum ) {
42- if ($ int >= $ minimum ) {
35+ return $ this ->postParse (static function (int $ int ) use ($ minimum, $ exclusiveMinimum ) {
36+ if ((! $ exclusiveMinimum && $ int >= $ minimum) || ( $ exclusiveMinimum && $ int > $ minimum ) ) {
4337 return $ int ;
4438 }
4539
4640 throw new ErrorsException (
4741 new Error (
4842 self ::ERROR_MINIMUM_CODE ,
4943 self ::ERROR_MINIMUM_TEMPLATE ,
50- ['minimum ' => $ minimum , 'given ' => $ int ]
51- )
52- );
53- });
54- }
55-
56- public function exclusiveMinimum (int $ exclusiveMinimum ): static
57- {
58- return $ this ->postParse (static function (int $ int ) use ($ exclusiveMinimum ) {
59- if ($ int > $ exclusiveMinimum ) {
60- return $ int ;
61- }
62-
63- throw new ErrorsException (
64- new Error (
65- self ::ERROR_EXCLUSIVE_MINIMUM_CODE ,
66- self ::ERROR_EXCLUSIVE_MINIMUM_TEMPLATE ,
67- ['exclusiveMinimum ' => $ exclusiveMinimum , 'given ' => $ int ]
68- )
69- );
70- });
71- }
72-
73- public function exclusiveMaximum (int $ exclusiveMaximum ): static
74- {
75- return $ this ->postParse (static function (int $ int ) use ($ exclusiveMaximum ) {
76- if ($ int < $ exclusiveMaximum ) {
77- return $ int ;
78- }
79-
80- throw new ErrorsException (
81- new Error (
82- self ::ERROR_EXCLUSIVE_MAXIMUM_CODE ,
83- self ::ERROR_EXCLUSIVE_MAXIMUM_TEMPLATE ,
84- ['exclusiveMaximum ' => $ exclusiveMaximum , 'given ' => $ int ]
44+ ['minimum ' => $ minimum , 'exclusiveMinimum ' => $ exclusiveMinimum , 'given ' => $ int ]
8545 )
8646 );
8747 });
8848 }
8949
90- public function maximum (int $ maximum ): static
50+ public function maximum (int $ maximum, bool $ exclusiveMaximum = false ): static
9151 {
92- return $ this ->postParse (static function (int $ int ) use ($ maximum ) {
93- if ($ int <= $ maximum ) {
52+ return $ this ->postParse (static function (int $ int ) use ($ maximum, $ exclusiveMaximum ) {
53+ if ((! $ exclusiveMaximum && $ int <= $ maximum) || ( $ exclusiveMaximum && $ int < $ maximum ) ) {
9454 return $ int ;
9555 }
9656
9757 throw new ErrorsException (
9858 new Error (
9959 self ::ERROR_MAXIMUM_CODE ,
10060 self ::ERROR_MAXIMUM_TEMPLATE ,
101- ['maximum ' => $ maximum , 'given ' => $ int ]
61+ ['maximum ' => $ maximum , 'exclusiveMaximum ' => $ exclusiveMaximum , ' given ' => $ int ]
10262 )
10363 );
10464 });
10565 }
10666
10767 /**
108- * @deprecated use minimum
68+ * @deprecated Use minimum($gte) instead
10969 */
11070 public function gte (int $ gte ): static
11171 {
112- @trigger_error ('Use minimum instead ' , E_USER_DEPRECATED );
72+ @trigger_error ('Use minimum($gte) instead ' , E_USER_DEPRECATED );
11373
11474 return $ this ->postParse (static function (int $ int ) use ($ gte ) {
11575 if ($ int >= $ gte ) {
@@ -127,11 +87,11 @@ public function gte(int $gte): static
12787 }
12888
12989 /**
130- * @deprecated use exclusiveMinimum
90+ * @deprecated Use minimum($gt, true) instead
13191 */
13292 public function gt (int $ gt ): static
13393 {
134- @trigger_error ('Use exclusiveMinimum instead ' , E_USER_DEPRECATED );
94+ @trigger_error ('Use minimum($gt, true) instead ' , E_USER_DEPRECATED );
13595
13696 return $ this ->postParse (static function (int $ int ) use ($ gt ) {
13797 if ($ int > $ gt ) {
@@ -149,11 +109,11 @@ public function gt(int $gt): static
149109 }
150110
151111 /**
152- * @deprecated use exclusiveMaximum
112+ * @deprecated Use maximum($lt, true) instead
153113 */
154114 public function lt (int $ lt ): static
155115 {
156- @trigger_error ('Use exclusiveMaximum instead ' , E_USER_DEPRECATED );
116+ @trigger_error ('Use maximum($lt, true) instead ' , E_USER_DEPRECATED );
157117
158118 return $ this ->postParse (static function (int $ int ) use ($ lt ) {
159119 if ($ int < $ lt ) {
@@ -171,11 +131,11 @@ public function lt(int $lt): static
171131 }
172132
173133 /**
174- * @deprecated use maximum
134+ * @deprecated Use maximum($lte) instead
175135 */
176136 public function lte (int $ lte ): static
177137 {
178- @trigger_error ('Use maximum instead ' , E_USER_DEPRECATED );
138+ @trigger_error ('Use maximum($lte) instead ' , E_USER_DEPRECATED );
179139
180140 return $ this ->postParse (static function (int $ int ) use ($ lte ) {
181141 if ($ int <= $ lte ) {
0 commit comments