@param EntityId|SiteLink $target

@throws UnexpectedValueException
@return array

@todo Fix duplicated code
775157
private function getTargetParamsFromTarget( $target ) {
		if( $target instanceof EntityId ) {
			return array( 'id' => $target->getSerialization() );
		} elseif( $target instanceof SiteLink ) {
			return array(
				'site' => $target->getSiteId(),
				'title' => $target->getPageName(),
			);
		} else {
			throw new UnexpectedValueException( '$target needs to be an EntityId or SiteLink' );
		}
	}
994439
public function getCachedMixedMemberNameReferences()
    {
        $cache_directory = $this->config->getCacheDirectory();

        if (!$cache_directory) {
            return null;
        }

        $cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::UNKNOWN_MEMBER_CACHE_NAME;

        if (!is_readable($cache_location)) {
            return null;
        }

        $cache = unserialize((string) file_get_contents($cache_location));

        if (!is_array($cache)) {
            throw new \UnexpectedValueException('The reference cache must be an array');
        }

        return $cache;
    }
1359507
public function asLink($href=NULL,$target=NULL) {
		if (isset($href))
			$this->setProperty("href", $href);
		if(isset($target))
			$this->setProperty("target", $target);
		return $this->setTagName("a");
	}
342218
protected function getDomaincd($domain)
    {
        $pattern = '//epp:epp/epp:response/epp:resData/domain:chkData/domain:cd[domain:name[php:functionString("XPath\quote", text()) = \'%s\']]';
        $query = sprintf($pattern, XPath\quote($domain));
        $node = $this->getFirst($query);

        if ($node === null) {
            throw new UnexpectedValueException(sprintf('Domain with name [%s] not found.', $domain));
        }

        return $node;
    }
547823
public function store(Model $model, $source, $value)
    {
        if ( ! $this->isTranslated()) {
            $this->performStore($model, $source, $value);
            return;
        }

        /** @var Model|Translatable $model */

        if ( ! is_array($value)) {
            throw new UnexpectedValueException("Value should be in per-locale array format for translatable data");
        }

        foreach ($value as $locale => $singleValue) {

            // Safeguard: use empty string if non-nullable translated field is null
            if (null === $singleValue && ! $this->isNullable()) {
                $singleValue = '';
            }

            $this->performStore($model->translateOrNew($locale), $source, $singleValue);
        }
    }
481047
protected function getInvalidLinkError($scheme, $target, $anchorName = null)
    {
        $url = "$scheme://$target" . ($anchorName ? '#' . $anchorName : '');

        switch ($scheme) {
            case 'eznode':
                return sprintf('Invalid link "%s": target node cannot be found', $url);
            case 'ezobject':
                return sprintf('Invalid link "%s": target object cannot be found', $url);
            default:
                throw new InvalidArgumentException($scheme, "Given scheme '{$scheme}' is not supported.");
        }
    }
364357
protected function getItemsData($object, string $format = null, array $context = []): array
    {
        $data = [];

        foreach ($object as $obj) {
            $item = $this->normalizer->normalize($obj, $format, $context);
            if (!\is_array($item)) {
                throw new UnexpectedValueException('Expected item to be an array');
            }
            $data['_embedded']['item'][] = $item;
            $data['_links']['item'][] = $item['_links']['self'];
        }

        return $data;
    }
27238
protected function buildDataClaim($value)
    {
        @json_encode($value);

        if (($errorCode = json_last_error()) !== JSON_ERROR_NONE) {
            
            throw new UnexpectedValueException($this->jsonErrorMessage($errorCode));
        }

        return array('d', $value);
    }
1231277
public function findByKeys($primaryKeys)
    {
        $data = $this->newDataInstance(null, false);

        if (!is_array($primaryKeys)) {
            throw new \UnexpectedValueException(__METHOD__ . '|$primaryKeys must be an array !');
        }

        //~ Set values before cache
        foreach ($primaryKeys as $field => $value) {
            $this->setDataValue($data, $field, $value);
        }

        $data = $this->getCache($data);

        if ($data === false) {

            foreach ($primaryKeys as $field => $value) {
                $this->addWhere($field, $value);
            }

            $data = $this->selectOne();

            //~ Clear & set in cache
            $this->clear();
            $this->setCache($data);
        }

        return $data;
    }
225792
protected function processSymlink(string $target, $linkData)
    {
        $link = $this->getLink($linkData);

        if (!$link) {
            throw new InvalidArgumentException('No link passed in config');
        }

        if (!$target) {
            throw new InvalidArgumentException('No target passed in config');
        }

        if ($this->fileSystem->isAbsolutePath($target)) {
            throw new InvalidArgumentException(
                sprintf('Invalid symlink target path %s. It must be relative', $target)
            );
        }

        if ($this->fileSystem->isAbsolutePath($link)) {
            throw new InvalidArgumentException(
                sprintf('Invalid symlink link path %s. It must be relative', $link)
            );
        }

        $currentDirectory = realpath(getcwd());
        $targetPath = realpath($currentDirectory . DIRECTORY_SEPARATOR . $target);
        $linkPath = $currentDirectory . DIRECTORY_SEPARATOR . $link;

        if (!is_dir($targetPath) && !is_file($targetPath)) {
            if ($this->getConfig(static::SKIP_MISSED_TARGET, $link)) {
                return null;
            }
            throw new InvalidArgumentException(
                sprintf('The target path %s does not exists', $targetPath)
            );
        }

        try {
            $this->fileSystem->ensureDirectoryExists(\dirname($linkPath));
        } catch (\RuntimeException $exception) {
            throw new LinkDirectoryError($exception->getMessage(), $exception->getCode(), $exception);
        }

        if (is_link($linkPath) && realpath(readlink($linkPath)) === $targetPath) {
            $this->event->getIO()->write(
                sprintf(
                    '  Symlink <comment>%s</comment> to <comment>%s</comment> already created',
                    $target,
                    $link
                )
            );
            return null;
        }

        return (new Symlink())
            ->setTarget($targetPath)
            ->setLink($linkPath)
            ->setAbsolutePath($this->getConfig(static::ABSOLUTE_PATH, $linkData, false))
            ->setForceCreate($this->getConfig(static::FORCE_CREATE, $linkData, false));
    }
723660
public function getBaseTemplate($target, $templateId){
        $base = $this->getResolvedBase($target);
        if(is_array($base) && isset($base['templates']) && isset($base['templates'][$templateId])){
            return $base['templates'][$templateId];
        }
        return null;
    }
50911
public function offsetGet($offset)
    {
        switch ($offset) {
            case 'operator':
                return $this->getOperator();
                break;

            case 'leftSubTerm':
                return $this->getLeftSubTerm();
                break;

            case 'rightSubTerm':
                return $this->getRightSubTerm();
                break;

            default:
                throw new \UnexpectedValueException("Offset $offset does not exist.");
        }
    }
621078
private function identifyRequest($target = false)
    {
        $retval = false;

        $this->locateURI();

        $nb_engine = CNabuEngine::getEngine();

        if ($target) {
            $temp_target = CNabuSiteTarget::findByURL($this->nb_site, $this->page_uri);
            if ($temp_target instanceof CNabuSiteTarget && $temp_target->isValueNumeric('nb_language_id')) {
                $nb_language = new CNabuLanguage($temp_target);
                if ($nb_language->isFetched()) {
                    $this->nb_language = $nb_language;
                } else {
                    $this->nb_language = $this->nb_site->getDefaultLanguage();
                }
            }

            if (!($target instanceof CNabuSiteTarget) &&
                is_numeric($nb_site_target_id = nb_getMixedValue($target, 'nb_site_target_id'))
            ) {
                $target = new CNabuSiteTarget($nb_site_target_id);
                if ($target->isFetched()) {
                    $this->nb_site_target = $target;
                }
            } else {
                $this->nb_site_target = $target;
            }
            if ($this->nb_site_target instanceof CNabuSiteTarget &&
                $this->nb_language === null && $this->nb_site_target->isValueNumeric('nb_language_id')) {
                $this->nb_language = new CNabuLanguage($this->nb_site_target->getValue('nb_language_id'));
                if ($this->nb_language->isNew()) {
                    $this->nb_language = null;
                }
            }
            if ($this->nb_language === null) {
                $this->nb_language = $this->nb_site->getDefaultLanguage();
            }
            if ($this->nb_site_target !== null &&
                $this->nb_language !== null &&
                $this->nb_site_target->hasTranslation($this->nb_language)
            ) {
                $this->nb_response->setHTTPResponseCode(200);
                $nb_engine->traceLog('Page Status', 'Found');

                $retval = true;
            }
        } elseif ($this->findTargetByURL($this->page_uri)) {
            $nb_engine->traceLog("Page ID", $this->nb_site_target->getId());

            if ($this->nb_language === null) {
                throw new ENabuCoreException(ENabuCoreException::ERROR_LANGUAGE_NOT_FOUND_FOR_PAGE_URI);
            }
            $nb_engine->traceLog("Page language", $this->nb_language->getISO6391());
            $nb_engine->traceLog('Page Status', 'Found');

            $retval = true;
        }

        if (!($this->nb_site_target instanceof CNabuSiteTarget) || !$retval) {
            $nb_engine->traceLog('Page Status', 'Not found');
            $link = $this->nb_site->getPageNotFoundTargetLink();
            if ($link->isLinkable()) {
                if ($link->isTranslatedTarget()) {
                    $this->nb_language = $this->nb_site->getDefaultLanguage();
                    if ($this->nb_language instanceof CNabuLanguage &&
                        ($nb_site_target = $link->getTranslatedObject()) instanceof CNabuSiteTarget &&
                        ($nb_site_target->getTranslation($this->nb_language) instanceof CNabuSiteTargetLanguage)
                    ) {
                        $this->nb_site_target = $nb_site_target;
                        $retval = true;
                    }
                }
            }

            if ($this->nb_response->getHTTPResponseCode() === 0) {
                $this->nb_response->setHTTPResponseCode(404);
            }
        }

        return $retval;
    }
241111
public function get()
    {
        if ($this->date) {
            $result = $this->historical($this->date, $this->base, $this->targets);
        } else {
            $result = $this->latest($this->base, $this->targets);
        }

        // Ensure the result object is valid.
        if (!$result instanceof ResultContract) {
            throw new UnexpectedValueException('Invalid result type');
        }

        // Perform conversion if requested.
        if ($this->amount !== 1) {
            $converted = $result->rates;

            foreach ($converted as $key => $value) {
                $converted[$key] = round($this->amount * $value, 2);
            }

            // Attach converted values to results.
            $result->setConverted($converted);
        }

        return $result;
    }
8500
public function get($target = null)
    {
        $options = ['key' => $this->apiKey];

        if (null !== $target) {
            $this->url = sprintf('%s&target={target}', $this->url);

            $options['target'] = $target;
        }

        return $this->process($options);
    }
611531
public function getSettingList(Site $site)
    {
        $settingList = [];
        $items       = $this->getSettingBySiteId($site->getId());
        /** @var $setting \PageBuilder\Entity\Setting */
        foreach ($items as $setting) {
            $code               = $setting->getSettingKey()->getCode();
            $value              = $setting->getSettingValue() ?: $setting->getSettingKey()->getDefaultValue();
            $settingList[$code] = $value;
        }

        $locale                = $site->getLocale() ?: 'en_GB';
        $settingList           = array_merge($settingList, \Locale::parseLocale($locale));
        $settingList['locale'] = $locale;

        return $settingList;
    }
1345021
private function _parseAttrTypeAndValue(int &$offset): array
    {
        $idx = $offset;
        $type = $this->_parseAttrType($idx);
        $this->_skipWs($idx);
        if ($idx >= $this->_len || "=" != $this->_dn[$idx++]) {
            throw new \UnexpectedValueException("Invalid type and value pair.");
        }
        $this->_skipWs($idx);
        // hexstring
        if ($idx < $this->_len && "#" == $this->_dn[$idx]) {
            ++$idx;
            $data = $this->_parseAttrHexValue($idx);
            try {
                $value = Element::fromDER($data);
            } catch (DecodeException $e) {
                throw new \UnexpectedValueException(
                    "Invalid DER encoding from hexstring.", 0, $e);
            }
        } else {
            $value = $this->_parseAttrStringValue($idx);
        }
        $offset = $idx;
        return array($type, $value);
    }