@@ -30,8 +30,9 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | self::_init( ); |
| 32 | 32 | |
| 33 | - if( !self::_validate_constants( $scalar ) or !isset( self::$___constants[ static::class ][ 1 ][ $scalar ] ) ) |
|
| 34 | - throw new InvalidInitializerException; |
|
| 33 | + if( !self::_validate_constants( $scalar ) or !isset( self::$___constants[ static::class ][ 1 ][ $scalar ] ) ) { |
|
| 34 | + throw new InvalidInitializerException; |
|
| 35 | + } |
|
| 35 | 36 | |
| 36 | 37 | $this->scalar = $scalar; |
| 37 | 38 | |
@@ -39,12 +40,15 @@ discard block |
||
| 39 | 40 | |
| 40 | 41 | final public static function __callStatic( string $name, array $args ) { |
| 41 | 42 | |
| 42 | - if( !empty( $args ) ) throw new BadMethodCallException; |
|
| 43 | + if( !empty( $args ) ) { |
|
| 44 | + throw new BadMethodCallException; |
|
| 45 | + } |
|
| 43 | 46 | |
| 44 | 47 | self::_init( ); |
| 45 | 48 | |
| 46 | - if( !isset( self::$___constants[ static::class ][ 0 ][ $name ] ) ) |
|
| 47 | - throw new InvalidInitializerException; |
|
| 49 | + if( !isset( self::$___constants[ static::class ][ 0 ][ $name ] ) ) { |
|
| 50 | + throw new InvalidInitializerException; |
|
| 51 | + } |
|
| 48 | 52 | |
| 49 | 53 | $class = static::class; |
| 50 | 54 | return new $class( self::$___constants[ static::class ][ 0 ][ $name ] ); |
@@ -53,18 +57,22 @@ discard block |
||
| 53 | 57 | |
| 54 | 58 | private static function _init( ) { |
| 55 | 59 | |
| 56 | - if( isset( self::$___constants[ static::class ] ) ) return; |
|
| 60 | + if( isset( self::$___constants[ static::class ] ) ) { |
|
| 61 | + return; |
|
| 62 | + } |
|
| 57 | 63 | |
| 58 | 64 | $csts = ( new ReflectionClass( static::class ) )->getConstants(); |
| 59 | 65 | $vals = [ ]; |
| 60 | 66 | |
| 61 | 67 | foreach( $csts as $key => $value ) { |
| 62 | 68 | |
| 63 | - if( !static::_validate_constants( $value ) ) |
|
| 64 | - throw new EnumConstantTypeException( static::class, $key, gettype( $value ) ); |
|
| 69 | + if( !static::_validate_constants( $value ) ) { |
|
| 70 | + throw new EnumConstantTypeException( static::class, $key, gettype( $value ) ); |
|
| 71 | + } |
|
| 65 | 72 | |
| 66 | - if( isset( $vals[ $value ] ) ) |
|
| 67 | - throw new DuplicatedConstantException( static::class, $key ); |
|
| 73 | + if( isset( $vals[ $value ] ) ) { |
|
| 74 | + throw new DuplicatedConstantException( static::class, $key ); |
|
| 75 | + } |
|
| 68 | 76 | |
| 69 | 77 | $vals[ $value ] = true; |
| 70 | 78 | |
@@ -77,8 +85,12 @@ discard block |
||
| 77 | 85 | |
| 78 | 86 | protected static function _validate_constants( $value ) : bool { |
| 79 | 87 | |
| 80 | - if( is_int( $value ) ) return true; |
|
| 81 | - if( is_string( $value ) && $value !== '' ) return true; |
|
| 88 | + if( is_int( $value ) ) { |
|
| 89 | + return true; |
|
| 90 | + } |
|
| 91 | + if( is_string( $value ) && $value !== '' ) { |
|
| 92 | + return true; |
|
| 93 | + } |
|
| 82 | 94 | return false; |
| 83 | 95 | |
| 84 | 96 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | self::_init( ); |
| 32 | 32 | |
| 33 | - if( !self::_validate_constants( $scalar ) or !isset( self::$___constants[ static::class ][ 1 ][ $scalar ] ) ) |
|
| 33 | + if ( !self::_validate_constants( $scalar ) or !isset( self::$___constants[ static::class ][ 1 ][ $scalar ] ) ) |
|
| 34 | 34 | throw new InvalidInitializerException; |
| 35 | 35 | |
| 36 | 36 | $this->scalar = $scalar; |
@@ -39,11 +39,11 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | final public static function __callStatic( string $name, array $args ) { |
| 41 | 41 | |
| 42 | - if( !empty( $args ) ) throw new BadMethodCallException; |
|
| 42 | + if ( !empty( $args ) ) throw new BadMethodCallException; |
|
| 43 | 43 | |
| 44 | 44 | self::_init( ); |
| 45 | 45 | |
| 46 | - if( !isset( self::$___constants[ static::class ][ 0 ][ $name ] ) ) |
|
| 46 | + if ( !isset( self::$___constants[ static::class ][ 0 ][ $name ] ) ) |
|
| 47 | 47 | throw new InvalidInitializerException; |
| 48 | 48 | |
| 49 | 49 | $class = static::class; |
@@ -53,17 +53,17 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | private static function _init( ) { |
| 55 | 55 | |
| 56 | - if( isset( self::$___constants[ static::class ] ) ) return; |
|
| 56 | + if ( isset( self::$___constants[ static::class ] ) ) return; |
|
| 57 | 57 | |
| 58 | 58 | $csts = ( new ReflectionClass( static::class ) )->getConstants(); |
| 59 | 59 | $vals = [ ]; |
| 60 | 60 | |
| 61 | - foreach( $csts as $key => $value ) { |
|
| 61 | + foreach ( $csts as $key => $value ) { |
|
| 62 | 62 | |
| 63 | - if( !static::_validate_constants( $value ) ) |
|
| 63 | + if ( !static::_validate_constants( $value ) ) |
|
| 64 | 64 | throw new EnumConstantTypeException( static::class, $key, gettype( $value ) ); |
| 65 | 65 | |
| 66 | - if( isset( $vals[ $value ] ) ) |
|
| 66 | + if ( isset( $vals[ $value ] ) ) |
|
| 67 | 67 | throw new DuplicatedConstantException( static::class, $key ); |
| 68 | 68 | |
| 69 | 69 | $vals[ $value ] = true; |
@@ -77,8 +77,8 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | protected static function _validate_constants( $value ) : bool { |
| 79 | 79 | |
| 80 | - if( is_int( $value ) ) return true; |
|
| 81 | - if( is_string( $value ) && $value !== '' ) return true; |
|
| 80 | + if ( is_int( $value ) ) return true; |
|
| 81 | + if ( is_string( $value ) && $value !== '' ) return true; |
|
| 82 | 82 | return false; |
| 83 | 83 | |
| 84 | 84 | } |