Fix formatting and interfaces in nearly every file

This commit is contained in:
Nabeel Shahzad
2018-03-19 20:50:40 -05:00
parent 04c5b9e7bf
commit ccf56ddec1
331 changed files with 3282 additions and 2492 deletions

View File

@@ -4,20 +4,42 @@ namespace App\Interfaces;
/**
* Class EnumBase
* Borrowing some features from https://github.com/myclabs/php-enum
* after this was created :)
* @package App\Models\Enums
*/
abstract class Enum
{
protected static $labels = [];
protected static $cache = [];
protected $value;
/**
* Create an instance of this Enum
* @param $val
*/
public function __construct($val)
{
$this->value = $val;
}
/**
* Return the value that's been set if this is an instance
* @return mixed
*/
public function getValue()
{
return $this->value;
}
/**
* Return the label, try to return the translated version as well
* @param $value
* @return mixed
*/
public static function label($value) {
if(isset(static::$labels[$value])) {
public static function label($value)
{
if (isset(static::$labels[$value])) {
return trans(static::$labels[$value]);
}
}
@@ -28,7 +50,7 @@ abstract class Enum
public static function labels()
{
$labels = [];
foreach(static::$labels as $key => $label) {
foreach (static::$labels as $key => $label) {
$labels[$key] = trans($label);
}
@@ -38,10 +60,10 @@ abstract class Enum
/**
* Select box
*/
public static function select($add_blank=false)
public static function select($add_blank = false)
{
$labels = [];
if($add_blank) {
if ($add_blank) {
$labels[] = '';
}
@@ -59,7 +81,7 @@ abstract class Enum
*/
public static function toArray()
{
$class = get_called_class();
$class = static::class;
if (!array_key_exists($class, static::$cache)) {
$reflection = new \ReflectionClass($class);
static::$cache[$class] = $reflection->getConstants();
@@ -69,9 +91,19 @@ abstract class Enum
}
/**
* Returns a value when called statically like so: MyEnum::SOME_VALUE() given SOME_VALUE is a class constant
* @param Enum $enum
* @return bool
*/
protected function equals(Enum $enum): bool
{
return $this->getValue() === $enum->getValue() && get_called_class() == get_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
* @param array $arguments
* @return static
* @throws \BadMethodCallException
* @throws \ReflectionException