<commit_before><?php

namespace HtaccessFirewall\Host;

use HtaccessFirewall\Host\Exception\InvalidArgumentException;

class IP implements Host
{
    /**
     * @var string
     */
    private $value;

    /**
     * Initialize IP.
     *
     * @param $value
     *
     * @throws InvalidArgumentException
     */
    private function __construct($value)
    {
        if (!self::isValid($value)) {
            throw new InvalidArgumentException('The first parameter of IP must be a valid IP address.');
        }

        $this->value = $value;
    }

    /**
     * Create IP from string.
     *
     * @param $string
     *
     * @return IP
     */
    public static function fromString($string)
    {
        return new self($string);
    }

    /**
     * Create IP from current request.
     *
     * @return IP
     */
    public static function fromCurrentRequest()
    {
        return new self($_SERVER['REMOTE_ADDR']);
    }

    /**
     * Check if string is a valid IP.
     *
     * @param string $value
     *
     * @return bool
     */
    public static function isValid($value)
    {
        return filter_var($value, FILTER_VALIDATE_IP) !== false;
    }

    /**
     * Compare equality with another Host.
     *
     * @param Host $other
     *
     * @return bool
     */
    public function equals(Host $other)
    {
        return $this->toString() === $other->toString();
    }

    /**
     * Get string representation of IP.
     *
     * @return string
     */
    public function toString()
    {
        return $this->value;
    }

    /**
     * Cast IP to string.
     *
     * @return string<commit_msg>Change naming<commit_after><?php

namespace HtaccessFirewall\Host;

use HtaccessFirewall\Host\Exception\InvalidArgumentException;

class IP implements Host
{
    /**
     * @var string
     */
    private $value;

    /**
     * Initialize IP.
     *
     * @param $value
     *
     * @throws InvalidArgumentException
     */
    private function __construct($value)
    {
        if (!self::validate($value)) {
            throw new InvalidArgumentException('The first parameter of IP must be a valid IP address.');
        }

        $this->value = $value;
    }

    /**
     * Create IP from string.
     *
     * @param $string
     *
     * @return IP
     */
    public static function fromString($string)
    {
        return new self($string);
    }

    /**
     * Create IP from current request.
     *
     * @return IP
     */
    public static function fromCurrentRequest()
    {
        return new self($_SERVER['REMOTE_ADDR']);
    }

    /**
     * Check if string is a valid IP.
     *
     * @param string $value
     *
     * @return bool
     */
    public static function validate($value)
    {
        return filter_var($value, FILTER_VALIDATE_IP) !== false;
    }

    /**
     * Compare equality with another Host.
     *
     * @param Host $other
     *
     * @return bool
     */
    public function equals(Host $other)
    {
        return $this->toString() === $other->toString();
    }

    /**
     * Get string representation of IP.
     *
     * @return string
     */
    public function toString()
    {
        return $this->value;
    }

    /**
     * Cast IP to string.
     *
     * @return string
{'fraction_non_alphanumeric': 0.11782661782661782, 'fraction_numerical': 0.0, 'mean_word_length': 1.7445561139028476, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '5346999', 'n_tokens_mistral': 958, 'n_tokens_neox': 933, 'n_words': 246}