Commit fb770fef authored by Jan Kuchař's avatar Jan Kuchař

renamed Enum::getScalar() -> Enum::toScalar()

parent 3f0d7920
......@@ -104,23 +104,23 @@ abstract class Enum
// -------- INSTANCE IMPLEMENTATION ---------
/** @var int|string */
private $scalar;
private $scalarValue;
/**
* @param int|string $scalar
* @param int|string $scalarValue
*/
protected function __construct($scalar)
protected function __construct($scalarValue)
{
$this->scalar = $scalar;
$this->scalarValue = $scalarValue;
}
/**
* Provides scalar representation of enum value.
* Returns scalar representation of enum value.
* @return int|string
*/
public function getScalar()
public function toScalar()
{
return $this->scalar;
return $this->scalarValue;
}
/**
......@@ -132,7 +132,7 @@ abstract class Enum
public function getConstantName(): string
{
return self::getMeta()->getConstantNameForScalar(
$this->getScalar()
$this->toScalar()
);
}
......@@ -152,6 +152,6 @@ abstract class Enum
*/
public function scalarEquals($theOtherScalarValue): bool
{
return $this->getScalar() === $theOtherScalarValue;
return $this->toScalar() === $theOtherScalarValue;
}
}
......@@ -39,7 +39,7 @@ final class Meta
// check type of all scalar values
$keyType = null;
foreach($values as $value) {
$scalar = $value->getScalar();
$scalar = $value->toScalar();
if ($keyType === NULL) {
$keyType = \gettype($scalar);
}
......@@ -49,7 +49,7 @@ final class Meta
}
foreach($values as $value) {
$scalar = $value->getScalar();
$scalar = $value->toScalar();
if (isset($scalarToValues[$scalar])) {
throw new UsageException('You have provided duplicated scalar values.');
}
......
......@@ -11,9 +11,6 @@
namespace Grifart\Enum;
// Project root exceptions:
use Throwable;
class UsageException extends \LogicException {}
abstract class RuntimeException extends \RuntimeException {}
......
......@@ -23,5 +23,5 @@ class OrderState extends \Grifart\Enum\Enum
\Tester\Assert::notSame(OrderState::NEW(), OrderState::DELIVERED());
\Tester\Assert::notSame(OrderState::ACTIVE(), OrderState::DELIVERED());
\Tester\Assert::same('active', OrderState::ACTIVE()->getScalar());
\Tester\Assert::same('active', OrderState::ACTIVE()->toScalar());
\Tester\Assert::same(OrderState::ACTIVE(), OrderState::fromScalar('active'));
......@@ -29,5 +29,5 @@ abstract class ReflectionConstantNames2 extends \Grifart\Enum\Enum
}
}
\Tester\Assert::same('new', ReflectionConstantNames2::NEW()->getScalar());
\Tester\Assert::same('active', ReflectionConstantNames2::ACTIVE()->getScalar());
\Tester\Assert::same('new', ReflectionConstantNames2::NEW()->toScalar());
\Tester\Assert::same('active', ReflectionConstantNames2::ACTIVE()->toScalar());
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment