Passed
Push — master ( e9fe83...f34f5c )
by 4kizuki
06:12
created
src/Enum.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -25,44 +25,44 @@  discard block
 block discarded – undo
25 25
     private static $___constants = [ ];
26 26
     protected $scalar;
27 27
 
28
-    public function __construct( $scalar ) {
28
+    public function __construct($scalar) {
29 29
 
30 30
         self::_init( );
31 31
 
32
-        if( !self::_validate_constants( $scalar ) or !isset( self::$___constants[ static::class ][ 1 ][ $scalar ] ) )
32
+        if (!self::_validate_constants($scalar) or !isset(self::$___constants[ static::class ][ 1 ][ $scalar ]))
33 33
             throw new InvalidInitializerException;
34 34
 
35 35
         $this->scalar = $scalar;
36 36
 
37 37
     }
38 38
 
39
-    final public static function __callStatic( string $name, array $args ) {
39
+    final public static function __callStatic(string $name, array $args) {
40 40
 
41
-        if( !empty( $args ) ) throw new BadMethodCallException;
41
+        if (!empty($args)) throw new BadMethodCallException;
42 42
 
43 43
         self::_init( );
44 44
 
45
-        if( !isset( self::$___constants[ static::class ][ 0 ][ $name ] ) )
45
+        if (!isset(self::$___constants[ static::class ][ 0 ][ $name ]))
46 46
             throw new InvalidInitializerException;
47 47
 
48 48
         $class = static::class;
49
-        return new $class( self::$___constants[ static::class ][ 0 ][ $name ] );
49
+        return new $class(self::$___constants[ static::class ][ 0 ][ $name ]);
50 50
 
51 51
     }
52 52
 
53 53
     private static function _init( ) {
54 54
 
55
-        if( !isset( self::$___constants[ static::class ] ) ) {
55
+        if (!isset(self::$___constants[ static::class ])) {
56 56
 
57
-            $csts = ( new ReflectionClass( static::class ) )->getConstants( );
57
+            $csts = (new ReflectionClass(static::class))->getConstants( );
58 58
             $vals = [ ];
59 59
 
60
-            foreach( $csts as $key => $value ) {
60
+            foreach ($csts as $key => $value) {
61 61
 
62
-                if( !static::_validate_constants( $value ) )
63
-                    throw new EnumConstantTypeException( static::class, $key, gettype( $value ) );
62
+                if (!static::_validate_constants($value))
63
+                    throw new EnumConstantTypeException(static::class, $key, gettype($value));
64 64
 
65
-                $vals[$value] = true;
65
+                $vals[ $value ] = true;
66 66
 
67 67
             }
68 68
 
@@ -74,10 +74,10 @@  discard block
 block discarded – undo
74 74
 
75 75
     public function value( ) { return $this->scalar; }
76 76
 
77
-    protected static function _validate_constants( $value ) : bool {
77
+    protected static function _validate_constants($value) : bool {
78 78
 
79
-        if( is_int( $value ) ) return true;
80
-        if( is_string( $value ) && $value !== '' ) return true;
79
+        if (is_int($value)) return true;
80
+        if (is_string($value) && $value !== '') return true;
81 81
         return false;
82 82
 
83 83
     }
Please login to merge, or discard this patch.
Braces   +18 added lines, -9 removed lines patch added patch discarded remove patch
@@ -29,8 +29,9 @@  discard block
 block discarded – undo
29 29
 
30 30
         self::_init( );
31 31
 
32
-        if( !self::_validate_constants( $scalar ) or !isset( self::$___constants[ static::class ][ 1 ][ $scalar ] ) )
33
-            throw new InvalidInitializerException;
32
+        if( !self::_validate_constants( $scalar ) or !isset( self::$___constants[ static::class ][ 1 ][ $scalar ] ) ) {
33
+                    throw new InvalidInitializerException;
34
+        }
34 35
 
35 36
         $this->scalar = $scalar;
36 37
 
@@ -38,12 +39,15 @@  discard block
 block discarded – undo
38 39
 
39 40
     final public static function __callStatic( string $name, array $args ) {
40 41
 
41
-        if( !empty( $args ) ) throw new BadMethodCallException;
42
+        if( !empty( $args ) ) {
43
+            throw new BadMethodCallException;
44
+        }
42 45
 
43 46
         self::_init( );
44 47
 
45
-        if( !isset( self::$___constants[ static::class ][ 0 ][ $name ] ) )
46
-            throw new InvalidInitializerException;
48
+        if( !isset( self::$___constants[ static::class ][ 0 ][ $name ] ) ) {
49
+                    throw new InvalidInitializerException;
50
+        }
47 51
 
48 52
         $class = static::class;
49 53
         return new $class( self::$___constants[ static::class ][ 0 ][ $name ] );
@@ -59,8 +63,9 @@  discard block
 block discarded – undo
59 63
 
60 64
             foreach( $csts as $key => $value ) {
61 65
 
62
-                if( !static::_validate_constants( $value ) )
63
-                    throw new EnumConstantTypeException( static::class, $key, gettype( $value ) );
66
+                if( !static::_validate_constants( $value ) ) {
67
+                                    throw new EnumConstantTypeException( static::class, $key, gettype( $value ) );
68
+                }
64 69
 
65 70
                 $vals[$value] = true;
66 71
 
@@ -76,8 +81,12 @@  discard block
 block discarded – undo
76 81
 
77 82
     protected static function _validate_constants( $value ) : bool {
78 83
 
79
-        if( is_int( $value ) ) return true;
80
-        if( is_string( $value ) && $value !== '' ) return true;
84
+        if( is_int( $value ) ) {
85
+            return true;
86
+        }
87
+        if( is_string( $value ) && $value !== '' ) {
88
+            return true;
89
+        }
81 90
         return false;
82 91
 
83 92
     }
Please login to merge, or discard this patch.
src/Exceptions/InvalidInitializerException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 block discarded – undo
17 17
 class InvalidInitializerException extends DomainException {
18 18
     
19 19
     public function __construct( ) {
20
-        parent::__construct( "Invalid enum initializer given. Given initializer isn't found in enum constants." );
20
+        parent::__construct("Invalid enum initializer given. Given initializer isn't found in enum constants.");
21 21
     }
22 22
     
23 23
 }
Please login to merge, or discard this patch.