Cast the value to the attribute's type as specified in the juggable array.

@param mixed  $value
@param string $type

@throws InvalidArgumentException

@return mixed
353810
public function juggle($value, $type)
    {
        // Cast non-null values
        if ( ! is_null($value)) {
            // Ensure that the type is a valid type to cast.
            // We do this check here because it might not have been done
            // as is the case when the model is first initialized.
            if ($this->checkJuggleType($type)) {
                // Get the method that the type maps to
                $method = $this->buildJuggleMethod($type);

                // Cast the value to the type using the method
                $value = $this->{$method}($value);
            }
        }

        return $value;
    }
1365055
protected function serializeType($value, $type)
    {
        return $this->connection->convertToDatabaseValue(
            $value,
            TypeMapper::getDoctrineTypeByType($type)
        );
    }
979182
public function withAttribute($name, $value){
        if(!is_string($name)){
            throw new \InvalidArgumentException(
                "First argument must be of the type string, " . gettype($name) . " given."
            );
        }

        if(
            array_key_exists($name, $this->attributes)
            && $this->attributes[$name] === $value
        ){
            return $this;
        }

        $clone                      = clone $this;
        $clone->attributes[$name]   = $value;

        return $clone;
    }
1046676
public static function castFrom($value): InputStream
    {
        if ($value instanceof InputStream) {
            return $value;
        }

        if (is_string($value)) {
            return new self($value);
        }

        throw new \InvalidArgumentException(
                'Given value is neither an instance of' . InputStream::class
                . ' nor a string denoting a file'
        );
    }
564333
private function objectParam($value)
    {
        if ($value instanceof \stdClass) {
            throw new \InvalidArgumentException(
                'Values of type `\stdClass` are interpreted as structs and must define their types.'
            );
        }

        if ($value instanceof ValueInterface) {
            return [
                $this->typeObject($value->type()),
                $value->formatAsString()
            ];
        }

        if ($value instanceof Int64) {
            return [
                $this->typeObject(self::TYPE_INT64),
                $value->get()
            ];
        }

        throw new \InvalidArgumentException(sprintf(
            'Unrecognized value type %s. ' .
            'Please ensure you are using the latest version of google/cloud or google/cloud-spanner.',
            get_class($value)
        ));
    }
316061
public function normalizeValue($value)
	{
		if ($value instanceof AttributeFilter)
		{
			return $value;
		}

		if (is_callable($value))
		{
			return new AttributeFilter($value);
		}

		throw new InvalidArgumentException('Argument 1 passed to ' . __METHOD__ . ' must be a valid callback or an instance of s9e\\TextFormatter\\Configurator\\Items\\AttributeFilter');
	}
670632
public function setAsFloat($value)
    {
        if (!(is_numeric($value) || $value instanceof NumericTypeInterface)) {
            throw new \InvalidArgumentException('value is not numeric');
        }
        $val = is_object($value) ? $value->asFloatType()->get() : floatval($value);
        $intVal = pow(10, $this->precision->get()) * $val;
        parent::set($intVal);

        return $this;
    }
139565
public function setValue($value)
    {
        if (null !== $value) {
            if (!$this->validateValue($value)) {
                throw new \InvalidArgumentException(\sprintf(
                    'Binding invalid value (type "%s") into filter "%s" (%s)',
                    \is_object($value) ? \get_class($value) : \gettype($value),
                    $this->name,
                    \get_class($this)
                ));
            }

            $this->value = $value;
            $this->updateBound();
        }

        return $this;
    }
103100
protected function toPhpType($value, $type)
    {
        switch ($type) {
            case 'int':
                return (int) $value;

            case 'string':
                return (string) $value;

            case 'datetime':
                return $value === '0000-00-00 00:00:00' ? '' : $value;

            case 'date':
                return $value === '0000-00-00' ? '' : $value;

            case 'bool':
                return (bool) $value;

            case 'array':
            case 'json':
                // Ignore default array value
                return is_array($value) ? $value : $this->cacheJsonDecode($value, true);

            case 'float':
                return (float) $value;

            default:
                throw new InvalidArgumentException('Unsupported cast type: ' . $type);
        }
    }
345274
protected function process($value, string $type)
    {
        if ($type === 'integer') {
            return (int) $value;
        }

        if ($type === 'float') {
            return (float) $value;
        }

        if ($type === 'boolean') {
            return (bool) $value;
        }

        return (string) $value;
    }
295695
public function marshal($value)
    {
        if ($this->options()->allowed && !in_array($value, $this->options()->allowed)) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Allowed values for this field are %s.',
                    implode(', ', $this->options()->allowed)
                )
            );
        }
        return new TypedValue((string) $value);
    }
415594
private function convertValue($value, $type){

        switch($type){
            case "is_numeric":
                $value = floatval($value);
                break;
            case "is_float":
                $value = floatval($value);
                break;
            case "is_string":
                $value = strval($value);
                break;
            default:
                $value = strval($value);
        }

        return $value;
    }
281966
private function structParam($value, StructType $type)
    {
        if (!($value instanceof StructValue) && !is_array($value) && $value !== null) {
            throw new \InvalidArgumentException(
                'Struct value must be an array an instance of `Google\Cloud\Spanner\StructValue` or null.'
            );
        }

        $typeFields = $type->fields();

        // iterate through types and values separately to accurately align
        // unnamed and fields with duplicate names.
        // We also record the original position in order to return values in
        // the order given.
        $values = [];
        if (is_array($value)) {
            $idx = 0;
            foreach ($value as $name => $val) {
                if (!isset($values[$name])) {
                    $values[$name] = [];
                }

                // Nest values inside an array keyed by field name.
                // This allows for duplicate field names, and aligning
                // definitions by position.
                $values[$name][] = [
                    'index' => $idx,
                    'value' => $val
                ];

                $idx++;
            }
        } elseif ($value instanceof StructValue) {
            foreach ($value->values() as $idx => $val) {
                $name = $val['name'];
                $valValue = $val['value'];

                if (!isset($values[$name])) {
                    $values[$name] = [];
                }

                $values[$name][] = [
                    'index' => $idx,
                    'value' => $valValue
                ];
            }
        }

        // Iterate through given type fields and align them with corresponding values.
        $res = [];
        $fields = [];
        $names = [];
        foreach ($typeFields as $typeIndex => $paramType) {
            $fieldName = $paramType['name'];

            // Count the number of times the field name has been encountered thus far.
            // This lets us pick the correct index for duplicate fields.
            if (isset($names[$fieldName])) {
                $names[$fieldName]++;
            } else {
                $names[$fieldName] = 0;
            }

            // Get the value which corresponds to the current type.
            $index = $names[$fieldName];
            $paramValue = isset($values[$fieldName][$index])
                ? $values[$fieldName][$index]
                : null;

            // If the value didn't exist in the values structure, set it to null.
            // The $typeIndex will give us a hook to order fields properly.
            // Otherwise, remove the current field value from the list of values.
            if ($paramValue === null) {
                $paramValue = ['value' => null, 'index' => $typeIndex];
            } else {
                unset($values[$fieldName][$index]);
            }

            $param = $this->paramType($paramValue['value'], $paramType['type'], $paramType['child']);

            $fields[$paramValue['index']] = array_filter([
                'name' => $fieldName,
                'type' => $param[1]
            ]);

            $res[$paramValue['index']] = $param[0];
        }

        // Iterate over any remaining fields. If anything is left here, it means
        // no type was defined and its type must be inferred.
        foreach ($values as $name => $list) {
            foreach ($list as $value) {
                $index = $value['index'];
                $val = $value['value'];

                $type = null;
                $def = null;
                if (is_array($val) && !$this->isAssoc($val)) {
                    $type = Database::TYPE_ARRAY;
                    $def = new ArrayType(null);
                }

                $param = $this->paramType($val, $type, $def);

                $fields[$index] = array_filter([
                    'name' => $name,
                    'type' => $param[1]
                ]);

                $res[$index] = $param[0];
            }
        }

        // Sort values and fields by key to reset back to the order given by the user.
        ksort($res);
        ksort($fields);

        $type = [
            'code' => self::TYPE_STRUCT,
            'structType' => [
                'fields' => $fields
            ]
        ];

        // If the input is null, send null (but with the full type structure)
        $res = $value === null ? null : $res;

        return [
            $res,
            $type
        ];
    }
50557
private function castTo($value, $type) {
	
		switch ($type) {
	
			default:
				$value = (string)$value;
				break;
				
			case 'int':
				$value = (int)$value;
				break;
				
			case 'bool':
				$value = (bool)$value;
				break;
				
			case 'password':
				if ($this->isCryptAvailable()) {
					$value = openssl_decrypt($value, 'AES128', OPTIONS_CRYPT_KEY);
				} else {
					$app = Application::getInstance();
					$app->logWarning('OPTIONS_CRYPT_KEY constant should be defined into config.php file.');
				}
				break;
				
			case 'list':
				break;
				
		}
		
		return $value;
	
	}
544855
public function setAttribute($key, $value)
    {
        if (array_key_exists($key, static::$attributeTypeMapping)) {
            $type = strtolower(static::$attributeTypeMapping[$key]);
            switch ($type) {
                case 'boolean':
                case 'bool':
                    $value = (bool) filter_var($value, FILTER_VALIDATE_BOOLEAN);
                    break;
                case 'integer':
                case 'int':
                    $value = (int) $value;
                    break;
                case 'float':
                    $value = (float) $value;
                    break;
                case 'string':
                default:
                    $value = (string) $value;
                    break;
            }

            $this->attributes[$key] = $value;
        } else {
            throw new \InvalidArgumentException("Unexpected attribute '$key'.");
        }

        return $this;
    }
882876
public static function fromValue($value)
    {
        $values = static::getValues();
        if (array_key_exists($value, $values)) {
            return new static($values[$value], $value);
        }
        throw new \InvalidArgumentException("No enum constant value '$value' class " . get_called_class());
    }
354817
public function toObject($value)
    {
        if (!is_array($value)) {
            throw new TypeCastException('Is not array');
        }

        foreach ($this->rules as $class => $rule) {
            if ($this->isMatch($rule, $value)) {
                return $this->createInstance($class, $value);
            }
        }

        throw new TypeCastException('Rule not found');
    }