Skip to content

Commit

Permalink
Merge pull request #75 from willemstuursma/php-72-optimizations
Browse files Browse the repository at this point in the history
Prefix all function calls with a backspace
  • Loading branch information
mnapoli authored Aug 1, 2018
2 parents 8c5649e + ca4a0a0 commit ca2f409
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cache:
- $HOME/.composer/cache

before_script:
- composer install -n
- travis_retry composer install -n

script:
- vendor/bin/phpunit
Expand Down
16 changes: 8 additions & 8 deletions src/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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());
}

/**
Expand All @@ -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 (!isset(static::$cache[$class])) {
$reflection = new \ReflectionClass($class);
static::$cache[$class] = $reflection->getConstants();
}
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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());
}

/**
Expand Down

0 comments on commit ca2f409

Please sign in to comment.