Skip to content

Commit

Permalink
III-2490: Make Enum::getAllowedValues() static
Browse files Browse the repository at this point in the history
  • Loading branch information
bertramakers committed Feb 28, 2018
1 parent 83a8dc8 commit db758ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/String/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,28 @@ final public function __construct($value)
$this->setValue($value);
}

/**
* @return string[]
*/
abstract protected function getAllowedValues();

/**
* @param string $value
* @throws \InvalidArgumentException
*/
private function guardAllowedValue($value)
{
$allowed = $this->getAllowedValues();
$allowed = static::getAllowedValues();
if (!in_array($value, $allowed)) {
throw new \InvalidArgumentException(
"Encountered unknown value '{$value}'. Allowed values: " . implode(', ', $allowed)
);
}
}

/**
* @return string[]
*/
public static function getAllowedValues()
{
return [];
}

/**
* @param string $name
* @param array $arguments
Expand Down
2 changes: 1 addition & 1 deletion tests/String/MockEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MockEnum extends Enum
/**
* @return string[]
*/
public function getAllowedValues()
public static function getAllowedValues()
{
return [
'foo',
Expand Down

0 comments on commit db758ff

Please sign in to comment.