<commit_before><?php

use Symfony\Component\HttpFoundation\AcceptHeader;

if ( ! function_exists('jsonapi_request')) {
    /**
     * Returns JSON-API request instance.
     *
     * This may be used as `request()` would, but adds JSON-API related information.
     *
     * @return \Czim\JsonApi\Http\Requests\JsonApiRequest
     */
    function jsonapi_request()
    {
        return app(\Czim\JsonApi\Http\Requests\JsonApiRequest::class);
    }
}

if ( ! function_exists('jsonapi_request_create')) {
    /**
     * Returns JSON-API request instance for create request.
     *
     * This may be used as `request()` would, but adds JSON-API related information.
     *
     * @return \Czim\JsonApi\Http\Requests\JsonApiCreateRequest
     */
    function jsonapi_request_create()
    {
        return app(\Czim\JsonApi\Http\Requests\JsonApiCreateRequest::class);
    }
}

if ( ! function_exists('jsonapi_query')) {
    /**
     * Returns JSON-API request query parser.
     *
     * @return \Czim\JsonApi\Support\Request\RequestQueryParser
     */
    function jsonapi_query()
    {
        return app(\Czim\JsonApi\Support\Request\RequestQueryParser::class);
    }
}

if ( ! function_exists('jsonapi_response')) {
    /**
     * Casts a given array as a JSON-API response.
     *
     * @param  mixed  $data
     * @param  int    $status
     * @param  array  $headers
     * @param  int    $options
     * @return \Czim\JsonApi\Http\Responses\JsonApiResponse
     */
    function jsonapi_response($data = null, $status = 200, $headers = [], $options = 0)
    {
        return new \Czim\JsonApi\Http\Responses\JsonApiResponse($data, $status, $headers, $options);
    }
}

if ( ! function_exists('jsonapi_encode')) {
    /**
     * Encodes a JSON-API array with a fresh encoder instance.
     *
     * @param  mixed $data
     * @param  array  $includes
     * @return array
     */
    function jsonapi_encode($data, array $includes = null)
    {
        /** @var \Czim\JsonApi\Contracts\Encoder\EncoderInterface $encoder */
        $encoder = app(\Czim\JsonApi\Contracts\Encoder\EncoderInterface::class);

        return $encoder->encode($data, $includes);
    }
}

if ( ! function_exists('jsonapi_error')) {
    /**
     * Makes a JSON-API response instance for an error or exception.
     *
     * @param  mixed $data
     * @return \Czim\JsonApi\Http\Responses\JsonApiResponse
     */
    function jsonapi_error($data)
    {
        $encoded = jsonapi_encode($data);

        $status = (int) array_get($encoded, 'error.status', 500);

        return jsonapi_response($encoded, $status);
    }
}

if ( ! function_exists('is_jsonapi_request')) {
    /**
     * Returns whether the current request is JSON-API.
     *
     * @return bool
     */
    function is_jsonapi_request()
    {
        $acceptHeader = AcceptHeader::fromString(request()->header('accept'));

        return $acceptHeader->has('application/vnd.api+json');
    }
}<commit_msg>Fixed incorrect status code for errors response<commit_after><?php

use Symfony\Component\HttpFoundation\AcceptHeader;

if ( ! function_exists('jsonapi_request')) {
    /**
     * Returns JSON-API request instance.
     *
     * This may be used as `request()` would, but adds JSON-API related information.
     *
     * @return \Czim\JsonApi\Http\Requests\JsonApiRequest
     */
    function jsonapi_request()
    {
        return app(\Czim\JsonApi\Http\Requests\JsonApiRequest::class);
    }
}

if ( ! function_exists('jsonapi_request_create')) {
    /**
     * Returns JSON-API request instance for create request.
     *
     * This may be used as `request()` would, but adds JSON-API related information.
     *
     * @return \Czim\JsonApi\Http\Requests\JsonApiCreateRequest
     */
    function jsonapi_request_create()
    {
        return app(\Czim\JsonApi\Http\Requests\JsonApiCreateRequest::class);
    }
}

if ( ! function_exists('jsonapi_query')) {
    /**
     * Returns JSON-API request query parser.
     *
     * @return \Czim\JsonApi\Support\Request\RequestQueryParser
     */
    function jsonapi_query()
    {
        return app(\Czim\JsonApi\Support\Request\RequestQueryParser::class);
    }
}

if ( ! function_exists('jsonapi_response')) {
    /**
     * Casts a given array as a JSON-API response.
     *
     * @param  mixed  $data
     * @param  int    $status
     * @param  array  $headers
     * @param  int    $options
     * @return \Czim\JsonApi\Http\Responses\JsonApiResponse
     */
    function jsonapi_response($data = null, $status = 200, $headers = [], $options = 0)
    {
        return new \Czim\JsonApi\Http\Responses\JsonApiResponse($data, $status, $headers, $options);
    }
}

if ( ! function_exists('jsonapi_encode')) {
    /**
     * Encodes a JSON-API array with a fresh encoder instance.
     *
     * @param  mixed $data
     * @param  array  $includes
     * @return array
     */
    function jsonapi_encode($data, array $includes = null)
    {
        /** @var \Czim\JsonApi\Contracts\Encoder\EncoderInterface $encoder */
        $encoder = app(\Czim\JsonApi\Contracts\Encoder\EncoderInterface::class);

        return $encoder->encode($data, $includes);
    }
}

if ( ! function_exists('jsonapi_error')) {
    /**
     * Makes a JSON-API response instance for an error or exception.
     *
     * @param  mixed $data
     * @return \Czim\JsonApi\Http\Responses\JsonApiResponse
     */
    function jsonapi_error($data)
    {
        $encoded = jsonapi_encode($data);

        $status = (int) array_get($encoded, 'errors.0.status', 500);

        return jsonapi_response($encoded, $status);
    }
}

if ( ! function_exists('is_jsonapi_request')) {
    /**
     * Returns whether the current request is JSON-API.
     *
     * @return bool
     */
    function is_jsonapi_request()
    {
        $acceptHeader = AcceptHeader::fromString(request()->header('accept'));

        return $acceptHeader->has('application/vnd.api+json');
    }
}
{'fraction_non_alphanumeric': 0.13083010607846438, 'fraction_numerical': 0.0025256777235224785, 'mean_word_length': 2.644171779141104, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1842838', 'n_tokens_mistral': 1855, 'n_tokens_neox': 1831, 'n_words': 372}