/** * @see \Doctrineum\Scalar\ScalarEnumType::convertToPHPValue for usage * * @param mixed $enumValue * * @return BooleanEnum|null * @throws \Doctrineum\Boolean\Exceptions\UnexpectedValueToConvert * @throws \Doctrineum\Scalar\Exceptions\CouldNotDetermineEnumClass * @throws \Doctrineum\Scalar\Exceptions\EnumClassNotFound */ protected function convertToEnum($enumValue) { try { return parent::convertToEnum($this->convertToEnumValue($enumValue)); } catch (\Doctrineum\Scalar\Exceptions\UnexpectedValueToConvert $exception) { // wrapping exception by local one throw new Exceptions\UnexpectedValueToConvert($exception->getMessage(), $exception->getCode(), $exception); } }
/** * @test */ public function I_can_use_it_as_an_enum() { $sutClass = $this->getSutClass(); self::assertTrue(class_exists($sutClass), "Class {$sutClass} not found"); self::assertTrue(is_a($sutClass, ScalarEnum::class, true), "Class {$sutClass} should be child of " . ScalarEnum::class); $typeClass = $this->getEnumTypeClass(); self::assertTrue(class_exists($typeClass), "Expected enum type class {$typeClass} not found"); self::assertTrue(is_a($typeClass, ScalarEnumType::class, true)); $typeClass::registerSelf(); self::assertTrue(ScalarEnumType::hasType($this->getEnumCode())); }
/** * @param $valueForEnum * @return float|int|null|string * @throws \Doctrineum\Scalar\Exceptions\UnexpectedValueToEnum */ protected function prepareValueForEnum($valueForEnum) { $valueForEnum = parent::prepareValueForEnum($valueForEnum); // like DrdPlus\Codes\Armaments\MeleeWeaponCode::light_axe = light_axe return preg_replace('~[^:]+::~', '', $valueForEnum); }