<commit_before><?php

namespace Rad\Network\Http;

use Rad\Network\Http\Message\ServerRequest;
use Rad\Network\Http\Request\UploadedFile;
use Rad\Network\Http\Message\Uri;
use Rad\Network\Http\Request\ReformatUploadedFiles;

/**
 * Http Request
 *
 * @package Rad\Network\Http
 */
class Request extends ServerRequest
{
    /**
     * Whether or not to trust HTTP_X headers set by most load balancers.
     * Only set to true if your application runs behind load balancers/proxies
     * that you control.
     *
     * @var bool
     */
    public $trustProxy = false;

    /**
     * Rad\Network\Http\Request constructor
     */
    public function __construct()
    {
        parent::__construct(
            $_SERVER,
            $this->prepareUploadedFiles($_FILES),
            $this->prepareUri($_SERVER),
            isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET',
            'php://input',
            $this->prepareHeaders($_SERVER)
        );

        $this->cookieParams = $_COOKIE;
        $this->queryParams = $_GET;
        $this->parsedBody = $this->prepareParsedBody();

        if (isset($this->parsedBody['_method'])) {
            $this->method = strtoupper($this->parsedBody['_method']);
        }
    }

    /**
     * Gets variable from query params.
     * If no parameters are given the $_GET super global is returned
     *
     * @param string $name
     * @param mixed  $defaultValue
     * @param bool   $notAllowEmpty
     *
     * @return mixed
     */
    public function getQuery($name = null, $defaultValue = null, $notAllowEmpty = false)
    {
        if (!is_null($name)) {
            if (isset($this->getQueryParams()[$name])) {
                if (empty($this->getQueryParams()[$name]) && $notAllowEmpty) {
                    return $defaultValue;
                }

                return $this->getQueryParams()[$name];
            }

            return $defaultValue;
        }

        return $this->getQueryParams();
    }

    /**
     * Gets variable from server params
     *
     * @param string $name
     *
     * @return mixed
     */
    public function getServer($name)
    {
        if ($this->hasServer($name)) {
            return $this->getServerParams()[$name];
        }

        return null;
    }

    /**
     * Checks whether $_GET super global has certain index
     *
     * @param string $name
     *
     * @return bool
     */
    public function hasQuery($name)
    {
        return isset($this->getQueryParams()[$name]);
    }

    /**
     * Checks whether $_SERVER super global has certain index
     *
     * @param string $name
     *
     * @return bool
     */
    public function hasServer($name)
    {
        return isset($this->getServerParams()[$name]);
    }

    /**
     * Checks whether request has been made using ajax.
     * Checks if $_SERVER[‘HTTP_X_REQUESTED_WITH’]==’XMLHttpRequest’
     *
     * @return bool
     */
    public function isAjax()
    {
        return ($this->getHeaderLine('X_REQUESTED_WITH') === 'XMLHttpRequest');
    }

    /**
     * Checks whether request has been made using any secure layer
     *
     * @return bool
     */
    public function isSecureRequest()
    {
        return ($this->getUri()->getScheme() === 'https');
    }

    /**
     * Gets active server address IP
     *
     * @return string
     */
    public function getServerAddress()
    {
        if ($this->getServer('SERVER_ADDR')) {
            return $this->getServer('SERVER_ADDR');
        }

        return '127.0.0.1';
    }

    /**
     * Gets active server name
     *
     * @return string
     */
    public function getServerName()
    {
        if ($this->getServer('SERVER_NAME')) {
            return $this->getServer('SERVER_NAME');
        }

        return 'localhost';
    }

    /**
     * Gets most possible client IPv4 Address.
     * This method search in $_SERVER[‘REMOTE_ADDR’] and optionally in $_SERVER[‘HTTP_X_FORWARDED_FOR’]
     *
     * @return string
     */
    public function getClientAddress()
    {
        $address = null;
        if ($this->getHeaderLine('X_FORWARDED_FOR') && $this->trustProxy) {
            $address = $this->getHeaderLine('X_FORWARDED_FOR');
        }

        if (is_null($address) && $this->getServer('REMOTE_ADDR')) {
            $address = $this->getServer('REMOTE_ADDR');
        }

        if (is_string($address)) {
            if ($addresses = explode(',', $address)) {
                return $addresses[0];
            }

            return $address;
        }

        return false;
    }

    /**
     * Gets HTTP user agent used to made the request
     *
     * @return string
     */
    public function getUserAgent()
    {
        return $this->getHeaderLine('USER_AGENT');
    }

    /**
     * Check if HTTP method match any of the passed methods
     *
     * @param string|array $methods
     *
     * @return bool
     */
    public function isMethod($methods)
    {
        if (is_array($methods)) {
            return in_array($this->getMethod(), $methods);
        }

        if (is_string($methods)) {
            return ($this->getMethod() == $methods);
        }

        return false;
    }<commit_msg>remove some useless codes in network<commit_after><?php

namespace Rad\Network\Http;

use Rad\Network\Http\Message\ServerRequest;
use Rad\Network\Http\Request\UploadedFile;
use Rad\Network\Http\Message\Uri;
use Rad\Network\Http\Request\ReformatUploadedFiles;

/**
 * Http Request
 *
 * @package Rad\Network\Http
 */
class Request extends ServerRequest
{
    /**
     * Whether or not to trust HTTP_X headers set by most load balancers.
     * Only set to true if your application runs behind load balancers/proxies
     * that you control.
     *
     * @var bool
     */
    public $trustProxy = false;

    /**
     * Rad\Network\Http\Request constructor
     */
    public function __construct()
    {
        parent::__construct(
            $_SERVER,
            $this->prepareUploadedFiles($_FILES),
            $this->prepareUri($_SERVER),
            isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET',
            'php://input',
            $this->prepareHeaders($_SERVER)
        );

        $this->cookieParams = $_COOKIE;
        $this->queryParams = $_GET;
        $this->parsedBody = $this->prepareParsedBody();

        if (isset($this->parsedBody['_method'])) {
            $this->method = strtoupper($this->parsedBody['_method']);
        }
    }

    /**
     * Gets variable from query params.
     * If no parameters are given the $_GET super global is returned
     *
     * @param string $name
     * @param mixed  $defaultValue
     * @param bool   $notAllowEmpty
     *
     * @return mixed
     */
    public function getQuery($name = null, $defaultValue = null, $notAllowEmpty = false)
    {
        if (!is_null($name)) {
            if (isset($this->getQueryParams()[$name])) {
                if (empty($this->getQueryParams()[$name]) && $notAllowEmpty) {
                    return $defaultValue;
                }

                return $this->getQueryParams()[$name];
            }

            return $defaultValue;
        }

        return $this->getQueryParams();
    }

    /**
     * Gets variable from server params
     *
     * @param string $name
     *
     * @return mixed
     */
    public function getServer($name)
    {
        if ($this->hasServer($name)) {
            return $this->getServerParams()[$name];
        }

        return null;
    }

    /**
     * Checks whether $_GET super global has certain index
     *
     * @param string $name
     *
     * @return bool
     */
    public function hasQuery($name)
    {
        return isset($this->getQueryParams()[$name]);
    }

    /**
     * Checks whether $_SERVER super global has certain index
     *
     * @param string $name
     *
     * @return bool
     */
    public function hasServer($name)
    {
        return isset($this->getServerParams()[$name]);
    }

    /**
     * Checks whether request has been made using ajax.
     * Checks if $_SERVER[‘HTTP_X_REQUESTED_WITH’]==’XMLHttpRequest’
     *
     * @return bool
     */
    public function isAjax()
    {
        return ($this->getHeaderLine('X_REQUESTED_WITH') === 'XMLHttpRequest');
    }

    /**
     * Checks whether request has been made using any secure layer
     *
     * @return bool
     */
    public function isSecureRequest()
    {
        return ($this->getUri()->getScheme() === 'https');
    }

    /**
     * Gets active server address IP
     *
     * @return string
     */
    public function getServerAddress()
    {
        if ($this->getServer('SERVER_ADDR')) {
            return $this->getServer('SERVER_ADDR');
        }

        return '127.0.0.1';
    }

    /**
     * Gets active server name
     *
     * @return string
     */
    public function getServerName()
    {
        if ($this->getServer('SERVER_NAME')) {
            return $this->getServer('SERVER_NAME');
        }

        return 'localhost';
    }

    /**
     * Gets most possible client IPv4 Address.
     * This method search in $_SERVER[‘REMOTE_ADDR’] and optionally in $_SERVER[‘HTTP_X_FORWARDED_FOR’]
     *
     * @return string
     */
    public function getClientAddress()
    {
        $address = null;
        if ($this->getHeaderLine('X_FORWARDED_FOR') && $this->trustProxy) {
            $address = $this->getHeaderLine('X_FORWARDED_FOR');
        }

        if (is_null($address) && $this->getServer('REMOTE_ADDR')) {
            $address = $this->getServer('REMOTE_ADDR');
        }

        if ($address) {
            $addresses = explode(',', $address);
            return $addresses[0];
        }

        return '';
    }

    /**
     * Gets HTTP user agent used to made the request
     *
     * @return string
     */
    public function getUserAgent()
    {
        return $this->getHeaderLine('USER_AGENT');
    }

    /**
     * Check if HTTP method match any of the passed methods
     *
     * @param string|array $methods
     *
     * @return bool
     */
    public function isMethod($methods)
    {
        if (is_array($methods)) {
            return in_array($this->getMethod(), $methods);
        }

        if (is_string($methods)) {
            return ($this->getMethod() == $methods);
        }

        return false;
    }
{'fraction_non_alphanumeric': 0.1314748721906048, 'fraction_numerical': 0.0015433587344458378, 'mean_word_length': 1.9371104815864022, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3659782', 'n_tokens_mistral': 3016, 'n_tokens_neox': 2938, 'n_words': 675}