@inheritDoc

@throws InvalidVariantException If an invalid quality factor in encountered when building an server preference.
483666
public function setQualityFactor($qFactor)
    {
        if ($this->isFromServer && !$this->validQualityFactor($qFactor)) {
            throw new InvalidVariantException('Invalid quality factor "' . $qFactor . '" in server preferences');
        }

        $qFactor = $this->normalizeQualityFactor($qFactor);

        $clone = clone $this;
        $clone->qFactor = $qFactor;

        return $clone;
    }
369854
public function factor(StorageSelection $selection)
    {
        $file = $selection->getImpl();

        if (!($file instanceof \SplFileInfo)) {
            throw new InvalidConfigurationException('StorageSelection does not contain a SplFileInfo as impl property but this is mandatory for a LocalFileStorage.');
        }
        if (!$file->isFile() || !$file->isReadable()) {
            throw new InvalidConfigurationException('StorageSelection references a File that does not exists or is not readable.');
        }

        $format = $selection->getMetadata('format');
        if (!$format) {
            $format = $this->formatDiscoverStrategyInterface->getFormat($selection);
            if (!$format) {
                throw new InvalidConfigurationException('Could not discover format!');
            }

            if ($this->logger) {
                $this->logger->info("File $file was discovered as format '$format'", ['selection' => $selection->toArray()]);
            }
        }

        $localFile = new LocalFileStorage($file, $format);

        return $localFile;
    }
130184
private void validate(List<ByteBuffer> variables) throws InvalidRequestException
    {
        // Ensure that exactly one key has been specified.
        if (keyValidator.size() < 1)
            throw new InvalidRequestException("You must specify a PRIMARY KEY");
        else if (keyValidator.size() > 1)
            throw new InvalidRequestException("You may only specify one PRIMARY KEY");

        AbstractType<?> comparator;

        try
        {
            cfProps.validate();
            comparator = cfProps.getComparator();
        }
        catch (ConfigurationException e)
        {
            throw new InvalidRequestException(e.toString());
        }
        catch (SyntaxException e)
        {
            throw new InvalidRequestException(e.toString());
        }

        for (Map.Entry<Term, String> column : columns.entrySet())
        {
            ByteBuffer name = column.getKey().getByteBuffer(comparator, variables);

            if (keyAlias != null && keyAlias.equals(name))
                throw new InvalidRequestException("Invalid column name: "
                                                  + column.getKey().getText()
                                                  + ", because it equals to the key_alias.");

        }
    }
1023697
protected function handleMissingVar(File $phpCsFile, int $docBlockEndIndex, int $docBlockStartIndex, ?string $defaultValueType): void
    {
        $error = 'Doc Block annotation @var for variable missing';
        if ($defaultValueType === null) {
            $phpCsFile->addError($error, $docBlockEndIndex, 'VarAnnotationMissing');
            return;
        }

        $error .= ', type `' . $defaultValueType . '` detected';
        $fix = $phpCsFile->addFixableError($error, $docBlockEndIndex, 'WrongType');
        if (!$fix) {
            return;
        }

        $index = $phpCsFile->findPrevious(Tokens::$emptyTokens, $docBlockEndIndex - 1, $docBlockStartIndex, true);
        if (!$index) {
            $index = $docBlockStartIndex;
        }

        $phpCsFile->fixer->beginChangeset();
        $phpCsFile->fixer->addNewline($index);
        $phpCsFile->fixer->addContent($index, "\t" . ' * @var ' . $defaultValueType);
        $phpCsFile->fixer->endChangeset();
    }
222912
private function compareQualityFactor(PreferenceInterface $lValue, PreferenceInterface $rValue)
    {
        if ($rValue->getQualityFactor() < $lValue->getQualityFactor()) {
            return -1;
        } elseif ($rValue->getQualityFactor() > $lValue->getQualityFactor()) {
            return 1;
        } else {
            return 0;
        }
    }
251998
private function validateComponentKeys(array $v)
    {
        $diff = array_diff_key($v, array_flip($this->enabledComponentTypes));
        if (!empty($diff)) {
            throw new InvalidConfigurationException(sprintf(
                'Only "%s" component types are supported for configuration, "%s" more given.',
                implode('", "', $this->enabledComponentTypes),
                implode('", "', array_keys($diff))
            ));
        }

        return $v;
    }
183327
private function validate()
    {
        if (null === $this->provider) {
            throw new MissingProviderException('A provider must be set for converting a currency');
        }

        if (null === $this->from || null === $this->to) {
            throw new \RuntimeException('from and to parameters must be provided');
        }
    }
202042
private function validateInput( $settings ) {
        if ( !isset( $settings["serverUrl"] ) ||
             !isset( $settings["username"] ) ||
             !isset( $settings["password"] )
        ) {
            throw new \InvalidArgumentException( 'Username, password or serverUrl is incorrect' );
        }

        if ( !filter_var( $settings["serverUrl"], FILTER_VALIDATE_URL )
             || strpos( $settings["serverUrl"], "." ) === false
        ) {
            throw new \InvalidArgumentException( 'Invalid serverUrl has been provided' );
        }

        if ( !in_array( $settings['authMode'], [ 'OnlineFederation', 'Federation' ] ) ) {
            throw new \InvalidArgumentException( 'Provided authentication mode <' . $this->authMode . '> is not supported' );
        }
    }
19027
public function setPriority($priority)
    {
        if (!OptionsPriorities::isValid($priority)) {
            throw new InvalidOptionsException('priority is not valid, please refer to the documentation or use the constants of the class "OptionsPriorities"');
        }
        $this->priority = $priority;

        return $this;
    }
1168934
private void validateServerVariables(ValidationHelper helper, Context context, Set<String> variables, Server t) {
        ServerVariables serverVariables = t.getVariables();

        for (String variable : variables) {
            if (serverVariables == null || !serverVariables.containsKey(variable)) {
                final String message = Tr.formatMessage(tc, "serverVariableNotDefined", variable);
                helper.addValidationEvent(new ValidationEvent(ValidationEvent.Severity.ERROR, context.getLocation("variables"), message));
            }
        }
    }
368894
public function qualityFactorComparator($mediaType1, $mediaType2)
    {
        $diff = $mediaType2['q'] - $mediaType1['q'];

        // doesn't cope too well with values 1 > v > -1, so make sure we return simple integers
        if ($diff > 0) {
            $diff = 1;
        } elseif ($diff < 0) {
            $diff = -1;
        }

        return $diff;
    }
196194
protected function IDiv( $val )
	{
		if ( ! $val instanceof IntProxy ) throw new \InvalidArgumentException();

		/**
		 * @var DecimalValue $result
		 */
		$result = $this->Div( $val );
		return Integer::FromValue( $result->getValue()->getIntegerPart() );
	}
299049
protected static function _parseAccept($accept, array $defaults = null)
    {
        if (! empty($accept)) {
            // Get all of the types
            $types = explode(',', $accept);

            foreach ($types as $type) {
                // Split the type into parts
                $parts = explode(';', $type);

                // Make the type only the MIME
                $type = trim(array_shift($parts));

                // Default quality is 1.0
                $options = array('quality' => 1.0);

                foreach ($parts as $part) {
                    // Prevent undefined $value notice below
                    if (strpos($part, '=') === false) {
                        continue;
                    }

                    // Separate the key and value
                    list($key, $value) = explode('=', trim($part));

                    switch ($key) {
                        case 'q':
                            $options['quality'] = (float) trim($value);
                            break;
                        case 'version':
                            $options['version'] = (float) trim($value);
                            break;
                    }
                }

                // Add the accept type and quality
                $defaults[$type] = $options;
            }
        }

        // Make sure that accepts is an array
        $accepts = (array) $defaults;

        // Order by quality
        arsort($accepts);

        return $accepts;
    }
77504
private function _checkVariables() {
	    // Check to make sure that the $databaseComponent is a string
        if (! is_string($this->databaseComponent)) {
            throw new InvalidConfigException("Image Manager Component - Init: Database component '$this->databaseComponent' is not a string");
        }

        // Check to make sure that the $databaseComponent object exists
        if (Yii::$app->get($this->databaseComponent, false) === null) {
            throw new InvalidConfigException("Image Manager Component - Init: Database component '$this->databaseComponent' does not exists in application configuration");
        }

        // Check to make sure that the $databaseComponent is a yii\db\Connection object
        if (($databaseComponentClassName = get_class(Yii::$app->get($this->databaseComponent))) !== ($connectionClassName = Connection::className())) {
            throw new InvalidConfigException("Image Manager Component - Init: Database component '$this->databaseComponent' is not of type '$connectionClassName' instead it is '$databaseComponentClassName'");
        }
    }
957079
public function getContextConfigValue($varName, $defaultValue = null)
    {
        if ($this->type == InternalBaseBlock::INJECTOR_VAR) {
            return $this->context->getVarValue($varName, $defaultValue);
        }
        
        if ($this->type == InternalBaseBlock::INJECTOR_CFG) {
            return $this->context->getCfgValue($varName, $defaultValue);
        }
            
        throw new InvalidConfigException("The type '{$this->type}' is not supported.");
    }
17614
private void checkForDeletingVariant(JMFType nonVar, JSVariant var, boolean varIsAccess,
      JSchema accSchema, JSchema encSchema) throws JMFSchemaViolationException
  {
    // Deleting variant always has exactly two cases
    if (var.getCaseCount() != 2) {
      if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) JmfTr.debug(this, tc, "Compatibility violation (deleting variant):"
                                             + " var CaseCount = " + var.getCaseCount()
                                             + ", varIsAccess " + varIsAccess
                                             );
      if (varIsAccess) {
        violation(var, nonVar);
      }
      else {
        violation(nonVar, var);
      }
    }
    if (isEmpty(var.getCase(1))) {
      // Second case is empty tuple, so we proceed to compare the first case to the
      // candidate deletable type.
      JMFType compare = var.getCase(0);
      if (varIsAccess)
        recordCompatibilityInfo(compare, accSchema, nonVar, encSchema);
      else
        recordCompatibilityInfo(nonVar, accSchema, compare, encSchema);
    }
    else {
      if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) JmfTr.debug(this, tc, "Compatibility violation (deleting variant):"
                                             + " var Case(1) not empty"
                                             );
      if (varIsAccess) {
        violation(var, nonVar);
      }
      else {
        violation(nonVar, var);
      }
    }
  }
610819
static public function supportedVariables()
    {
        $out = array(
            'execution_time' => 'float (seconds, rounded to 1msec)',
            'mem_usage' => 'int (bytes, rounded to 1000)',
            'output_size' => 'int (bytes)'
        );
        /// @todo fix to run from eZ5 context
        if ( eZPerfLoggerDebug::isDebugEnabled() )
        {
            $out['db_queries'] = 'int';
            $out['accumulators/*'] = 'float (seconds, rounded to 1msec)';
            $out['accumulators/*/count'] = 'int (number of times operation executed)';
        }
        if ( extension_loaded( 'xhprof' ) )
        {
            $out['xhkprof_runs'] = 'string (csv list of identifiers)';
        }
        if ( isset( $_SERVER['UNIQUE_ID'] ) )
        {
            $out['unique_id'] = 'string (unique per-request identifier)';
        }
        /// @todo also take into account CP version numbers
        if ( version_compare( '4.7.0', eZPublishSDK::version() ) >= 0 )
        {
            $out['content/nodeid'] = 'int';
        }
        $out['_server/*'] = 'string (depending on the specific variable)';
        return $out;
    }