77
88class Type extends AbstractRule implements RuleInterface
99{
10+ public const BOOL = 'bool ' ;
11+ public const BOOLEAN = 'boolean ' ;
12+ public const INT = 'int ' ;
13+ public const INTEGER = 'integer ' ;
14+ public const LONG = 'long ' ;
15+ public const FLOAT = 'float ' ;
16+ public const DOUBLE = 'double ' ;
17+ public const REAL = 'real ' ;
18+ public const NUMERIC = 'numeric ' ;
19+ public const STRING = 'string ' ;
20+ public const SCALAR = 'scalar ' ;
21+ public const ARRAY = 'array ' ;
22+ public const ITERABLE = 'iterable ' ;
23+ public const COUNTABLE = 'countable ' ;
24+ public const CALLABLE = 'callable ' ;
25+ public const OBJECT = 'object ' ;
26+ public const RESOURCE = 'resource ' ;
27+ public const NULL = 'null ' ;
28+ public const ALPHANUMERIC = 'alphanumeric ' ;
29+ public const ALPHA = 'alpha ' ;
30+ public const DIGIT = 'digit ' ;
31+ public const CONTROL = 'control ' ;
32+ public const PUNCTUATION = 'punctuation ' ;
33+ public const HEXADECIMAL = 'hexadecimal ' ;
34+ public const GRAPH = 'graph ' ;
35+ public const PRINTABLE = 'printable ' ;
36+ public const WHITESPACE = 'whitespace ' ;
37+ public const LOWERCASE = 'lowercase ' ;
38+ public const UPPERCASE = 'uppercase ' ;
39+
1040 private const TYPE_FUNCTIONS = [
11- ' bool ' => 'is_bool ' ,
12- ' boolean ' => 'is_bool ' ,
13- ' int ' => 'is_int ' ,
14- ' integer ' => 'is_int ' ,
15- ' long ' => 'is_int ' ,
16- ' float ' => 'is_float ' ,
17- ' double ' => 'is_float ' ,
18- ' real ' => 'is_float ' ,
19- ' numeric ' => 'is_numeric ' ,
20- ' string ' => 'is_string ' ,
21- ' scalar ' => 'is_scalar ' ,
22- ' array ' => 'is_array ' ,
23- ' iterable ' => 'is_iterable ' ,
24- ' countable ' => 'is_countable ' ,
25- ' callable ' => 'is_callable ' ,
26- ' object ' => 'is_object ' ,
27- ' resource ' => 'is_resource ' ,
28- ' null ' => 'is_null ' ,
29- ' alphanumeric ' => 'ctype_alnum ' ,
30- ' alpha ' => 'ctype_alpha ' ,
31- ' digit ' => 'ctype_digit ' ,
32- ' control ' => 'ctype_cntrl ' ,
33- ' punctuation ' => 'ctype_punct ' ,
34- ' hexadecimal ' => 'ctype_xdigit ' ,
35- ' graph ' => 'ctype_graph ' ,
36- ' printable ' => 'ctype_print ' ,
37- ' whitespace ' => 'ctype_space ' ,
38- ' lowercase ' => 'ctype_lower ' ,
39- ' uppercase ' => 'ctype_upper '
41+ self :: BOOL => 'is_bool ' ,
42+ self :: BOOLEAN => 'is_bool ' ,
43+ self :: INT => 'is_int ' ,
44+ self :: INTEGER => 'is_int ' ,
45+ self :: LONG => 'is_int ' ,
46+ self :: FLOAT => 'is_float ' ,
47+ self :: DOUBLE => 'is_float ' ,
48+ self :: REAL => 'is_float ' ,
49+ self :: NUMERIC => 'is_numeric ' ,
50+ self :: STRING => 'is_string ' ,
51+ self :: SCALAR => 'is_scalar ' ,
52+ self :: ARRAY => 'is_array ' ,
53+ self :: ITERABLE => 'is_iterable ' ,
54+ self :: COUNTABLE => 'is_countable ' ,
55+ self :: CALLABLE => 'is_callable ' ,
56+ self :: OBJECT => 'is_object ' ,
57+ self :: RESOURCE => 'is_resource ' ,
58+ self :: NULL => 'is_null ' ,
59+ self :: ALPHANUMERIC => 'ctype_alnum ' ,
60+ self :: ALPHA => 'ctype_alpha ' ,
61+ self :: DIGIT => 'ctype_digit ' ,
62+ self :: CONTROL => 'ctype_cntrl ' ,
63+ self :: PUNCTUATION => 'ctype_punct ' ,
64+ self :: HEXADECIMAL => 'ctype_xdigit ' ,
65+ self :: GRAPH => 'ctype_graph ' ,
66+ self :: PRINTABLE => 'ctype_print ' ,
67+ self :: WHITESPACE => 'ctype_space ' ,
68+ self :: LOWERCASE => 'ctype_lower ' ,
69+ self :: UPPERCASE => 'ctype_upper '
4070 ];
4171
4272 public function __construct (
@@ -57,12 +87,12 @@ public function assert(mixed $value, string $name): void
5787 return ;
5888 }
5989
60- if (!isset (self ::TYPE_FUNCTIONS [$ constraint ]) && !class_exists ($ constraint ) && !interface_exists ($ constraint )) {
90+ if (!isset (self ::TYPE_FUNCTIONS [$ constraint ]) && !\ class_exists ($ constraint ) && !\ interface_exists ($ constraint )) {
6191 throw new UnexpectedValueException (
6292 \sprintf (
6393 'Invalid constraint type "%s". Accepted values are: "%s" ' ,
6494 $ constraint ,
65- implode (', ' , array_keys (self ::TYPE_FUNCTIONS ))
95+ \ implode ('", " ' , \ array_keys (self ::TYPE_FUNCTIONS ))
6696 )
6797 );
6898 }
0 commit comments