Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Enum/AbstractTranslatedEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class AbstractTranslatedEnum implements EnumInterface
public function __construct(TranslatorInterface $translator, $transPattern)
{
if (false === strpos($transPattern, '%s')) {
throw new InvalidTranslatePatternException($transPattern);
throw InvalidTranslatePatternException::placeholderRequired($transPattern);
}

$this->translator = $translator;
Expand Down
10 changes: 9 additions & 1 deletion Exception/DuplicatedEnumException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,13 @@
*/
class DuplicatedEnumException extends \BadMethodCallException
{
//todo
/**
* @param string $name
*
* @return DuplicatedEnumException
*/
public static function alreadyRegistered($name)
{
return new self(sprintf('Enum with name "%s" is already registered', $name));
}
}
10 changes: 9 additions & 1 deletion Exception/InvalidEnumException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,13 @@
*/
class InvalidEnumException extends \DomainException
{
//todo
/**
* @param string $name
*
* @return InvalidEnumException
*/
public static function nonexistent($name)
{
return new self(sprintf('Nonexistent enum with name "%s" in registry', $name));
}
}
10 changes: 9 additions & 1 deletion Exception/InvalidTranslatePatternException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,13 @@
*/
class InvalidTranslatePatternException extends \InvalidArgumentException
{
//todo
/**
* @param string $transPattern
*
* @return InvalidTranslatePatternException
*/
public static function placeholderRequired($transPattern)
{
return new self(sprintf('Translation pattern "%s" must contain %%s placeholder', $transPattern));
}
}
4 changes: 2 additions & 2 deletions Registry/EnumRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class EnumRegistry implements EnumRegistryInterface
public function add(EnumInterface $enum)
{
if ($this->has($enum->getName())) {
throw new DuplicatedEnumException($enum->getName());
throw DuplicatedEnumException::alreadyRegistered($enum->getName());
}

$this->enums[$enum->getName()] = $enum;
Expand All @@ -34,7 +34,7 @@ public function add(EnumInterface $enum)
public function get($name)
{
if (!$this->has($name)) {
throw new InvalidEnumException($name);
throw InvalidEnumException::nonexistent($name);
}

return $this->enums[$name];
Expand Down