<commit_before><?php
/**
 * Vision PHP-Framework
 *
 * @author <NAME> <<EMAIL>>
 * @copyright 2012-2014 <NAME>
 * @license http://www.opensource.org/licenses/mit-license.php MIT
 */
namespace Vision\Http;

use Vision\DataStructures\Arrays\Mutator\SquareBracketNotation;

/**
 * Request
 *
 * @author <NAME> <<EMAIL>>
 */
class Request extends AbstractMessage implements RequestInterface
{
    /** @type null|SquareBracketNotation $GET */
    protected $GET;

    /** @type null|SquareBracketNotation $POST */
    protected $POST;

    /** @type null|SquareBracketNotation $FILES */
    protected $FILES;

    /** @type null|SquareBracketNotation $COOKIE */
    protected $COOKIE;

    /** @type null|SquareBracketNotation $SERVER */
    protected $SERVER;

    /** @type null|string $method */
    protected $method;

    /** @type null|string $host */
    protected $host;

    /** @type null|string $basePath */
    protected $basePath;

    /** @type null|string $path */
    protected $path;

    /** @type null|string $pathInfo */
    protected $pathInfo;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->GET = new SquareBracketNotation($_GET);
        $this->POST = new SquareBracketNotation($_POST);
        $this->FILES = new SquareBracketNotation($this->transformFilesArray($_FILES));
        $this->COOKIE = new SquareBracketNotation($_COOKIE);
        $this->SERVER = new SquareBracketNotation($_SERVER);

        // Set $this->method
        if (isset($this->SERVER['REQUEST_METHOD'])) {
            $this->method = strtoupper($this->SERVER['REQUEST_METHOD']);
        }

        $this->initHost()
             ->initBasePath()
             ->initPathInfo()
             ->initPath();
    }

    /**
     * @param string $key
     *
     * @return mixed
     */
    public function __get($key)
    {
        $key = strtoupper($key);

        if (isset($this->$key)) {
            return $this->$key;
        }

        return null;
    }

    /**
     * Check, if the current request method is POST.
     *
     * @api
     *
     * @return bool
     */
    public function isPost()
    {
        return $this->method === 'POST';
    }

    /**
     * Check, if the current request method is GET.
     *
     * @api
     *
     * @return bool
     */
    public function isGet()
    {
        return $this->method === 'GET';
    }

    /**
     * Check, if the current request method is HEAD.
     *
     * @api
     *
     * @return bool
     */
    public function isHead()
    {
        return $this->method === 'HEAD';
    }

    /**
     * Check, if the current request method is PUT.
     *
     * @api
     *
     * @return bool
     */
    public function isPut()
    {
        return $this->method === 'PUT';
    }

    /**
     * Check, if the current request method is DELETE.
     *
     * @api
     *
     * @return bool
     */
    public function isDelete()
    {
        return $this->method === 'DELETE';
    }

    /**
     * @see http://www.php.net/manual/en/reserved.variables.server.php
     *
     * @api
     *
     * @return bool
     */
    public function isSecure()
    {
        return (!empty($this->SERVER['HTTPS']) && $this->SERVER['HTTPS'] !== 'off');
    }

    /**
     * @api
     *
     * @return bool
     */
    public function isAjax()
    {
        return (isset($this->SERVER['HTTP_X_REQUESTED_WITH'])
                && $this->SERVER['HTTP_X_REQUESTED_WITH'] === "XMLHttpRequest");
    }

    /**
     * @api
     *
     * @return string
     */
    public function getScheme()
    {
        if ($this->isSecure()) {
            return 'https';
        }
        return 'http';
    }

    /**
     * @api
     *
     * @return null|string
     */
    public function getHost()
    {
        return $this->host;
    }

    /**
     * @internal
     *<commit_msg>Simplify code<commit_after><?php
/**
 * Vision PHP-Framework
 *
 * @author <NAME> <<EMAIL>>
 * @copyright 2012-2014 <NAME>
 * @license http://www.opensource.org/licenses/mit-license.php MIT
 */
namespace Vision\Http;

use Vision\DataStructures\Arrays\Mutator\SquareBracketNotation;

/**
 * Request
 *
 * @author <NAME> <<EMAIL>>
 */
class Request extends AbstractMessage implements RequestInterface
{
    /** @type null|SquareBracketNotation $GET */
    protected $GET;

    /** @type null|SquareBracketNotation $POST */
    protected $POST;

    /** @type null|SquareBracketNotation $FILES */
    protected $FILES;

    /** @type null|SquareBracketNotation $COOKIE */
    protected $COOKIE;

    /** @type null|SquareBracketNotation $SERVER */
    protected $SERVER;

    /** @type null|string $method */
    protected $method;

    /** @type null|string $host */
    protected $host;

    /** @type null|string $basePath */
    protected $basePath;

    /** @type null|string $path */
    protected $path;

    /** @type null|string $pathInfo */
    protected $pathInfo;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->GET = new SquareBracketNotation($_GET);
        $this->POST = new SquareBracketNotation($_POST);
        $this->FILES = new SquareBracketNotation($this->transformFilesArray($_FILES));
        $this->COOKIE = new SquareBracketNotation($_COOKIE);
        $this->SERVER = new SquareBracketNotation($_SERVER);

        // Set $this->method
        if (isset($this->SERVER['REQUEST_METHOD'])) {
            $this->method = strtoupper($this->SERVER['REQUEST_METHOD']);
        }

        $this->initHost()
             ->initBasePath()
             ->initPathInfo()
             ->initPath();
    }

    /**
     * @param string $key
     *
     * @return mixed
     */
    public function __get($key)
    {
        $key = strtoupper($key);

        if (isset($this->$key)) {
            return $this->$key;
        }

        return null;
    }

    /**
     * Check, if the current request method is POST.
     *
     * @api
     *
     * @return bool
     */
    public function isPost()
    {
        return $this->method === 'POST';
    }

    /**
     * Check, if the current request method is GET.
     *
     * @api
     *
     * @return bool
     */
    public function isGet()
    {
        return $this->method === 'GET';
    }

    /**
     * Check, if the current request method is HEAD.
     *
     * @api
     *
     * @return bool
     */
    public function isHead()
    {
        return $this->method === 'HEAD';
    }

    /**
     * Check, if the current request method is PUT.
     *
     * @api
     *
     * @return bool
     */
    public function isPut()
    {
        return $this->method === 'PUT';
    }

    /**
     * Check, if the current request method is DELETE.
     *
     * @api
     *
     * @return bool
     */
    public function isDelete()
    {
        return $this->method === 'DELETE';
    }

    /**
     * @see http://www.php.net/manual/en/reserved.variables.server.php
     *
     * @api
     *
     * @return bool
     */
    public function isSecure()
    {
        return (!empty($this->SERVER['HTTPS']) && $this->SERVER['HTTPS'] !== 'off');
    }

    /**
     * @api
     *
     * @return bool
     */
    public function isAjax()
    {
        return (isset($this->SERVER['HTTP_X_REQUESTED_WITH'])
                && $this->SERVER['HTTP_X_REQUESTED_WITH'] === "XMLHttpRequest");
    }

    /**
     * @api
     *
     * @return string
     */
    public function getScheme()
    {
        return $this->isSecure() ? 'https' : 'http';
    }

    /**
     * @api
     *
     * @return null|string
     */
    public function getHost()
    {
        return $this->host;
    }

    /**
     * @internal
     *
{'fraction_non_alphanumeric': 0.1526130587775316, 'fraction_numerical': 0.0020852339371823275, 'mean_word_length': 1.8506686478454681, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2332515', 'n_tokens_mistral': 2418, 'n_tokens_neox': 2337, 'n_words': 497}