public function coerce(Parameter $parameter, $value)
    {
        $schema = $parameter->getSchema();

        switch ($schema->getType()) {
            case Schema::TYPE_STRING:
                return (string)$value;
            case Schema::TYPE_BOOL:
                if (!is_scalar($value)) {
                    return $value;
                }
                $bool = $this->coerceBooleanValue($value);

                return $bool === null ? $value : $bool;
            case Schema::TYPE_NUMBER:
                if (!is_numeric($value)) {
                    return $value;
                }

                return ctype_digit($value) ? (int)$value : (float)$value;
            case Schema::TYPE_OBJECT:
                if (!is_array($value)) {
                    return $value == '' ? null : $value;
                }
                if (count($value) && is_numeric(key($value))) {
                    return $value;
                }

                return (object)$value;
            case Schema::TYPE_ARRAY:
                if (is_array($value) || !is_string($value)) {
                    return $value;
                }

                return $this->coerceArrayValue(
                    $parameter->getCollectionFormat() ? $parameter->getCollectionFormat() : 'csv',
                    $value
                );
            case Schema::TYPE_INT:
                if (!ctype_digit($value)) {
                    return $value;
                }

                return (integer)$value;
            case Schema::TYPE_NULL:
                if ($value !== '') {
                    return $value;
                }

                return null;
            default:
                return $value;
        }
    }
public function coerce(Parameter $parameter, $value)
    {
        $schema = $parameter->getSchema();

        switch ($schema->getType()) {
            case Schema::TYPE_STRING:
                return (string)$value;
            case Schema::TYPE_BOOL:
                if (!is_scalar($value)) {
                    return $value;
                }
                $bool = $this->coerceBooleanValue($value);

                return $bool === null ? $value : $bool;
            case Schema::TYPE_NUMBER:
                if (!is_numeric($value)) {
                    return $value;
                }

                return ctype_digit($value) ? (int)$value : (float)$value;
            case Schema::TYPE_OBJECT:
                if (!is_array($value)) {
                    return $value == '' ? null : $value;
                }
                if (count($value) && is_numeric(key($value))) {
                    return $value;
                }

                return (object)$value;
            case Schema::TYPE_ARRAY:
                if (is_array($value) || !is_string($value)) {
                    return $value;
                }

                return $this->coerceArrayValue(
                    $parameter->getCollectionFormat() ? $parameter->getCollectionFormat() : 'csv',
                    $value
                );
            case Schema::TYPE_INT:
                if (!ctype_digit($value)) {
                    return $value;
                }

                return (integer)$value;
            case Schema::TYPE_NULL:
                if ($value !== '') {
                    return $value;
                }

                return null;
            default:
                return $value;
        }
    }
public function coerce ( Parameter $ parameter , $ value ) { $ schema = $ parameter -> getSchema ( ) ; switch ( $ schema -> getType ( ) ) { case Schema :: TYPE_STRING : return ( string ) $ value ; case Schema :: TYPE_BOOL : if ( ! is_scalar ( $ value ) ) { return $ value ; } $ bool = $ this -> coerceBooleanValue ( $ value ) ; return $ bool === null ? $ value : $ bool ; case Schema :: TYPE_NUMBER : if ( ! is_numeric ( $ value ) ) { return $ value ; } return ctype_digit ( $ value ) ? ( int ) $ value : ( float ) $ value ; case Schema :: TYPE_OBJECT : if ( ! is_array ( $ value ) ) { return $ value == '' ? null : $ value ; } if ( count ( $ value ) && is_numeric ( key ( $ value ) ) ) { return $ value ; } return ( object ) $ value ; case Schema :: TYPE_ARRAY : if ( is_array ( $ value ) || ! is_string ( $ value ) ) { return $ value ; } return $ this -> coerceArrayValue ( $ parameter -> getCollectionFormat ( ) ? $ parameter -> getCollectionFormat ( ) : 'csv' , $ value ) ; case Schema :: TYPE_INT : if ( ! ctype_digit ( $ value ) ) { return $ value ; } return ( integer ) $ value ; case Schema :: TYPE_NULL : if ( $ value !== '' ) { return $ value ; } return null ; default : return $ value ; } }
Try to coerce a value into its defined type.

If coersion is not possible, will return the original value, to be picked up by validation.

@SuppressWarnings(PHPMD.CyclomaticComplexity)

@param Parameter $parameter
@param mixed     $value

@return mixed
Try to coerce a value into its defined type .