Skip to content

Commit a37e3bc

Browse files
committed
Почищен код
1 parent a0e9563 commit a37e3bc

File tree

1 file changed

+19
-34
lines changed

1 file changed

+19
-34
lines changed

Enum.php

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,65 @@
22

33
namespace vjik\enum;
44

5+
use LogicException;
6+
use ReflectionException;
7+
use UnexpectedValueException;
8+
59
/**
610
* Abstract Enum class
7-
*
811
* @property mixed $id
912
* @property mixed $name
1013
*/
1114
abstract class Enum
1215
{
1316

14-
1517
/**
1618
* @var array
1719
*/
1820
protected static $_cache = [];
1921

20-
2122
/**
22-
* @var mixed
23+
* @var int|string
2324
*/
2425
protected $id;
2526

26-
2727
/**
2828
* @var string
2929
*/
3030
protected $name;
3131

32-
3332
/**
34-
* @param mixed $id
35-
*
36-
* @throws \UnexpectedValueException
33+
* @param int|string $id
34+
* @throws UnexpectedValueException
35+
* @throws ReflectionException
3736
*/
3837
public function __construct($id)
3938
{
4039
if (!static::isValid($id)) {
41-
throw new \UnexpectedValueException("Value '$id' is not part of the enum " . get_called_class());
40+
throw new UnexpectedValueException("Value '$id' is not part of the enum " . get_called_class());
4241
}
4342
foreach (static::toArray()[$id] as $k => $v) {
4443
$this->$k = $v;
4544
}
4645
}
4746

48-
4947
/**
5048
* Проверяет входит ли значение в допустимые
51-
*
52-
* @param $id
53-
* @param $filter
54-
*
49+
* @param int|string $id
50+
* @param array $filter
5551
* @return bool
52+
* @throws ReflectionException
5653
*/
5754
public static function isValid($id, array $filter = [])
5855
{
5956
return in_array($id, static::toIds($filter), true);
6057
}
6158

62-
6359
/**
6460
* Все доступные значения в виде массива с данными
65-
*
6661
* @param array $filter ['key' => 'value', ['operator', 'key', 'value'], …]
67-
*
6862
* @return array enum-значение - ключ, массив с данными - значение
63+
* @throws ReflectionException
6964
*/
7065
public static function toArray(array $filter = [])
7166
{
@@ -146,13 +141,11 @@ public static function toArray(array $filter = [])
146141
return $items;
147142
}
148143

149-
150144
/**
151145
* Все доступные значения в виде массива
152-
*
153146
* @param array $filter
154-
*
155147
* @return array
148+
* @throws ReflectionException
156149
*/
157150
public static function toIds(array $filter = [])
158151
{
@@ -163,13 +156,11 @@ public static function toIds(array $filter = [])
163156
return $ids;
164157
}
165158

166-
167159
/**
168160
* Все доступные значение с именами
169-
*
170161
* @param array $filter
171-
*
172162
* @return array enum-значение - ключ, имя - значение
163+
* @throws ReflectionException
173164
*/
174165
public static function toList(array $filter = [])
175166
{
@@ -180,13 +171,11 @@ public static function toList(array $filter = [])
180171
return $list;
181172
}
182173

183-
184174
/**
185175
* Все доступные значения в виде объектов
186-
*
187176
* @param array $filter
188-
*
189177
* @return array
178+
* @throws ReflectionException
190179
*/
191180
public static function toObjects(array $filter = [])
192181
{
@@ -197,13 +186,10 @@ public static function toObjects(array $filter = [])
197186
return $objects;
198187
}
199188

200-
201189
/**
202-
* @param $name
203-
*
190+
* @param string $name
204191
* @return mixed
205-
*
206-
* @throws \LogicException
192+
* @throws LogicException
207193
*/
208194
public function __get($name)
209195
{
@@ -213,10 +199,9 @@ public function __get($name)
213199
} elseif (property_exists($this, $name)) {
214200
return $this->{$name};
215201
}
216-
throw new \LogicException('Getting unknown property: ' . get_class($this) . '::' . $name);
202+
throw new LogicException('Getting unknown property: ' . get_class($this) . '::' . $name);
217203
}
218204

219-
220205
/**
221206
* @return string
222207
*/

0 commit comments

Comments
 (0)