<commit_before><?php

namespace VMware\VCloud\Ip;

use \VMware\VCloud\Object as Object;
use \VMware\VCloud\Exception as Exception;

class Address extends Object
{
    protected $address;

    public function __construct($address)
    {
        // Check parameter
        if (gettype($address) !== 'string' && gettype($address) !== 'integer' && gettype($address) !== 'double') {
            throw new Exception\InvalidParameter($address, array('string', 'integer', 'double'));
        }

        // If the $address is a number, consider it as the IP Address number representation
        if (preg_match('/^-?[0-9]+$/', $address)) {

            $this->set('address', intval($address));

            if ($this->getAddress() < -2147483648 || $this->getAddress() > 2147483647) {
                throw new Exception\IpOutOfRange('IP address ' + $this + ' is invalid (' . $address . ')');
            }

        } else { // Otherwise, parse it as a string

            // Retrieve the different part
            $ip = null;
            preg_match('/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/', $address, $ip);
            if (!$ip || $ip[1] > 255 || $ip[2] > 255 || $ip[3] > 255 || $ip[4] > 255) {
                throw new Exception\IpOutOfRange('IP address ' + $address + ' is invalid');
            }

            // Calculate the IP address number
            $this->set('address', (+$ip[1]<<24) + (+$ip[2]<<16) + (+$ip[3]<<8) + (+$ip[4]));
        }
    }

    public function getAddress()
    {
        return $this->get('address');
    }

    public function __toString()
    {
        return  (($this->getAddress() >> 24) & 255)
            . '.' . (($this->getAddress() >> 16) & 255)
            . '.' . (($this->getAddress() >> 8 ) & 255)
            . '.' . (($this->getAddress() >> 0 ) & 255);
    }

    public function getNext()
    {
        if ($this->getAddress() === 2147483647) { // 0111..111 => 1000..000
            return new self(-2147483648);
        }

        if ($this->getAddress() === -1) { // 255.255.255.255
            throw new Exception\IpOutOfRange('IP address 255.255.255.255 has no next address');
        }

        return new self($this->getAddress() + 1);
    }

    public function getPrevious()
    {
        if ($this->getAddress() === -2147483648) { // 1000..000 => 0111..111
            return new self(2147483647);
        }

        if ($this->getAddress() === 0) { // 0.0.0.0
            throw new Exception\IpOutOfRange('IP address 0.0.0.0 has no previous address');
        }

        return new self($this->getAddress() - 1);
    }
}
<commit_msg>Updated type checking<commit_after><?php

namespace VMware\VCloud\Ip;

use \VMware\VCloud\Object as Object;
use \VMware\VCloud\Exception as Exception;

class Address extends Object
{
    protected $address;

    public function __construct($address)
    {
        // Check parameter
        if (!is_integer($address) && !is_float($address) && !is_string($address)) {
            throw new Exception\InvalidParameter($address, array('string', 'integer', 'double'));
        }

        // If the $address is a number, consider it as the IP Address number representation
        if (is_integer($address) || is_float($address) || is_string($address) && preg_match('/^-?[0-9]+$/', $address)) {

            $this->set('address', intval($address));

            if ($this->getAddress() < -2147483648 || $this->getAddress() > 2147483647) {
                throw new Exception\IpOutOfRange('IP address ' + $this + ' is invalid (' . $address . ')');
            }

        } else { // Otherwise, parse it as a string

            // Retrieve the different part
            $ip = null;
            preg_match('/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/', $address, $ip);
            if (!$ip || $ip[1] > 255 || $ip[2] > 255 || $ip[3] > 255 || $ip[4] > 255) {
                throw new Exception\IpOutOfRange('IP address ' + $address + ' is invalid');
            }

            // Calculate the IP address number
            $this->set('address', (+$ip[1]<<24) + (+$ip[2]<<16) + (+$ip[3]<<8) + (+$ip[4]));
        }
    }

    public function getAddress()
    {
        return $this->get('address');
    }

    public function __toString()
    {
        return  (($this->getAddress() >> 24) & 255)
            . '.' . (($this->getAddress() >> 16) & 255)
            . '.' . (($this->getAddress() >> 8 ) & 255)
            . '.' . (($this->getAddress() >> 0 ) & 255);
    }

    public function getNext()
    {
        if ($this->getAddress() === 2147483647) { // 0111..111 => 1000..000
            return new self(-2147483648);
        }

        if ($this->getAddress() === -1) { // 255.255.255.255
            throw new Exception\IpOutOfRange('IP address 255.255.255.255 has no next address');
        }

        return new self($this->getAddress() + 1);
    }

    public function getPrevious()
    {
        if ($this->getAddress() === -2147483648) { // 1000..000 => 0111..111
            return new self(2147483647);
        }

        if ($this->getAddress() === 0) { // 0.0.0.0
            throw new Exception\IpOutOfRange('IP address 0.0.0.0 has no previous address');
        }

        return new self($this->getAddress() - 1);
    }
}

{'fraction_non_alphanumeric': 0.18704344482891197, 'fraction_numerical': 0.06497500961168781, 'mean_word_length': 1.9988472622478386, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, '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': '3496287', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1595, 'n_words': 376}