Page MenuHomeDevCentral

No OneTemporary

diff --git a/src/Network/IPv4Range.php b/src/Network/IPv4Range.php
index 0a8d6f0..ae2b674 100644
--- a/src/Network/IPv4Range.php
+++ b/src/Network/IPv4Range.php
@@ -1,107 +1,105 @@
<?php
namespace Keruald\OmniTools\Network;
use Countable;
use InvalidArgumentException;
class IPv4Range extends IPRange {
/**
* @var string
*/
private $base;
/**
* @var int
*/
private $networkBits;
///
/// Constructors
///
public function __construct (string $base, int $networkBits) {
$this->setBase($base);
$this->setNetworkBits($networkBits);
}
///
/// Getters and setters
///
/**
* @return string
*/
public function getBase () : string {
return $this->base;
}
/**
* @param string $base
*/
public function setBase (string $base) : void {
if (!IP::isIPv4($base)) {
throw new InvalidArgumentException;
}
$this->base = $base;
}
/**
* @return int
*/
public function getNetworkBits () : int {
return $this->networkBits;
}
/**
* @param int $networkBits
*/
public function setNetworkBits (int $networkBits) : void {
if ($networkBits < 0 || $networkBits > 32) {
throw new InvalidArgumentException;
}
$this->networkBits = $networkBits;
}
///
/// Helper methods
///
public function getFirst () : string {
return $this->base;
}
public function getLast () : string {
return long2ip(ip2long($this->base) + 2 ** $this->count() - 1);
}
public function contains (string $ip) : bool {
if (!IP::isIP($ip)) {
throw new InvalidArgumentException;
}
if (!IP::isIPv4($ip)) {
return false;
}
$ipAsLong = ip2long($ip);
$baseAsLong = ip2long($this->base);
return $ipAsLong >= $baseAsLong
&& $ipAsLong <= $baseAsLong + $this->count() - 1;
-
- return false;
}
///
/// Countable interface
///
public function count () : int {
return 32 - $this->networkBits;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Fri, Sep 19, 00:25 (1 d, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2991962
Default Alt Text
(2 KB)

Event Timeline