Skip to content

Commit 8cdc1c8

Browse files
committed
enumeration vs. enumerator
1 parent 8ffd585 commit 8cdc1c8

File tree

4 files changed

+55
-55
lines changed

4 files changed

+55
-55
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ It's an abstract class that needs to be extended to use it.
4545
const FLOAT = 0.123;
4646
}
4747

48-
// different ways to instantiate an enumeration
48+
// different ways to instantiate an enumerator
4949
$status = UserStatus::get(UserStatus::ACTIVE);
5050
$status = UserStatus::ACTIVE();
5151
$status = UserStatus::getByName('ACTIVE');
@@ -57,11 +57,11 @@ It's an abstract class that needs to be extended to use it.
5757
$status->getOrdinal(); // returns the ordinal number of the selected constant
5858
(string) $status; // returns the selected constant name
5959

60-
// same enumerations of the same class holds the same instance
60+
// same enumerators (of the same enumeration class) holds the same instance
6161
UserStatus::get(UserStatus::ACTIVE) === UserStatus::ACTIVE()
6262
UserStatus::get(UserStatus::DELETED) != UserStatus::INACTIVE()
6363

64-
// simplified way to compare two enumerations
64+
// simplified way to compare two enumerators
6565
UserStatus::ACTIVE()->is(UserStatus::ACTIVE); // true
6666
UserStatus::ACTIVE()->is(UserStatus::ACTIVE()); // true
6767
UserStatus::ACTIVE()->is(UserStatus::DELETED); // false
@@ -84,7 +84,7 @@ It's an abstract class that needs to be extended to use it.
8484
public function getStatus()
8585
{
8686
if (!$this->status) {
87-
// initialize a default value
87+
// initialize the default enumerator
8888
$this->status = UserStatus::get(UserStatus::INACTIVE);
8989
}
9090
return $this->status;
@@ -124,7 +124,7 @@ corresponding instance of `UserStatus` else an exception will be thrown.)
124124

125125
## EnumMap
126126

127-
An ```EnumMap``` maps enumeration instances of exactly one type to data assigned to.
127+
An ```EnumMap``` maps enumerators of the same type to data assigned to.
128128
Internally the ```EnumMap``` is based of ```SplObjectStorage```.
129129

130130
use MabeEnum\EnumMap;
@@ -151,7 +151,7 @@ Internally the ```EnumMap``` is based of ```SplObjectStorage```.
151151

152152
## EnumSet
153153

154-
An ```EnumSet``` groups enumeration instances of exactly one type together.
154+
An ```EnumSet``` groups enumerators of the same type together.
155155
Internally it's based of a list (array) of ordinal values.
156156

157157
use MabeEnum\EnumSet;

src/MabeEnum/Enum.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
abstract class Enum
1717
{
1818
/**
19-
* The selected value
19+
* The selected enumerator value
2020
*
2121
* @var null|bool|int|float|string
2222
*/
2323
private $value;
2424

2525
/**
26-
* The ordinal number of the value
26+
* The ordinal number of the enumerator
2727
*
2828
* @var null|int
2929
*/
@@ -37,7 +37,7 @@ abstract class Enum
3737
private static $constants = array();
3838

3939
/**
40-
* Already instantiated enums
40+
* Already instantiated enumerators
4141
*
4242
* @var array ["$class" => ["$const" => $instance, ...], ...]
4343
*/
@@ -46,8 +46,8 @@ abstract class Enum
4646
/**
4747
* Constructor
4848
*
49-
* @param null|bool|int|float|string $value The value to select
50-
* @param int|null $ordinal The ordinal number of the value
49+
* @param null|bool|int|float|string $value The value of the enumerator
50+
* @param int|null $ordinal The ordinal number of the enumerator
5151
*/
5252
final private function __construct($value, $ordinal = null)
5353
{
@@ -56,7 +56,7 @@ final private function __construct($value, $ordinal = null)
5656
}
5757

5858
/**
59-
* Get the current selected constant name
59+
* Get the name of the enumerator
6060
*
6161
* @return string
6262
* @see getName()
@@ -94,7 +94,7 @@ final public function __wakeup()
9494
}
9595

9696
/**
97-
* Get the current selected value
97+
* Get the value of the enumerator
9898
*
9999
* @return null|bool|int|float|string
100100
*/
@@ -104,7 +104,7 @@ final public function getValue()
104104
}
105105

106106
/**
107-
* Get the current selected constant name
107+
* Get the name of the enumarator
108108
*
109109
* @return string
110110
*/
@@ -114,7 +114,7 @@ final public function getName()
114114
}
115115

116116
/**
117-
* Get the ordinal number of the selected value
117+
* Get the ordinal number of the enumerator
118118
*
119119
* @return int
120120
*/
@@ -139,7 +139,7 @@ final public function getOrdinal()
139139
}
140140

141141
/**
142-
* Compare this enum against another enum and check if it's the same
142+
* Compare this enumerator against another enumerator and check if it's the same
143143
*
144144
* @param mixed $enum
145145
* @return bool
@@ -151,7 +151,7 @@ final public function is($enum)
151151
}
152152

153153
/**
154-
* Get an enum of the given value or instance
154+
* Instantiate an enumerator of the given value or instance
155155
*
156156
* On passing an extended instance the instance will be returned if the value
157157
* is inherited by the called class or if $tradeExtendedAsUnknown is disabled
@@ -196,12 +196,12 @@ final public static function get($value, $tradeExtendedAsUnknown = true)
196196
}
197197

198198
/**
199-
* Get an enum by the given name
199+
* Instantiate an enumarator by the given name
200200
*
201-
* @param string $name The name to instantiate the enum by
201+
* @param string $name The name of the enumerator
202202
* @return static
203203
* @throws InvalidArgumentException On an invalid or unknown name
204-
* @throws LogicException On ambiguous constant values
204+
* @throws LogicException On ambiguous values
205205
*/
206206
final public static function getByName($name)
207207
{
@@ -220,12 +220,12 @@ final public static function getByName($name)
220220
}
221221

222222
/**
223-
* Get an enum by the given ordinal number
223+
* Instantiate an enumeration by the given ordinal number
224224
*
225-
* @param int $ordinal The ordinal number to instantiate the enum by
225+
* @param int $ordinal The ordinal number or the enumerator
226226
* @return static
227227
* @throws InvalidArgumentException On an invalid ordinal number
228-
* @throws LogicException On ambiguous constant values
228+
* @throws LogicException On ambiguous values
229229
*/
230230
final public static function getByOrdinal($ordinal)
231231
{
@@ -249,7 +249,7 @@ final public static function getByOrdinal($ordinal)
249249
}
250250

251251
/**
252-
* Clears all instantiated enums
252+
* Clear all instantiated enumerators of the called class
253253
*
254254
* NOTE: This can break singleton behavior ... use it with caution!
255255
*
@@ -273,7 +273,7 @@ final public static function getConstants()
273273
}
274274

275275
/**
276-
* Detect constants available by given class
276+
* Detect all available constants by the given class
277277
*
278278
* @param string $class
279279
* @return array
@@ -314,12 +314,12 @@ private static function detectConstants($class)
314314
}
315315

316316
/**
317-
* Instantiate an enum by a name of a constant.
317+
* Instantiate an enumarator by the given name.
318318
*
319319
* This will be called automatically on calling a method
320-
* with the same name of a defined constant.
320+
* with the same name of a defined enumerator.
321321
*
322-
* @param string $method The name to instantiate the enum by (called as method)
322+
* @param string $method The name of the enumeraotr (called as method)
323323
* @param array $args There should be no arguments
324324
* @return static
325325
* @throws InvalidArgumentException On an invalid or unknown name

src/MabeEnum/EnumMap.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,47 @@ class EnumMap extends SplObjectStorage
1717
{
1818

1919
/**
20-
* key()-behaviour: return the current iterator position
20+
* key()-behaviour: return the iterator position
2121
*/
2222
const KEY_AS_INDEX = 1;
2323

2424
/**
25-
* key()-behaviour: return the current enum name
25+
* key()-behaviour: return the name of the current element
2626
*/
2727
const KEY_AS_NAME = 2;
2828

2929
/**
30-
* key()-behaviour: return the current enum value
30+
* key()-behaviour: return the value of the current element
3131
*/
3232
const KEY_AS_VALUE = 3;
3333

3434
/**
35-
* key()-behaviour: return the current enum ordinal
35+
* key()-behaviour: return the ordinal number of the current element
3636
*/
3737
const KEY_AS_ORDINAL = 4;
3838

3939
/**
40-
* current()-behaviour: return the current enum object
40+
* current()-behaviour: return the instance of the enumerator
4141
*/
4242
const CURRENT_AS_ENUM = 8;
4343

4444
/**
45-
* current()-behaviour: return data mapped the current enum
45+
* current()-behaviour: return the data mapped the enumerator
4646
*/
4747
const CURRENT_AS_DATA = 16;
4848

4949
/**
50-
* current()-behaviour: return the current enum name
50+
* current()-behaviour: return the name of the enumerator
5151
*/
5252
const CURRENT_AS_NAME = 24;
5353

5454
/**
55-
* current()-behaviour: return the current enum value
55+
* current()-behaviour: return the value of the enumerator
5656
*/
5757
const CURRENT_AS_VALUE = 32;
5858

5959
/**
60-
* current()-behaviour: return the current enum ordinal
60+
* current()-behaviour: return the ordinal number of the enumerator
6161
*/
6262
const CURRENT_AS_ORDINAL = 40;
6363

@@ -96,7 +96,7 @@ public function __construct($enumClass, $flags = null)
9696
}
9797

9898
/**
99-
* Get the classname of enumeration this map is for
99+
* Get the classname of the enumeration this map is for
100100
* @return string
101101
*/
102102
public function getEnumClass()
@@ -146,7 +146,7 @@ public function getFlags()
146146
}
147147

148148
/**
149-
* Attach a new enumeration or overwrite an existing one
149+
* Attach a new enumerator or overwrite an existing one
150150
* @param Enum|null|boolean|int|float|string $enum
151151
* @param mixed $data
152152
* @return void
@@ -159,7 +159,7 @@ public function attach($enum, $data = null)
159159
}
160160

161161
/**
162-
* Test if the given enumeration exists
162+
* Test if the given enumerator exists
163163
* @param Enum|null|boolean|int|float|string $enum
164164
* @return boolean
165165
*/
@@ -175,7 +175,7 @@ public function contains($enum)
175175
}
176176

177177
/**
178-
* Detach an enumeration
178+
* Detach an enumerator
179179
* @param Enum|null|boolean|int|float|string $enum
180180
* @return void
181181
* @throws InvalidArgumentException On an invalid given enum
@@ -187,7 +187,7 @@ public function detach($enum)
187187
}
188188

189189
/**
190-
* Get a unique identifier for the given enumeration
190+
* Get a unique identifier for the given enumerator
191191
* @param Enum|scalar $enum
192192
* @return string
193193
* @throws InvalidArgumentException On an invalid given enum
@@ -200,7 +200,7 @@ public function getHash($enum)
200200
}
201201

202202
/**
203-
* Test if the given enumeration exists
203+
* Test if the given enumerator exists
204204
* @param Enum|null|boolean|int|float|string $enum
205205
* @return boolean
206206
* @see contains()
@@ -211,7 +211,7 @@ public function offsetExists($enum)
211211
}
212212

213213
/**
214-
* Get mapped data for this given enum
214+
* Get mapped data for the given enumerator
215215
* @param Enum|null|boolean|int|float|string $enum
216216
* @return mixed
217217
* @throws InvalidArgumentException On an invalid given enum
@@ -223,7 +223,7 @@ public function offsetGet($enum)
223223
}
224224

225225
/**
226-
* Attach a new enumeration or overwrite an existing one
226+
* Attach a new enumerator or overwrite an existing one
227227
* @param Enum|null|boolean|int|float|string $enum
228228
* @param mixed $data
229229
* @return void
@@ -237,7 +237,7 @@ public function offsetSet($enum, $data = null)
237237
}
238238

239239
/**
240-
* Detach an existing enumeration
240+
* Detach an existing enumerator
241241
* @param Enum|null|boolean|int|float|string $enum
242242
* @return void
243243
* @throws InvalidArgumentException On an invalid given enum

0 commit comments

Comments
 (0)