Apply fixes from StyleCI
This commit is contained in:
committed by
StyleCI Bot
parent
20f46adbc4
commit
9596d88b48
@@ -4,7 +4,6 @@ namespace App\Interfaces;
|
||||
|
||||
/**
|
||||
* Borrowed some ideas from myclabs/php-enum after this was created
|
||||
* @package App\Models\Enums
|
||||
*/
|
||||
abstract class Enum
|
||||
{
|
||||
@@ -13,12 +12,13 @@ abstract class Enum
|
||||
protected static $labels = [];
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* Create an instance of this Enum
|
||||
*
|
||||
* @param $val
|
||||
*/
|
||||
public function __construct($val)
|
||||
@@ -28,6 +28,7 @@ abstract class Enum
|
||||
|
||||
/**
|
||||
* Return the value that's been set if this is an instance
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
final public function getValue()
|
||||
@@ -37,7 +38,9 @@ abstract class Enum
|
||||
|
||||
/**
|
||||
* Return the label, try to return the translated version as well
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
final public static function label($value)
|
||||
@@ -62,7 +65,9 @@ abstract class Enum
|
||||
|
||||
/**
|
||||
* Get the numeric value from a string code
|
||||
*
|
||||
* @param $code
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
public static function getFromCode($code)
|
||||
@@ -72,14 +77,16 @@ abstract class Enum
|
||||
|
||||
/**
|
||||
* Convert the integer value into one of the codes
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return false|int|string
|
||||
*/
|
||||
public static function convertToCode($value)
|
||||
{
|
||||
$value = (int) $value;
|
||||
if (!array_key_exists($value, static::$codes)) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
return static::$codes[$value];
|
||||
@@ -87,7 +94,9 @@ abstract class Enum
|
||||
|
||||
/**
|
||||
* Select box entry items
|
||||
* @param bool $add_blank
|
||||
*
|
||||
* @param bool $add_blank
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function select($add_blank = false): array
|
||||
@@ -106,8 +115,10 @@ abstract class Enum
|
||||
|
||||
/**
|
||||
* Returns all possible values as an array
|
||||
* @return array Constant name in key, constant value in value
|
||||
*
|
||||
* @throws \ReflectionException
|
||||
*
|
||||
* @return array Constant name in key, constant value in value
|
||||
*/
|
||||
public static function toArray(): array
|
||||
{
|
||||
@@ -122,9 +133,10 @@ abstract class Enum
|
||||
|
||||
/**
|
||||
* @param Enum $enum
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
final public function equals(Enum $enum): bool
|
||||
final public function equals(self $enum): bool
|
||||
{
|
||||
return $this->getValue() === $enum->getValue() && get_called_class() == get_class($enum);
|
||||
}
|
||||
@@ -132,11 +144,14 @@ abstract class Enum
|
||||
/**
|
||||
* Returns a value when called statically like so: MyEnum::SOME_VALUE() given SOME_VALUE is a
|
||||
* class constant
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $arguments
|
||||
* @return static
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
* @throws \ReflectionException
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function __callStatic($name, $arguments)
|
||||
{
|
||||
@@ -144,6 +159,7 @@ abstract class Enum
|
||||
if (isset($array[$name])) {
|
||||
return new static($array[$name]);
|
||||
}
|
||||
|
||||
throw new \BadMethodCallException(
|
||||
"No static method or enum constant '$name' in class ".get_called_class()
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user