Skip to content

Commit a7a3d57

Browse files
committed
replaced 'get_called_class()' by 'static::class'
1 parent 326a3d3 commit a7a3d57

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/Enum.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ final public function getValue()
110110
*/
111111
final public function getName()
112112
{
113-
return array_search($this->value, self::detectConstants(get_called_class()), true);
113+
return array_search($this->value, self::detectConstants(static::class), true);
114114
}
115115

116116
/**
@@ -127,7 +127,7 @@ final public function getOrdinal()
127127
// detect ordinal
128128
$ordinal = 0;
129129
$value = $this->value;
130-
foreach (self::detectConstants(get_called_class()) as $constValue) {
130+
foreach (self::detectConstants(static::class) as $constValue) {
131131
if ($value === $constValue) {
132132
break;
133133
}
@@ -150,7 +150,7 @@ final public function is($enumerator)
150150

151151
// The following additional conditions are required only because of the issue of serializable singletons
152152
|| ($enumerator instanceof static
153-
&& get_class($enumerator) === get_called_class()
153+
&& get_class($enumerator) === static::class
154154
&& $enumerator->value === $this->value
155155
);
156156
}
@@ -165,7 +165,7 @@ final public function is($enumerator)
165165
*/
166166
final public static function get($value)
167167
{
168-
if ($value instanceof static && get_class($value) === get_called_class()) {
168+
if ($value instanceof static && get_class($value) === static::class) {
169169
return $value;
170170
}
171171

@@ -182,7 +182,7 @@ final public static function get($value)
182182
*/
183183
final public static function byValue($value)
184184
{
185-
$class = get_called_class();
185+
$class = static::class;
186186
$constants = self::detectConstants($class);
187187
$name = array_search($value, $constants, true);
188188
if ($name === false) {
@@ -210,7 +210,7 @@ final public static function byValue($value)
210210
final public static function byName($name)
211211
{
212212
$name = (string) $name;
213-
$class = get_called_class();
213+
$class = static::class;
214214
if (isset(self::$instances[$class][$name])) {
215215
return self::$instances[$class][$name];
216216
}
@@ -234,7 +234,7 @@ final public static function byName($name)
234234
final public static function byOrdinal($ordinal)
235235
{
236236
$ordinal = (int) $ordinal;
237-
$class = get_called_class();
237+
$class = static::class;
238238
$constants = self::detectConstants($class);
239239
$item = array_slice($constants, $ordinal, 1, true);
240240
if (empty($item)) {
@@ -259,7 +259,7 @@ final public static function byOrdinal($ordinal)
259259
*/
260260
final public static function getEnumerators()
261261
{
262-
return array_map('self::byName', array_keys(self::detectConstants(get_called_class())));
262+
return array_map([static::class, 'byName'], array_keys(self::detectConstants(static::class)));
263263
}
264264

265265
/**
@@ -269,7 +269,7 @@ final public static function getEnumerators()
269269
*/
270270
final public static function getValues()
271271
{
272-
return array_values(self::detectConstants(get_called_class()));
272+
return array_values(self::detectConstants(static::class));
273273
}
274274

275275
/**
@@ -279,7 +279,7 @@ final public static function getValues()
279279
*/
280280
final public static function getNames()
281281
{
282-
return array_keys(self::detectConstants(get_called_class()));
282+
return array_keys(self::detectConstants(static::class));
283283
}
284284
/*
285285
* Get a list of enumerator ordinal numbers
@@ -288,7 +288,7 @@ final public static function getNames()
288288
*/
289289
final public static function getOrdinals()
290290
{
291-
$count = count(self::detectConstants(get_called_class()));
291+
$count = count(self::detectConstants(static::class));
292292
return $count === 0 ? array() : range(0, $count - 1);
293293
}
294294

@@ -300,7 +300,7 @@ final public static function getOrdinals()
300300
*/
301301
final public static function getConstants()
302302
{
303-
return self::detectConstants(get_called_class());
303+
return self::detectConstants(static::class);
304304
}
305305

306306
/**
@@ -311,13 +311,11 @@ final public static function getConstants()
311311
*/
312312
final public static function has($value)
313313
{
314-
if ($value instanceof static && get_class($value) === get_called_class()) {
314+
if ($value instanceof static && get_class($value) === static::class) {
315315
return true;
316316
}
317317

318-
$class = get_called_class();
319-
$constants = self::detectConstants($class);
320-
318+
$constants = self::detectConstants(static::class);
321319
return in_array($value, $constants, true);
322320
}
323321

0 commit comments

Comments
 (0)