File tree Expand file tree Collapse file tree 9 files changed +23
-23
lines changed
Expand file tree Collapse file tree 9 files changed +23
-23
lines changed Original file line number Diff line number Diff line change @@ -13,17 +13,16 @@ public function __construct($value)
1313 {
1414 if (!($ value instanceof self) &&
1515 $ value !== null &&
16- !$ this -> isValid ($ value )
16+ !static :: isValid ($ value )
1717 ) {
18- $ type = gettype ($ value );
1918 throw new TypeException (
2019 '" ' . ((string ) $ value ) . '" is not expected in ' . get_class ($ this ) . '. '
2120 );
2221 }
2322
2423 $ this ->value = ($ value instanceof self)
2524 ? $ value ->getValue ()
26- : $ this -> filter ($ value );
25+ : static :: filter ($ value );
2726 }
2827
2928 public function __debugInfo ()
@@ -65,12 +64,12 @@ public function __toString()
6564 return (string ) $ this ->getValue ();
6665 }
6766
68- protected function isValid ($ value )
67+ public static function isValid ($ value )
6968 {
70- return false ;
69+ throw new TypeException ( ' Not implemented type validation. ' ) ;
7170 }
7271
73- protected function filter ($ value )
72+ protected static function filter ($ value )
7473 {
7574 return $ value ;
7675 }
Original file line number Diff line number Diff line change @@ -10,15 +10,15 @@ class _Boolean extends Type
1010 const TRUE = 'true ' ;
1111 const FALSE = 'false ' ;
1212
13- public function isValid ($ value )
13+ public static function isValid ($ value )
1414 {
1515 return $ value == 0 ||
1616 $ value == 1 ||
1717 $ value === true ||
1818 $ value === false ;
1919 }
2020
21- protected function filter ($ value )
21+ protected static function filter ($ value )
2222 {
2323 return $ value ? true : false ;
2424 }
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ class _Byte extends Type
1010 const MIN = -128 ;
1111 const MAX = 127 ;
1212
13- public function isValid ($ value )
13+ public static function isValid ($ value )
1414 {
1515 if (!ctype_digit ((string ) abs ($ value ))) {
1616 return false ;
@@ -19,7 +19,7 @@ public function isValid($value)
1919 return $ value >= static ::MIN && $ value <= static ::MAX ;
2020 }
2121
22- protected function filter ($ value )
22+ protected static function filter ($ value )
2323 {
2424 return (int ) $ value ;
2525 }
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ class _Char extends Type
1010 const MIN = 0 ;
1111 const MAX = 65535 ;
1212
13- public function isValid ($ value )
13+ public static function isValid ($ value )
1414 {
1515 if (ctype_alpha ($ value ) && strlen ($ value ) === 1 ) {
1616 $ value = ord ($ value );
@@ -23,7 +23,7 @@ public function isValid($value)
2323 return $ value >= static ::MIN && $ value <= static ::MAX ;
2424 }
2525
26- protected function filter ($ value )
26+ protected static function filter ($ value )
2727 {
2828 if (ctype_alpha ($ value ) && strlen ($ value ) === 1 ) {
2929 return $ value ;
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ class _Double extends Type
1212 const MIN = '4.9E-324 ' ;
1313 const MAX = '1.7976931348623157E308 ' ;
1414
15- public function isValid ($ value )
15+ public static function isValid ($ value )
1616 {
1717 if (!is_numeric ((string ) abs ($ value ))) {
1818 return false ;
@@ -26,7 +26,7 @@ public function isValid($value)
2626 );
2727 }
2828
29- protected function filter ($ value )
29+ protected static function filter ($ value )
3030 {
3131 return (string ) $ value ;
3232 }
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ class _Float extends Type
1010 const MIN = 1.4E-45 ;
1111 const MAX = 3.4028235E38 ;
1212
13- public function isValid ($ value )
13+ public static function isValid ($ value )
1414 {
1515 $ value = (string ) abs ($ value );
1616 if (!is_numeric ($ value )) {
@@ -20,7 +20,7 @@ public function isValid($value)
2020 return $ value == 0 || ($ value >= static ::MIN && $ value <= static ::MAX );
2121 }
2222
23- protected function filter ($ value )
23+ protected static function filter ($ value )
2424 {
2525 return (float ) $ value ;
2626 }
Original file line number Diff line number Diff line change @@ -10,11 +10,12 @@ class _Int extends Type
1010 const MIN = -2147483648 ;
1111 const MAX = 2147483647 ;
1212
13- public function isValid ($ value )
13+ public static function isValid ($ value )
1414 {
1515 if (ctype_alpha ($ value ) && strlen ($ value ) === 1 ) {
1616 $ value = ord ($ value );
1717 }
18+
1819 $ value = ($ value << 32 ) >> 32 ;
1920 if (!ctype_digit ((string ) abs ($ value ))) {
2021 return false ;
@@ -23,7 +24,7 @@ public function isValid($value)
2324 return $ value >= static ::MIN && $ value <= static ::MAX ;
2425 }
2526
26- protected function filter ($ value )
27+ protected static function filter ($ value )
2728 {
2829 if (ctype_alpha ($ value ) && strlen ($ value ) === 1 ) {
2930 return ord ($ value );
Original file line number Diff line number Diff line change @@ -10,16 +10,16 @@ class _Long extends Type
1010 const MIN = -9223372036854775808 ;
1111 const MAX = 9223372036854775807 ;
1212
13- public function isValid ($ value )
13+ public static function isValid ($ value )
1414 {
1515 if (!ctype_digit ((string ) abs ($ value ))) {
1616 return false ;
1717 }
1818 return $ value >= static ::MIN && $ value <= static ::MAX ;
1919 }
2020
21- protected function filter ($ value )
21+ protected static function filter ($ value )
2222 {
23- return (string ) (( int ) $ value) ;
23+ return (int ) $ value ;
2424 }
2525}
Original file line number Diff line number Diff line change @@ -10,14 +10,14 @@ class _Short extends Type
1010 const MIN = -32768 ;
1111 const MAX = 32767 ;
1212
13- public function isValid ($ value )
13+ public static function isValid ($ value )
1414 {
1515 return ctype_digit ((string ) abs ($ value )) &&
1616 $ value >= static ::MIN &&
1717 $ value <= static ::MAX ;
1818 }
1919
20- protected function filter ($ value )
20+ protected static function filter ($ value )
2121 {
2222 return (int ) $ value ;
2323 }
You can’t perform that action at this time.
0 commit comments