/** * {@inheritdoc} */ public function toPhonetic(HexFormatContext $context) { $context->setCurrentByte($this); if ($this->isNumeric()) { return NumericHexFormatter::getInstance()->format($this); } if ($this->isTeen()) { return ByteEnum::search((string) $this); } $first = $this->firstNibble->toPhonetic($context); $second = $this->secondNibble->toPhonetic($context); $join = NibbleJoiner::getInstance()->join($first, $second); return sprintf('%s%s%s', $first, $join, $second); }
/** * Return phonetic nibble value * * Due to multiple possible constants based on nibble position (first, second) * this method should be used in favor of the default search method * * @param Nibble $nibble * @param bool $isFirst * @return string */ public static function find(Nibble $nibble, $isFirst) { $keys = array_keys(static::toArray(), $nibble->getValue(), true); return $isFirst ? $keys[0] : $keys[1]; }