File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ private function __construct($name, $value)
49
49
*/
50
50
public function getValue ()
51
51
{
52
+ $ this ->validate ();
52
53
return $ this ->value ;
53
54
}
54
55
@@ -59,6 +60,7 @@ public function getValue()
59
60
*/
60
61
public function getKey ()
61
62
{
63
+ $ this ->validate ();
62
64
return $ this ->name ;
63
65
}
64
66
@@ -67,6 +69,7 @@ public function getKey()
67
69
*/
68
70
public function __toString ()
69
71
{
72
+ $ this ->validate ();
70
73
return (string )$ this ->value ;
71
74
}
72
75
@@ -79,9 +82,22 @@ public function __toString()
79
82
*/
80
83
final public function equals (Enum $ enum )
81
84
{
85
+ $ this ->validate ();
82
86
return $ this ->getValue () === $ enum ->getValue ();
83
87
}
84
88
89
+ /**
90
+ * Check if Enum is initialized
91
+ *
92
+ * @throws BadMethodCallException
93
+ */
94
+ private function validate ()
95
+ {
96
+ if ($ this ->name === null ) {
97
+ throw new BadMethodCallException ("Enum is not initialized " );
98
+ }
99
+ }
100
+
85
101
/**
86
102
* Returns the names (keys) of all constants in the Enum class
87
103
*
You can’t perform that action at this time.
0 commit comments