<commit_before><?php
/**
 * APIResponse Class
 * Helper class for Sending API Responses
 */
class APIResponse {

    /**
     * List of all known HTTP response codes - used to
     * translate numeric codes to messages.
     *
     * @var array
     */
    protected $http_messages = array(
        // Informational 1xx
        100 => 'Continue',
        101 => 'Switching Protocols',

        // Success 2xx
        200 => 'OK',
        201 => 'Created',
        202 => 'Accepted',
        203 => 'Non-Authoritative Information',
        204 => 'No Content',
        205 => 'Reset Content',
        206 => 'Partial Content',

        // Redirection 3xx
        300 => 'Multiple Choices',
        301 => 'Moved Permanently',
        302 => 'Found',  // 1.1
        303 => 'See Other',
        304 => 'Not Modified',
        305 => 'Use Proxy',
        // 306 is deprecated but reserved
        307 => 'Temporary Redirect',

        // Client Error 4xx
        400 => 'Bad Request',
        401 => 'Unauthorized',
        402 => 'Payment Required',
        403 => 'Forbidden',
        404 => 'Not Found',
        405 => 'Method Not Allowed',
        406 => 'Not Acceptable',
        407 => 'Proxy Authentication Required',
        408 => 'Request Timeout',
        409 => 'Conflict',
        410 => 'Gone',
        411 => 'Length Required',
        412 => 'Precondition Failed',
        413 => 'Request Entity Too Large',
        414 => 'Request-URI Too Long',
        415 => 'Unsupported Media Type',
        416 => 'Requested Range Not Satisfiable',
        417 => 'Expectation Failed',

        // Server Error 5xx
        500 => 'Internal Server Error',
        501 => 'Not Implemented',
        502 => 'Bad Gateway',
        503 => 'Service Unavailable',
        504 => 'Gateway Timeout',
        505 => 'HTTP Version Not Supported',
        509 => 'Bandwidth Limit Exceeded'
    );

    /**
     * @var $content_type
     */
    private $content_type = 'application/json; charset=utf-8';

    /**
     * @var $response_code
     */
    private $response_code = 200;

    /**
     * @var $body
     */
    private $body;

    public function __construct() {

    }

    private function send_headers() {
        header('HTTP/1.1 '. $this->response_code .' '. $this->http_messages[$this->response_code], true, $this->response_code);
        header('Content-Type: '.$this->content_type, true, $this->response_code);
    }

    private function send_body() {
        echo json_encode($this->body);
    }

    public function send($body) {
        $this->body = $body;

        // send the headers
        $this->send_headers();

        // send the response body
        $this->send_body();

        // exit the script
        exit;
    }

    public function sendError($message, $code = 404) {
        $this->response_code = $code;

        $this->body = array('error'=>array('code'=>$code, 'message'=>$message));

        // send the headers
        $this->send_headers();

        // send the response body
        $this->send_body();

        // exit the script
        exit;
    }

}<commit_msg>Updated the Response class with a lot of new features<commit_after><?php
/**
 * Response Class
 * Helper class for Sending API Responses
 */
class Response {

    /**
     * List of all known HTTP response codes - used to
     * translate numeric codes to messages.
     *
     * @var array
     */
    protected $http_messages = array(
        // Informational 1xx
        100 => 'Continue',
        101 => 'Switching Protocols',

        // Success 2xx
        200 => 'OK',
        201 => 'Created',
        202 => 'Accepted',
        203 => 'Non-Authoritative Information',
        204 => 'No Content',
        205 => 'Reset Content',
        206 => 'Partial Content',

        // Redirection 3xx
        300 => 'Multiple Choices',
        301 => 'Moved Permanently',
        302 => 'Found',  // 1.1
        303 => 'See Other',
        304 => 'Not Modified',
        305 => 'Use Proxy',
        // 306 is deprecated but reserved
        307 => 'Temporary Redirect',

        // Client Error 4xx
        400 => 'Bad Request',
        401 => 'Unauthorized',
        402 => 'Payment Required',
        403 => 'Forbidden',
        404 => 'Not Found',
        405 => 'Method Not Allowed',
        406 => 'Not Acceptable',
        407 => 'Proxy Authentication Required',
        408 => 'Request Timeout',
        409 => 'Conflict',
        410 => 'Gone',
        411 => 'Length Required',
        412 => 'Precondition Failed',
        413 => 'Request Entity Too Large',
        414 => 'Request-URI Too Long',
        415 => 'Unsupported Media Type',
        416 => 'Requested Range Not Satisfiable',
        417 => 'Expectation Failed',

        // Server Error 5xx
        500 => 'Internal Server Error',
        501 => 'Not Implemented',
        502 => 'Bad Gateway',
        503 => 'Service Unavailable',
        504 => 'Gateway Timeout',
        505 => 'HTTP Version Not Supported',
        509 => 'Bandwidth Limit Exceeded'
    );

    /**
     * @var $content_type
     */
    private $content_type = 'application/json; charset=utf-8';

    /**
     * @var $response_code
     */
    private $response_code = 200;
    
    /**
     * @var $headers
     */
    private $headers = array();
    
    /**
     * @var $headers_sent - boolean
     */
    private $headers_sent = false;
    
    /**
     * @var $error
     */
    private $error;

    /**
     * @var $body
     */
    private $body = array();

    /**
     * Constructor
     */
    public function __construct() {
        $this->addHeader('Content-type: '. $this->content_type);
    }

    /**
     * Add Headers to send
     */
    public function addHeader($header, $replace = true) {
        if (!$headers_sent) {
            // if not already in the array, or if in the array but $replace == false, then we add it to the array
            if (!in_array($header, $this->headers) || (in_array($header, $this->headers) && !$replace)) {
                $this->headers[] = array(
                      'header' => $header
                    , 'replace' => $replace
                );
                return true;
            }
        }
        
        return false;
    }
    
    /**
     * Get an array of headers that are to be sent
     */
    public function getHeaders() {
        return $this->headers;
    }
    
    /**
     * Set the headers to be sent
     */
    private function setHeaders() {
        // set the HTTP/1.1 header
        header('HTTP/1.1 '. $this->response_code .' '. $this->http_messages[$this->response_code], true, $this->response_code);
        
        // set the rest of the headers
        foreach($this->headers as $key => $header) {
            header($header['header'], $header['replace']);
        }
        
        $this->headers_sent = true;
        
        return $this->headers_sent;
    }
    
    /**
     * Set the content type
     */
    public function setContentType($type) {
        if (is_string($type)) {
            $this->$content_type = $type;
            $this->addHeader('Content-type: '. $this->content_type);
        }
        return $this->getContentType();
    }
    
    /**
     * Get Content Type
     */
    public function getContentType() {
        return $this->content_type;
    }
    
    /**
     * Set Error
     */
    public function setError($code, $msg, $details, $http_response_code = false) {
        $this->error = array(
              'code' => $code
            , 'msg' => $msg
            , 'details' => $details
        );
        
        if ($http_resposne_code != false) {
            $this->setResponseCode();
        }
    }
    
    /**
     * Set the HTTP Response Code
     */
    public function setResponseCode($code) {
        if (in_array($code, array_keys($this->http_messages))) {
            $this->response_code = $code
            return $this->getResponseCode();
        }
        return false;
    }
    
    /**
     * Get the HTTP Response Code
     */
    public function getResponseCode() {
        return $this->response_code;
    }

    /**
     * send the body of the response
     */
    private function sendBody() {
        // add the errors to the body of the response
        if (is_array($this->errors)) {
            $this->body['err'] = $this->errors;
        }
        echo json_encode($this->body);
    }

    /**
     * Compose and send the response
     */
    public function send(array $body) {
        $this->body = $body;

        // send the headers
        $this->send_headers();

        // send the response body
        $this->sendBody();

        // exit the script
        exit;
    }
}
{'fraction_non_alphanumeric': 0.1378596087456847, 'fraction_numerical': 0.03256616800920598, 'mean_word_length': 1.6857231149567367, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 139, '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': '733117', 'n_tokens_mistral': 2651, 'n_tokens_neox': 2402, 'n_words': 686}