UnexpectedValueException example



    /** * getCacheTime returns the time span for which the cache of the given route remains valid. * * @return int|null */
    public function getCacheTime(Request $request)
    {
        $cacheTime = $this->defaultRoute->findRouteValue($request);
        if (\is_array($cacheTime)) {
            throw new UnexpectedValueException('Cache time should be integer or null at this point');
        }

        return $cacheTime;
    }
}

    /** * Generate random bytes * * @param int $length * * @return string */
    public static function getBytes($length)
    {
        if ($length <= 0) {
            throw new UnexpectedValueException('Parameter "length" must be a positive integer');
        }

        return random_bytes($length);
    }

    /** * Generate random boolean * * @return bool */
    public static function getBoolean()
    {

    final public const FORMAT = 'jsonapi';

    /** * @return array|mixed */
    public function decode(string $data, string $format, array $context = [])
    {
        $decodedData = (new JsonDecode([JsonDecode::ASSOCIATIVE => true]))->decode($data, 'json');

        if (!\is_array($decodedData) || !\array_key_exists('data', $decodedData)) {
            throw new UnexpectedValueException('Input not a valid JSON:API data object.');
        }

        $includes = [];
        if (\array_key_exists('included', $decodedData)) {
            $includes = $this->resolveIncludes($decodedData['included']);
        }

        if ($this->isCollection($decodedData['data'])) {
            return $this->decodeCollection($decodedData$includes);
        }

        
unset($val);
            }

            $value = Zend_Json::encode($value);
        }

        if (\is_string($value) && \in_array($xType$mediaFields, true) && $this->mediaService->isEncoded($value)) {
            $value = $this->mediaService->normalize($value);
        }

        if (\is_array($value)) {
            throw new UnexpectedValueException(sprintf('Use field value type "%s" if arrays should be saved. Got value type "%s" instead', Field::VALUE_TYPE_JSON, $valueType));
        }

        return $value;
    }

    /** * Fetch all emotions with same category ID and * mark existing emotions with same devices and category */
    private function hasEmotionForSameDeviceType(int $categoryId): bool
    {
        
public function validate(mixed $vatIds, Constraint $constraint): void
    {
        if (!$constraint instanceof CustomerVatIdentification) {
            throw new UnexpectedTypeException($constraint, CustomerVatIdentification::class);
        }

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

        if (!is_iterable($vatIds)) {
            throw new UnexpectedValueException($vatIds, 'iterable');
        }

        if (!$this->shouldCheckVatIdFormat($constraint)) {
            return;
        }

        if (!$vatPattern = $this->getVatPattern($constraint)) {
            return;
        }

        $regex = '/^' . $vatPattern . '$/i';

        
if (isset($record['extra']['file'])) {
            $file = $record['extra']['file'];
            unset($record['extra']['file']);
        }
        if (isset($record['extra']['line'])) {
            $line = $record['extra']['line'];
            unset($record['extra']['line']);
        }

        $record = $this->normalize($record);
        if (!\is_array($record)) {
            throw new UnexpectedValueException('Variable $record must be an array');
        }

        $message = ['message' => $record['message']];
        $handleError = false;
        if ($record['context']) {
            $message['context'] = $record['context'];
            $handleError = true;
        }
        if ($record['extra']) {
            $message['extra'] = $record['extra'];
            $handleError = true;
        }
public function replace($mediaId, UploadedFile $file)
    {
        /** @var Media|null $media */
        $media = $this->modelManager->find(Media::class$mediaId);

        if ($media === null) {
            throw new InvalidArgumentException(sprintf('Media with id %s not found', $mediaId));
        }

        $filePath = $file->getRealPath();
        if (!\is_string($filePath)) {
            throw new UnexpectedValueException(sprintf('Could not get path of file "%s"', $file->getFilename()));
        }

        $uploadedFileExtension = $this->getExtension($file);

        if ($media->getType() !== $this->mappingService->getType($uploadedFileExtension)) {
            throw new WrongMediaTypeForReplaceException($media->getType());
        }

        if ($this->mappingService->isAllowed($uploadedFileExtension) === false) {
            throw new MediaFileExtensionNotAllowedException($uploadedFileExtension);
        }

        

    protected $purchaseSteps = 1;

    public function getMinPurchase(): int
    {
        return $this->minPurchase;
    }

    public function setMinPurchase(int $minPurchase): QuantityInformation
    {
        if ($minPurchase < 1) {
            throw new \UnexpectedValueException('minPurchase must be greater or equal 1');
        }

        $this->minPurchase = $minPurchase;

        return $this;
    }

    public function getMaxPurchase(): ?int
    {
        return $this->maxPurchase;
    }

    
use Shopware\Components\Routing\PreFilterInterface;
use UnexpectedValueException;

class FrontendPreFilter implements PreFilterInterface
{
    /** * {@inheritdoc} */
    public function preFilter($params, Context $context)
    {
        if (!\is_array($params)) {
            throw new UnexpectedValueException('Parameter "params" needs to be an array at this point');
        }

        if (isset($params['sDetails']$params['action']) && $params['action'] === 'detail') {
            $params['sArticle'] = $params['sDetails'];
            unset($params['sDetails']);
        }

        if (isset($params['action'])) {
            $params = array_merge(['action' => null]$params);
        }
        if (isset($params['controller'])) {
            


    /** * {@inheritdoc} */
    public function buildAdditionalText(ListProduct $product, ShopContextInterface $context)
    {
        $products = $this->buildAdditionalTextLists([$product->getNumber() => $product]$context);

        $product = array_shift($products);
        if (!$product instanceof ListProduct) {
            throw new UnexpectedValueException(sprintf('Expect instance of "%s", got "%s" instead', ListProduct::class, \gettype($product)));
        }

        return $product;
    }

    /** * {@inheritdoc} */
    public function buildAdditionalTextLists($products, ShopContextInterface $context)
    {
        $required = [];
        
$allowModifications = false;
        if (\is_bool($options)) {
            $allowModifications = $options;
        } elseif (\is_array($options)) {
            if (isset($options['allowModifications'])) {
                $allowModifications = (bool) $options['allowModifications'];
            }
            if (isset($options['nestSeparator'])) {
                $nestSeparator = (string) $options['nestSeparator'];
                if ($nestSeparator === '') {
                    throw new UnexpectedValueException('nestSeparator must be a non-empty string');
                }
                $this->_nestSeparator = $nestSeparator;
            }
            if (isset($options['skipExtends'])) {
                $this->_skipExtends = (bool) $options['skipExtends'];
            }
        }

        $iniArray = $this->_loadIniFile($filename);

        if ($section === null) {
            

    public function calculateReferencePrice($price$purchaseUnit$referenceUnit)
    {
        $purchaseUnit = (float) $purchaseUnit;
        $referenceUnit = (float) $referenceUnit;

        if (\is_string($price)) {
            $price = (float) str_replace(',', '.', $price);
        } elseif (!\is_float($price)) {
            throw new UnexpectedValueException('Parameter price needs to be of type "float" or a numeric string');
        }

        if ($purchaseUnit === 0.0 || $referenceUnit === 0.0) {
            return 0;
        }

        return $price / $purchaseUnit * $referenceUnit;
    }

    /** * Formats product prices * * @param float $price * * @return string */
private function getUserShippingData(int $userId, array $userData, string $countryQuery): array
    {
        $entityManager = Shopware()->Container()->get(ModelManager::class);

        $customer = $entityManager->find(Customer::class$userId);
        if (!$customer instanceof Customer) {
            throw new \InvalidArgumentException('User with provided id not found');
        }

        $shipping = $this->getShippingAddressData($entityManager$customer);
        if ($shipping === null) {
            throw new \UnexpectedValueException('No shipping address found for user with provided userId');
        }

        $userData['shippingaddress'] = $shipping;

        if (!isset($userData['shippingaddress']['firstname'])) {
            $userData['shippingaddress'] = $userData['billingaddress'];
            $userData['shippingaddress']['eqalBilling'] = true;
        }

        if (empty($userData['shippingaddress']['countryID'])) {
            $targetCountryId = $userData['billingaddress']['countryID'];
        }
return $input;
    }

    public static function getTypeString(ReflectionType $type): string
    {
        // @codeCoverageIgnoreStart         // ReflectionType::__toString was deprecated in 7.4 and undeprecated in 8         // and toString doesn't correctly show the nullable ? in the type before 8         if (!KINT_PHP80) {
            if (!$type instanceof ReflectionNamedType) {
                throw new UnexpectedValueException('ReflectionType on PHP 7 must be ReflectionNamedType');
            }

            $name = $type->getName();
            if ($type->allowsNull() && 'mixed' !== $name && false === \strpos($name, '|')) {
                $name = '?'.$name;
            }

            return $name;
        }
        // @codeCoverageIgnoreEnd
        
Home | Imprint | This part of the site doesn't use cookies.