From cad9c482a81cbb878f85685cb6825c0e6ec2e749 Mon Sep 17 00:00:00 2001 From: Willem Stuursma Date: Tue, 31 Jul 2018 17:28:02 +0200 Subject: [PATCH 1/3] Prefix all function calls with a backspace --- src/Enum.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Enum.php b/src/Enum.php index f3aa212..f26b6a9 100644 --- a/src/Enum.php +++ b/src/Enum.php @@ -41,7 +41,7 @@ abstract class Enum implements \JsonSerializable public function __construct($value) { if (!$this->isValid($value)) { - throw new \UnexpectedValueException("Value '$value' is not part of the enum " . get_called_class()); + throw new \UnexpectedValueException("Value '$value' is not part of the enum " . \get_called_class()); } $this->value = $value; @@ -82,7 +82,7 @@ public function __toString() */ final public function equals(Enum $enum = null) { - return $enum !== null && $this->getValue() === $enum->getValue() && get_called_class() == get_class($enum); + return $enum !== null && $this->getValue() === $enum->getValue() && \get_called_class() === \get_class($enum); } /** @@ -92,7 +92,7 @@ final public function equals(Enum $enum = null) */ public static function keys() { - return array_keys(static::toArray()); + return \array_keys(static::toArray()); } /** @@ -118,8 +118,8 @@ public static function values() */ public static function toArray() { - $class = get_called_class(); - if (!array_key_exists($class, static::$cache)) { + $class = \get_called_class(); + if (!\array_key_exists($class, static::$cache)) { $reflection = new \ReflectionClass($class); static::$cache[$class] = $reflection->getConstants(); } @@ -136,7 +136,7 @@ public static function toArray() */ public static function isValid($value) { - return in_array($value, static::toArray(), true); + return \in_array($value, static::toArray(), true); } /** @@ -162,7 +162,7 @@ public static function isValidKey($key) */ public static function search($value) { - return array_search($value, static::toArray(), true); + return \array_search($value, static::toArray(), true); } /** @@ -181,7 +181,7 @@ public static function __callStatic($name, $arguments) return new static($array[$name]); } - throw new \BadMethodCallException("No static method or enum constant '$name' in class " . get_called_class()); + throw new \BadMethodCallException("No static method or enum constant '$name' in class " . \get_called_class()); } /** From ec1d4fc213648a1c36ab1f619e3461069b0a7d76 Mon Sep 17 00:00:00 2001 From: Willem Stuursma Date: Tue, 31 Jul 2018 17:31:44 +0200 Subject: [PATCH 2/3] Replace function call with language construct (isset([]) evaluates to true) --- src/Enum.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Enum.php b/src/Enum.php index f26b6a9..7a105d1 100644 --- a/src/Enum.php +++ b/src/Enum.php @@ -119,7 +119,7 @@ public static function values() public static function toArray() { $class = \get_called_class(); - if (!\array_key_exists($class, static::$cache)) { + if (!isset(static::$cache[$class])) { $reflection = new \ReflectionClass($class); static::$cache[$class] = $reflection->getConstants(); } From ca4a0a004c5167a1ff86f423b805f28bff43c789 Mon Sep 17 00:00:00 2001 From: Willem Stuursma Date: Tue, 31 Jul 2018 17:32:53 +0200 Subject: [PATCH 3/3] Add travis_retry to overcome transport failures in composer install --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a175e29..a1bc09a 100755 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ cache: - $HOME/.composer/cache before_script: - - composer install -n + - travis_retry composer install -n script: - vendor/bin/phpunit