/**
  * {@inheritdoc}
  */
 protected function checkValue($field, $value, $locale, $scope)
 {
     if (!is_numeric($value)) {
         throw InvalidArgumentException::numericExpected($field, 'filter', 'completeness', gettype($value));
     }
     if (null === $scope) {
         throw new InvalidArgumentException('Scope expected for completeness filter. None given.');
     }
 }
 /**
  * Check if value is valid
  *
  * @param string      $field
  * @param mixed       $value
  * @param string|null $locale
  * @param string|null $scope
  */
 protected function checkValue($field, $value, $locale, $scope)
 {
     if (!is_numeric($value)) {
         throw InvalidArgumentException::numericExpected($field, 'filter', 'completeness', gettype($value));
     }
     if (null === $locale || null === $scope) {
         throw InvalidArgumentException::localeAndScopeExpected($field, 'filter', 'completeness');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'number');
     if (!is_numeric($value) && null !== $value) {
         throw InvalidArgumentException::numericExpected($attribute->getCode(), 'filter', 'number', gettype($value));
     }
     $field = ProductQueryUtility::getNormalizedValueFieldFromAttribute($attribute, $locale, $scope);
     $field = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, $field);
     $this->applyFilter($operator, $value, $field);
     return $this;
 }
 /**
  * Check if value is a valid identifier
  *
  * @param string $field
  * @param mixed  $value
  * @param string $filter
  */
 public static function checkIdentifier($field, $value, $filter)
 {
     $invalidIdField = static::hasProperty($field) && static::getProperty($field) === 'id' && !is_numeric($value);
     $invalidDefaultField = !static::hasProperty($field) && !is_numeric($value);
     if ($invalidIdField || $invalidDefaultField) {
         throw InvalidArgumentException::numericExpected(static::getCode($field), 'filter', $filter, gettype($value));
     }
     $invalidStringField = static::hasProperty($field) && static::getProperty($field) !== 'id' && !is_string($value);
     if ($invalidStringField) {
         throw InvalidArgumentException::stringExpected(static::getCode($field), 'filter', $filter, gettype($value));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function setValue(array $products, AttributeInterface $attribute, $data, $locale = null, $scope = null)
 {
     if (null === $this->productBuilder) {
         throw new \RuntimeException('The product builder should be set.');
     }
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'number');
     if (!is_numeric($data) && null !== $data) {
         throw InvalidArgumentException::numericExpected($attribute->getCode(), 'setter', 'number', gettype($data));
     }
     foreach ($products as $product) {
         $this->setData($attribute, $product, $data, $locale, $scope);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'number');
     if (!is_numeric($value) && null !== $value) {
         throw InvalidArgumentException::numericExpected($attribute->getCode(), 'filter', 'number', gettype($value));
     }
     $joinAlias = $this->getUniqueAlias('filter' . $attribute->getCode());
     $backendField = sprintf('%s.%s', $joinAlias, $attribute->getBackendType());
     if ($operator === Operators::IS_EMPTY) {
         $this->qb->leftJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope));
         $this->qb->andWhere($this->prepareCriteriaCondition($backendField, $operator, $value));
     } else {
         $condition = $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope);
         $condition .= ' AND ' . $this->prepareCriteriaCondition($backendField, $operator, $value);
         $this->qb->innerJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $condition);
     }
     return $this;
 }
 function it_throws_an_exception_if_the_content_of_value_are_not_numeric(AttributeInterface $attribute)
 {
     $attribute->getCode()->willReturn('options_code');
     $this->shouldThrow(InvalidArgumentException::numericExpected('options_code', 'filter', 'options', gettype('WRONG')))->during('addAttributeFilter', [$attribute, 'IN', [123, 'not numeric'], null, null, ['field' => 'options_code.id']]);
 }
 function it_throws_an_exception_if_value_is_not_a_valid_array(AttributeInterface $attribute)
 {
     $attribute->getId()->willReturn(1);
     $attribute->getCode()->willReturn('color');
     $value = 'string';
     $this->shouldThrow(InvalidArgumentException::arrayExpected('color', 'filter', 'reference_data', $value))->during('addAttributeFilter', [$attribute, '=', $value, null, null, ['field' => 'color']]);
     $value = ['foo'];
     $this->shouldThrow(InvalidArgumentException::numericExpected('color', 'filter', 'reference_data', 'string'))->during('addAttributeFilter', [$attribute, '=', $value, null, null, ['field' => 'color']]);
 }
 function it_throws_an_exception_if_value_is_not_an_integer()
 {
     $this->shouldThrow(InvalidArgumentException::numericExpected('completeness', 'filter', 'completeness', gettype('123')))->during('addFieldFilter', ['completeness', '=', '12a3', 'fr_FR', 'mobile']);
 }
 function it_throws_an_exception_if_content_of_array_is_not_integer_or_empty()
 {
     $this->shouldThrow(InvalidArgumentException::numericExpected('family', 'filter', 'family', gettype('WRONG')))->during('addFieldFilter', ['family', 'IN', [1, 2, 'WRONG']]);
 }
 function it_throws_an_error_if_data_is_not_a_number_or_null(AttributeInterface $attribute)
 {
     $attribute->getCode()->willReturn('attributeCode');
     $data = 'not a number';
     $this->shouldThrow(InvalidArgumentException::numericExpected('attributeCode', 'setter', 'number', gettype($data)))->during('setValue', [[], $attribute, $data, 'fr_FR', 'mobile']);
 }
 function it_throws_an_exception_if_value_is_not_a_numeric(AttributeInterface $attribute)
 {
     $attribute->getCode()->willReturn('number_code');
     $this->shouldThrow(InvalidArgumentException::numericExpected('number_code', 'filter', 'number', gettype('WRONG')))->during('addAttributeFilter', [$attribute, '=', 'WRONG']);
 }