Skip to content

Commit b335232

Browse files
committed
Removing values() method and restoring toArray() method to a non-deprecated state
1 parent 12f65ec commit b335232

File tree

2 files changed

+8
-27
lines changed

2 files changed

+8
-27
lines changed

src/Enum.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ abstract class Enum
3939
*/
4040
public function __construct($value)
4141
{
42-
if (!in_array($value, self::values())) {
42+
if (!in_array($value, self::toArray())) {
4343
throw new \UnexpectedValueException("Value '$value' is not part of the enum " . get_called_class());
4444
}
4545

@@ -79,15 +79,15 @@ public function __toString()
7979
*/
8080
public static function keys()
8181
{
82-
return array_keys(static::values());
82+
return array_keys(static::toArray());
8383
}
8484

8585
/**
8686
* Returns all possible values as an array
8787
*
8888
* @return array Constant name in key, constant value in value
8989
*/
90-
public static function values()
90+
public static function toArray()
9191
{
9292
$class = get_called_class();
9393
if (!array_key_exists($class, self::$cache)) {
@@ -98,17 +98,6 @@ public static function values()
9898
return self::$cache[$class];
9999
}
100100

101-
/**
102-
* An alias method for values()
103-
*
104-
* @return array
105-
* @deprecated
106-
*/
107-
public static function toArray()
108-
{
109-
return self::values();
110-
}
111-
112101
/**
113102
* Check if is valid enum value
114103
*
@@ -120,7 +109,7 @@ public static function toArray()
120109
*/
121110
public static function isValid($value)
122111
{
123-
return in_array($value, self::values());
112+
return in_array($value, self::toArray());
124113
}
125114

126115
/**
@@ -148,7 +137,7 @@ public static function isValidKey($key)
148137
*/
149138
public static function search($value)
150139
{
151-
return array_search($value, array_combine(self::keys(), self::values()));
140+
return array_search($value, array_combine(self::keys(), self::toArray()));
152141
}
153142

154143
/**

tests/EnumTest.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ public function testKeys()
9494
}
9595

9696
/**
97-
* values()
97+
* toArray()
9898
*/
99-
public function testValues()
99+
public function testToArray()
100100
{
101-
$values = EnumFixture::values();
101+
$values = EnumFixture::toArray();
102102
$this->assertInternalType("array", $values);
103103
$expectedValues = array(
104104
"FOO" => EnumFixture::FOO,
@@ -108,14 +108,6 @@ public function testValues()
108108
$this->assertEquals($expectedValues, $values);
109109
}
110110

111-
/**
112-
* toArray()
113-
*/
114-
public function testToArray()
115-
{
116-
$this->assertEquals(EnumFixture::values(), EnumFixture::toArray());
117-
}
118-
119111
/**
120112
* __callStatic()
121113
*/

0 commit comments

Comments
 (0)