{@inheritdoc}

@throws UnexpectedTypeException
170257
public function revert(PromotionSubjectInterface $subject, array $configuration, PromotionInterface $promotion): void
    {
        if (!$subject instanceof OrderInterface && !$subject instanceof OrderItemInterface) {
            throw new UnexpectedTypeException(
                $subject,
                'Sylius\Component\Core\Model\OrderInterface or Sylius\Component\Core\Model\OrderItemInterface'
            );
        }

        foreach ($subject->getAdjustments(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT) as $adjustment) {
            if ($promotion->getCode() === $adjustment->getOriginCode()) {
                $subject->removeAdjustment($adjustment);
            }
        }
    }
1226654
private function initTableTypes()
    {
        $this->tableTypes = [];

        foreach ($this->loadTableTypes() as $type) {
            if (!$type instanceof TableTypeInterface) {
                throw new UnexpectedTypeException($type, TableTypeInterface::class);
            }

            $this->tableTypes[get_class($type)] = $type;
        }
    }
161240
private function initFilterTypeExtensions()
    {
        $this->filterTypeExtensions = [];

        foreach ($this->loadFilterTypeExtensions() as $extension) {
            if (!$extension instanceof FilterTypeExtensionInterface) {
                throw new UnexpectedTypeException($extension, FilterTypeExtensionInterface::class);
            }

            $type = $extension->getExtendedType();

            $this->filterTypeExtensions[$type][] = $extension;
        }
    }
481261
public function validate($value, Constraint $constraint)
    {
        if (!$constraint instanceof PasswordRestrictions) {
            throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\PasswordRestrictions');
        }

        if (null === $value) {
            return;
        }

        if (null !== $this->minLength) {
            $this->validateMinLength($value);
        }

        if (null !== $this->maxLength) {
            $this->validateMaxLength($value);
        }

        if (null !== $this->minDigits) {
            $this->validateMinDigits($value);
        }

        if (null !== $this->minUppercase) {
            $this->validateMinUppercase($value);
        }

        if (null !== $this->minSpecialCharacters) {
            $this->validateMinSpecialCharacters($value);
        }
    }
600179
private function createProperty()
    {
        $propType = $this->propertyType();
        if (empty($propType)) {
            $ident = $this->propertyIdent();
            if ($ident && is_string($ident)) {
                $message = sprintf('Missing property type for property "%s"', $ident);
            } else {
                $message = sprintf('Missing property type');
            }
            throw new UnexpectedValueException($message);
        }

        $prop = $this->propertyFactory()->create($propType);

        $prop->setIdent($this->propertyIdent());
        $prop->setData($this->propertyData());

        return $prop;
    }
1292826
public function filterIn(string $type, $parameter)
    {
        if ($this->isType($type, $parameter)) {
            return $parameter;
        }
        $value = $this->getFilter($type)->filterIn($parameter, $type);
        if (!$this->isType($type, $value)) {
            throw new UnexpectedValueException(sprintf('FilterIn did not return an instance of "%s".', $type));
        }

        return $value;
    }
1317418
public function onChannelPreDelete(ResourceControllerEvent $event): void
    {
        $channel = $event->getSubject();

        if (!$channel instanceof ChannelInterface) {
            throw new UnexpectedTypeException(
                $channel,
                ChannelInterface::class
            );
        }

        $results = $this->channelRepository->findBy(['enabled' => true]);

        if (!$results || (count($results) === 1 && current($results) === $channel)) {
            $event->stop('sylius.channel.delete_error');
        }
    }
442593
public function asReal(): Primitive\Real
    {
        if (!$this->_element instanceof Primitive\Real) {
            throw new \UnexpectedValueException(
                $this->_generateExceptionMessage(Element::TYPE_REAL));
        }
        return $this->_element;
    }
251015
function(expectedType, value) {
  var actualType = getType(value);
  if (expectedType!== actualType) {
    throw new TypeError('Expected type to be ' +
      expectedType + ', but got ' + actualType);
  }
  return value;
}
1108836
public function transform($value)
    {
        if (null === $value) {
            return null;
        }

        if (!is_string($value)) {
            throw new UnexpectedTypeException($value, 'string');
        }

        return true;
    }
733948
private function initTypeExtensions()
    {
        $this->typeExtensions = [];

        foreach ($this->loadTypeExtensions() as $extension) {
            if (!$extension instanceof BlockTypeExtensionInterface) {
                throw new UnexpectedTypeException($extension, 'Fxp\Component\Block\BlockTypeExtensionInterface');
            }

            foreach ($extension::getExtendedTypes() as $extendedType) {
                $this->typeExtensions[$extendedType][] = $extension;
            }
        }
    }
1103044
public function set($key, $value)
    {
        $result = $this->allowed($value);
        if ($this->passes($result)) {
            parent::set($key, $this->normalize($value));
        } else {
            throw new \UnexpectedValueException(sprintf(
                'Value of type "%s" forbidden in this instance of %s',
                gettype($value),
                get_class($this)
            ));
        }
    }
6360
public function remove($value)
    {
        if (!is_string($value)) {
            throw new UnexpectedTypeException($value, 'string', 'value');
        }
        if (empty($value)) {
            return;
        }

        if ($this->allowTokenize) {
            $this->values = array_diff($this->values, explode($this->delimiter, $value));
        } else {
            $this->values = array_diff($this->values, [$value]);
        }
    }
853866
public function add(ResourceInterface $resource): void
    {
        if (!$resource instanceof $this->interface) {
            throw new UnexpectedTypeException($resource, $this->interface);
        }

        if (in_array($resource, $this->findAll())) {
            throw new ExistingResourceException();
        }

        $this->arrayObject->append($resource);
    }
329970
public function validate($value, Constraint $constraint)
    {
        if (!$constraint instanceof Collection) {
            throw new UnexpectedTypeException($constraint, Collection::class);
        }

        if (null === $value) {
            return;
        }

        if (!is_array($value) && !$value instanceof \Traversable) {
            throw new UnexpectedTypeException($value, 'array or Traversable');
        }

        foreach ($value as $field => $fieldValue) {
            foreach ($constraint->constraints as $fieldConstraint) {
                $this->context->getValidator()
                    ->inContext($this->context)
                    ->atPath('[' . $field . ']')
                    ->validate($fieldValue, $fieldConstraint);
            }
        }
    }
899988
private static function validateConstraint(Constraint $constraint): void
    {
        if (!$constraint instanceof UniqueEntity) {
            throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\UniqueEntity');
        }

        if (!\is_array($constraint->fields) && !\is_string($constraint->fields)) {
            throw new UnexpectedTypeException($constraint->fields, 'array');
        }

        if (null !== $constraint->errorPath && !\is_string($constraint->errorPath)) {
            throw new UnexpectedTypeException($constraint->errorPath, 'string or null');
        }

        if (0 === \count((array) $constraint->fields)) {
            throw new ConstraintDefinitionException('At least one field has to be specified.');
        }
    }
681280
public function validate($value, Constraint $constraint)
    {
        if (!$constraint instanceof Json) {
            throw new UnexpectedTypeException($constraint, Json::class);
        }

        if (null === $value || '' === $value) {
            return;
        }

        if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
            throw new UnexpectedTypeException($value, 'string');
        }

        if (json_decode($value) || json_last_error() === JSON_ERROR_NONE) {
            return;
        }

        $this->context->buildViolation($constraint->message)
            ->setParameter('{{ value }}', $this->formatValue($value))
            ->addViolation();
    }