1 | <?php |
||
16 | class EnumMap extends SplObjectStorage |
||
17 | { |
||
18 | /** |
||
19 | * The classname of the enumeration type |
||
20 | * @var string |
||
21 | */ |
||
22 | private $enumeration; |
||
23 | |||
24 | /** |
||
25 | * Constructor |
||
26 | * @param string $enumeration The classname of the enumeration type |
||
27 | * @throws InvalidArgumentException |
||
28 | */ |
||
29 | 16 | public function __construct($enumeration) |
|
39 | |||
40 | /** |
||
41 | * Get the classname of the enumeration |
||
42 | * @return string |
||
43 | */ |
||
44 | 2 | public function getEnumeration() |
|
48 | |||
49 | /** |
||
50 | * Attach a new enumerator or overwrite an existing one |
||
51 | * @param Enum|null|boolean|int|float|string $enumerator |
||
52 | * @param mixed $data |
||
53 | * @return void |
||
54 | * @throws InvalidArgumentException On an invalid given enumerator |
||
55 | */ |
||
56 | 6 | public function attach($enumerator, $data = null) |
|
61 | |||
62 | /** |
||
63 | * Test if the given enumerator exists |
||
64 | * @param Enum|null|boolean|int|float|string $enumerator |
||
65 | * @return boolean |
||
66 | */ |
||
67 | 10 | public function contains($enumerator) |
|
77 | |||
78 | /** |
||
79 | * Detach an enumerator |
||
80 | * @param Enum|null|boolean|int|float|string $enumerator |
||
81 | * @return void |
||
82 | * @throws InvalidArgumentException On an invalid given enumerator |
||
83 | */ |
||
84 | 4 | public function detach($enumerator) |
|
89 | |||
90 | /** |
||
91 | * Test if the given enumerator exists |
||
92 | * @param Enum|null|boolean|int|float|string $enumerator |
||
93 | * @return boolean |
||
94 | * @see contains() |
||
95 | */ |
||
96 | 6 | public function offsetExists($enumerator) |
|
100 | |||
101 | /** |
||
102 | * Get mapped data for the given enumerator |
||
103 | * @param Enum|null|boolean|int|float|string $enumerator |
||
104 | * @return mixed |
||
105 | * @throws InvalidArgumentException On an invalid given enumerator |
||
106 | */ |
||
107 | 8 | public function offsetGet($enumerator) |
|
112 | |||
113 | /** |
||
114 | * Attach a new enumerator or overwrite an existing one |
||
115 | * @param Enum|null|boolean|int|float|string $enumerator |
||
116 | * @param mixed $data |
||
117 | * @return void |
||
118 | * @throws InvalidArgumentException On an invalid given enumerator |
||
119 | * @see attach() |
||
120 | */ |
||
121 | 6 | public function offsetSet($enumerator, $data = null) |
|
126 | |||
127 | /** |
||
128 | * Detach an existing enumerator |
||
129 | * @param Enum|null|boolean|int|float|string $enumerator |
||
130 | * @return void |
||
131 | * @throws InvalidArgumentException On an invalid given enumerator |
||
132 | * @see detach() |
||
133 | */ |
||
134 | 4 | public function offsetUnset($enumerator) |
|
139 | |||
140 | /** |
||
141 | * Get the current value |
||
142 | * @return mixed |
||
143 | */ |
||
144 | 2 | public function current() |
|
148 | |||
149 | /** |
||
150 | * Get the current key |
||
151 | * @return Enum|null |
||
|
|||
152 | */ |
||
153 | 2 | public function key() |
|
157 | } |
||
158 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.