Skip to content
This repository was archived by the owner on Dec 26, 2023. It is now read-only.

Commit 127eb12

Browse files
author
Petr Knap
committed
Constants renamed to members
1 parent 82973ee commit 127eb12

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

src/Enum/AbstractEnum.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @author Petr Knap <dev@petrknap.cz>
99
* @since 2016-01-23
1010
* @package PetrKnap\Php\Enum
11-
* @version 0.2
11+
* @version 0.3
1212
* @license https://github.com/petrknap/php-enum/blob/master/LICENSE MIT
1313
*/
1414
abstract class AbstractEnum
@@ -21,36 +21,36 @@ abstract class AbstractEnum
2121
/**
2222
* @var mixed[][]
2323
*/
24-
private static $constants = [];
24+
private static $members = [];
2525

2626
/**
27-
* @var mixed
27+
* @var string
2828
*/
29-
private $constantName;
29+
private $memberName;
3030

3131
/**
3232
* @var mixed
3333
*/
34-
private $constantValue;
34+
private $memberValue;
3535

3636
/**
37-
* @param mixed $constantName
37+
* @param string $memberName
3838
* @throws EnumException
3939
*/
40-
protected function __construct($constantName)
40+
protected function __construct($memberName)
4141
{
42-
$this->constantName = $constantName;
43-
$this->constantValue = $this->get($constantName);
42+
$this->memberName = $memberName;
43+
$this->memberValue = $this->get($memberName);
4444
}
4545

4646
/**
4747
* Creates magical factories for easier access to enum
4848
*
49-
* @param mixed $constantName enum key
49+
* @param string $memberName enum key
5050
* @param array $args ignored
5151
* @return mixed
5252
*/
53-
public static function __callStatic($constantName, array $args)
53+
public static function __callStatic($memberName, array $args)
5454
{
5555
$className = get_called_class();
5656

@@ -60,10 +60,10 @@ public static function __callStatic($constantName, array $args)
6060
$instances = [];
6161
}
6262

63-
$instance = &$instances[$constantName];
63+
$instance = &$instances[$memberName];
6464

6565
if (!($instance instanceof $className)) {
66-
$instance = new $className($constantName);
66+
$instance = new $className($memberName);
6767
}
6868

6969
return $instance;
@@ -74,60 +74,60 @@ public static function __callStatic($constantName, array $args)
7474
*/
7575
public function getName()
7676
{
77-
return $this->constantName;
77+
return $this->memberName;
7878
}
7979

8080
/**
8181
* @return mixed
8282
*/
8383
public function getValue()
8484
{
85-
return $this->constantValue;
85+
return $this->memberValue;
8686
}
8787

8888
/**
89-
* @param mixed[] $constants
89+
* @param mixed[] $members
9090
*/
91-
protected static function setConstants(array $constants)
91+
protected static function setMembers(array $members)
9292
{
93-
self::$constants[get_called_class()] = $constants;
93+
self::$members[get_called_class()] = $members;
9494
}
9595

9696
/**
9797
* @return mixed[]
9898
*/
99-
public static function getConstants()
99+
public static function getMembers()
100100
{
101-
return self::$constants[get_called_class()];
101+
return self::$members[get_called_class()];
102102
}
103103

104104
/**
105-
* @param string $constantName
105+
* @param string $memberName
106106
* @return bool
107107
*/
108-
private function exists($constantName)
108+
private function exists($memberName)
109109
{
110-
return array_key_exists($constantName, self::$constants[get_called_class()]);
110+
return array_key_exists($memberName, self::$members[get_called_class()]);
111111
}
112112

113113
/**
114-
* @param string $constantName
114+
* @param string $memberName
115115
* @return mixed
116116
* @throws EnumException
117117
*/
118-
private function get($constantName)
118+
private function get($memberName)
119119
{
120-
if (!$this->exists($constantName)) {
120+
if (!$this->exists($memberName)) {
121121
throw new EnumException(
122122
sprintf(
123123
"%s does not exist in %s",
124-
$constantName,
124+
$memberName,
125125
get_called_class()
126126
),
127127
EnumException::OUT_OF_RANGE
128128
);
129129
}
130130

131-
return self::$constants[get_called_class()][$constantName];
131+
return self::$members[get_called_class()][$memberName];
132132
}
133133
}

tests/Enum/EnumTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testComparable()
6363
*/
6464
public function testGetConstants($name, $value)
6565
{
66-
$constants = EnumMock::getConstants();
66+
$constants = EnumMock::getMembers();
6767

6868
$this->assertInternalType("array", $constants);
6969
$this->assertArrayHasKey($name, $constants);

tests/Enum/EnumTest/EnumMock.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
*/
1111
class EnumMock extends AbstractEnum
1212
{
13-
protected function __construct($key)
13+
protected function __construct($memberName)
1414
{
15-
self::setConstants([
15+
self::setMembers([
1616
"A" => "a",
1717
"B" => "b"
1818
]);
1919

20-
parent::__construct($key);
20+
parent::__construct($memberName);
2121
}
2222

2323
/**

0 commit comments

Comments
 (0)