Commit 9bf343cb authored by Jan Kuchař's avatar Jan Kuchař

Enum::getScalarValue() -rename-> Enum::getScalar() (instance method)

parent c6ca8316
Pipeline #14365 passed with stages
in 31 seconds
......@@ -104,32 +104,35 @@ abstract class Enum
// -------- INSTANCE IMPLEMENTATION ---------
/** @var int|string */
private $scalarValue;
private $scalar;
protected function __construct($scalarValue)
/**
* @param int|string $scalar
*/
protected function __construct($scalar)
{
$this->scalarValue = $scalarValue;
$this->scalar = $scalar;
}
/**
* Provides scalar representation of enum value.
* @return int|string
*/
public function getScalarValue()
public function getScalar()
{
return $this->scalarValue;
return $this->scalar;
}
/**
* Retrieves constant name that is used to access enum value.
*
* Note: do not depend on this values, as it can change anytime. This value can be
* @internal Do not depend on this values, as it can change anytime. This value can be
* subject of refactorings of user-defined enums.
*/
public function getConstantName(): string
{
return self::getMeta()->getConstantNameForScalar(
self::getMeta()->getScalarForValue($this)
$this->getScalar()
);
}
......@@ -147,8 +150,8 @@ abstract class Enum
* @param int|string $theOtherScalarValue
* @return bool true if current scalar representation of value equals to given scalar value
*/
public function equalsScalarValue($theOtherScalarValue): bool
public function scalarEquals($theOtherScalarValue): bool
{
return self::getMeta()->getScalarForValue($this) === $theOtherScalarValue;
return $this->getScalar() === $theOtherScalarValue;
}
}
......@@ -35,7 +35,7 @@ final class Meta
private function buildScalarToValueMapping(array $values): array {
$scalarToValues = [];
foreach($values as $value) {
$scalar = $value->getScalarValue();
$scalar = $value->getScalar();
if (isset($scalarToValues[$scalar])) {
throw new \LogicException('You have provided duplicated values scalar names.');
}
......
......@@ -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()->getScalarValue());
\Tester\Assert::same('active', OrderState::ACTIVE()->getScalar());
\Tester\Assert::same(OrderState::ACTIVE(), OrderState::fromScalar('active'));
......@@ -17,5 +17,5 @@ class EqualsState extends \Grifart\Enum\Enum
\Tester\Assert::true(EqualsState::NEW()->equals(EqualsState::NEW()));
\Tester\Assert::false(EqualsState::NEW()->equals(EqualsState::ACTIVE()));
\Tester\Assert::true(EqualsState::NEW()->equalsScalarValue('new'));
\Tester\Assert::false(EqualsState::NEW()->equalsScalarValue('active'));
\Tester\Assert::true(EqualsState::NEW()->scalarEquals('new'));
\Tester\Assert::false(EqualsState::NEW()->scalarEquals('active'));
......@@ -29,5 +29,5 @@ abstract class ReflectionConstantNames2 extends \Grifart\Enum\Enum
}
}
\Tester\Assert::same('new', ReflectionConstantNames2::NEW()->getScalarValue());
\Tester\Assert::same('active', ReflectionConstantNames2::ACTIVE()->getScalarValue());
\Tester\Assert::same('new', ReflectionConstantNames2::NEW()->getScalar());
\Tester\Assert::same('active', ReflectionConstantNames2::ACTIVE()->getScalar());
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