@return string

@throws \UnexpectedValueException
766695
protected function getMetaForeignKey()
    {
        foreach ($this->builtInClasses as $model => $meta) {
            if ($this instanceof $model) {
                $basename = class_basename($model);

                return sprintf('%s_id', strtolower($basename));
            }
        }

        throw new UnexpectedValueException(sprintf('%s must extends one of Corcel built-in models: Comment, Post, Term or User.', static::class));
    }
1366090
public function asBitString(): Primitive\BitString
    {
        if (!$this->_element instanceof Primitive\BitString) {
            throw new \UnexpectedValueException(
                $this->_generateExceptionMessage(Element::TYPE_BIT_STRING));
        }
        return $this->_element;
    }
39883
protected function parse(): array
    {
        $offset = 0;
        $name = $this->_parseName($offset);
        if ($offset < $this->_len) {
            $remains = substr($this->_dn, $offset);
            throw new \UnexpectedValueException(
                "Parser finished before the end of string" .
                     ", remaining: '$remains'.");
        }
        return $name;
    }
225458
public function toValue() {
    $text = $this->getText();
    $quote_char = $text[0];
    $text = substr($text, 1, -1);
    if ($quote_char === '"') {
      $rules = array(
        preg_quote('\\\\') => '\\',
        preg_quote('\n') => "\n",
        preg_quote('\t') => "\t",
        preg_quote('\"') => '"',
        preg_quote('\$') => '$',
        preg_quote('\r') => "\r",
        preg_quote('\v') => "\v",
        preg_quote('\f') => "\f",
        preg_quote('\e') => "\e",
        '\\\\[0-7]{1,3}' => '__octal__',
        '\\\\x[0-9A-Fa-f]{1,2}' => '__hex__',
      );
    }
    else {
      $rules = array(
        preg_quote('\\\\') => '\\',
        preg_quote("\\'") => "'"
      );
    }
    $replacements = array_values($rules);
    $regex = '@(' . implode(')|(', array_keys($rules)) . ')@';
    return preg_replace_callback($regex, function ($matches) use ($replacements) {
      // find the first non-empty element (but skipping $matches[0]) using a quick for loop
      for ($i = 1; '' === $matches[$i]; ++$i);

      $match = $matches[0];
      $replacement = $replacements[$i - 1];
      if ($replacement === '__octal__') {
        $replacement = chr(octdec(substr($match, 1)));
      }
      elseif ($replacement === '__hex__') {
        $replacement = chr(hexdec(substr($match, 2)));
      }
      return $replacement;
    }, $text);
  }
1057466
public function getLevelName()
    {
        switch ($this->getLevel()) {
            case self::LEVEL_INFO:
                return 'Info';

            case self::LEVEL_WARNING:
                return 'Warning';

            case self::LEVEL_ERROR:
                return 'Error';

            default:
                throw new \UnexpectedValueException('Level was set to ' . $this->getLevel());
        }
    }
236888
private function buildConnection()
    {
        $connection = stream_socket_client("tcp://{$this->host}:{$this->port}", $errno, $message);
        $success    = fread($connection, 26);

        if (false === $connection || false === $success) {
            throw new \UnexpectedValueException("Failed to connect: $message");
        }

        return $connection;
    }
120875
public function getModel()
    {
        if(!$this->__model instanceof ModelInterface)
        {
            $this->__model = $this->getObject($this->__model);

            if(!$this->__model instanceof ModelInterface)
            {
                throw new \UnexpectedValueException(
                    'Model: '.get_class($this->__model).' does not implement ModelInterface'
                );
            }
        }

        return $this->__model;
    }
35702
public function getModel()
    {
        if(!$this->_model instanceof KModelInterface)
        {
            //Make sure we have a model identifier
            if(!($this->_model instanceof KObjectIdentifier)) {
                $this->setModel($this->_model);
            }

            $this->_model = $this->getObject($this->_model);

            if(!$this->_model instanceof KModelInterface)
            {
                throw new UnexpectedValueException(
                    'Model: '.get_class($this->_model).' does not implement KModelInterface'
                );
            }

            //Inject the request into the model state
            $this->_model->setState($this->getRequest()->query->toArray());
        }

        return $this->_model;
    }
55704
public function getIterator()
    {

        $result = $this->data !== null ? $this->data : call_user_func($this->getter);

        if (!$result) {
            return new ArrayIterator([]);
        }

        if ($result instanceof Iterator) {
            return $result;
        }

        if (is_array($result)) {
            return new ArrayIterator($result);
        }

        if (!$result instanceof Traversable) {
            throw new UnexpectedValueException('The returned result of the assigned callable is not supported (traversable)');
        }

        $array = [];

        foreach ($result as $item) {
            $array[] = $item;
        }

        return new ArrayIterator($array);
    }
294889
public function getTemplate()
    {
        if(!$this->__template instanceof TemplateInterface)
        {
            $this->__template = $this->getObject($this->__template);

            if(!$this->__template instanceof TemplateInterface)
            {
                throw new \UnexpectedValueException(
                    'Template: '.get_class($this->_model).' does not implement TemplateInterface'
                );
            }
        }

        return $this->__template;
    }
1110940
public function getUser()
    {
        if(!$this->_user instanceof UserInterface)
        {
            $this->_user = $this->getObject('user', ObjectConfig::unbox($this->_user));

            if(!$this->_user instanceof UserInterface)
            {
                throw new \UnexpectedValueException(
                    'User: '.get_class($this->_user).' does not implement UserInterface'
                );
            }
        }

        return $this->_user;
    }
422531
public function getValue()
    {
        $out = [];
        foreach ($this->value as $key => $value) {
            $out[] = $key.'='.(is_array($value) ? implode(',', $value) : $value);
        }

        return strtoupper(implode(';', $out));
    }
1326787
public function getRequest()
    {
        if(!$this->_request instanceof KDispatcherRequestInterface)
        {
            $this->_request = $this->getObject($this->_request);

            if(!$this->_request instanceof KDispatcherRequestInterface)
            {
                throw new UnexpectedValueException(
                    'Request: '.get_class($this->_request).' does not implement KDispatcherRequestInterface'
                );
            }
        }

        return $this->_request;
    }
77654
public function getNoncer()
    {
        if (!isset($this->noncer)) {
            $this->noncer = new self::$defaultNoncerClass($this->noncerLength);
            if (!$this->noncer instanceof NoncerInterface) {
                throw new \UnexpectedValueException('Noncer must implement Acquia\Rest\NoncerInterface');
            }
        }
        return $this->noncer;
    }
337043
public function asEnumerated(): Primitive\Enumerated
    {
        if (!$this->_element instanceof Primitive\Enumerated) {
            throw new \UnexpectedValueException(
                $this->_generateExceptionMessage(Element::TYPE_ENUMERATED));
        }
        return $this->_element;
    }
564700
public function asBMPString(): Primitive\BMPString
    {
        if (!$this->_element instanceof Primitive\BMPString) {
            throw new \UnexpectedValueException(
                $this->_generateExceptionMessage(Element::TYPE_BMP_STRING));
        }
        return $this->_element;
    }
612150
public function transform($string)
    {
        $string = $this->transliterator->transliterate($string);
        if ($string === false) {
            throw new UnexpectedValueException($this->transliterator->getErrorMessage(), $this->transliterator->getErrorCode());
        }
        return $string;
    }