@@ -26,47 +26,47 @@ discard block |
||
26 | 26 | private static $___constants = [ ]; |
27 | 27 | protected $scalar; |
28 | 28 | |
29 | - public function __construct( $scalar ) { |
|
29 | + public function __construct($scalar) { |
|
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; |
37 | 37 | |
38 | 38 | } |
39 | 39 | |
40 | - final public static function __callStatic( string $name, array $args ) { |
|
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; |
50 | - return new $class( self::$___constants[ static::class ][ 0 ][ $name ] ); |
|
50 | + return new $class(self::$___constants[ static::class ][ 0 ][ $name ]); |
|
51 | 51 | |
52 | 52 | } |
53 | 53 | |
54 | 54 | private static function _init( ) { |
55 | 55 | |
56 | - if( !isset( self::$___constants[ static::class ] ) ) { |
|
56 | + if (!isset(self::$___constants[ static::class ])) { |
|
57 | 57 | |
58 | - $csts = ( new ReflectionClass( static::class ) )->getConstants( ); |
|
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 ) ) |
|
64 | - throw new EnumConstantTypeException( static::class, $key, gettype( $value ) ); |
|
63 | + if (!static::_validate_constants($value)) |
|
64 | + throw new EnumConstantTypeException(static::class, $key, gettype($value)); |
|
65 | 65 | |
66 | - if( isset( $vals[ $value ] ) ) |
|
67 | - throw new DuplicatedConstantException( static::class, $key ); |
|
66 | + if (isset($vals[ $value ])) |
|
67 | + throw new DuplicatedConstantException(static::class, $key); |
|
68 | 68 | |
69 | - $vals[$value] = true; |
|
69 | + $vals[ $value ] = true; |
|
70 | 70 | |
71 | 71 | } |
72 | 72 | |
@@ -78,10 +78,10 @@ discard block |
||
78 | 78 | |
79 | 79 | public function value( ) { return $this->scalar; } |
80 | 80 | |
81 | - protected static function _validate_constants( $value ) : bool { |
|
81 | + protected static function _validate_constants($value) : bool { |
|
82 | 82 | |
83 | - if( is_int( $value ) ) return true; |
|
84 | - if( is_string( $value ) && $value !== '' ) return true; |
|
83 | + if (is_int($value)) return true; |
|
84 | + if (is_string($value) && $value !== '') return true; |
|
85 | 85 | return false; |
86 | 86 | |
87 | 87 | } |
@@ -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 ] ); |
@@ -60,11 +64,13 @@ discard block |
||
60 | 64 | |
61 | 65 | foreach( $csts as $key => $value ) { |
62 | 66 | |
63 | - if( !static::_validate_constants( $value ) ) |
|
64 | - throw new EnumConstantTypeException( static::class, $key, gettype( $value ) ); |
|
67 | + if( !static::_validate_constants( $value ) ) { |
|
68 | + throw new EnumConstantTypeException( static::class, $key, gettype( $value ) ); |
|
69 | + } |
|
65 | 70 | |
66 | - if( isset( $vals[ $value ] ) ) |
|
67 | - throw new DuplicatedConstantException( static::class, $key ); |
|
71 | + if( isset( $vals[ $value ] ) ) { |
|
72 | + throw new DuplicatedConstantException( static::class, $key ); |
|
73 | + } |
|
68 | 74 | |
69 | 75 | $vals[$value] = true; |
70 | 76 | |
@@ -80,8 +86,12 @@ discard block |
||
80 | 86 | |
81 | 87 | protected static function _validate_constants( $value ) : bool { |
82 | 88 | |
83 | - if( is_int( $value ) ) return true; |
|
84 | - if( is_string( $value ) && $value !== '' ) return true; |
|
89 | + if( is_int( $value ) ) { |
|
90 | + return true; |
|
91 | + } |
|
92 | + if( is_string( $value ) && $value !== '' ) { |
|
93 | + return true; |
|
94 | + } |
|
85 | 95 | return false; |
86 | 96 | |
87 | 97 | } |
@@ -16,8 +16,8 @@ |
||
16 | 16 | */ |
17 | 17 | class DuplicatedConstantException extends LogicException { |
18 | 18 | |
19 | - public function __construct( string $className, string $constName ) { |
|
20 | - parent::__construct( "Constant duplication found: \"{$className}::{$constName}\"." ); |
|
19 | + public function __construct(string $className, string $constName) { |
|
20 | + parent::__construct("Constant duplication found: \"{$className}::{$constName}\"."); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | } |