Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wordfenc.../vendor/wordfenc.../mmdb-rea.../src
File: IpAddress.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Wordfence\MmdbReader;
[2] Fix | Delete
[3] Fix | Delete
use Wordfence\MmdbReader\Exception\InvalidIpAddressException;
[4] Fix | Delete
[5] Fix | Delete
class IpAddress implements IpAddressInterface {
[6] Fix | Delete
[7] Fix | Delete
const TYPE_IPV4 = 4;
[8] Fix | Delete
const TYPE_IPV6 = 6;
[9] Fix | Delete
[10] Fix | Delete
const LENGTH_IPV4 = 4;
[11] Fix | Delete
const LENGTH_IPV6 = 16;
[12] Fix | Delete
[13] Fix | Delete
const SEPARATOR_IPV4 = '.';
[14] Fix | Delete
const SEPARATOR_IPV6 = ':';
[15] Fix | Delete
[16] Fix | Delete
private static $SEPARATORS = array(
[17] Fix | Delete
self::SEPARATOR_IPV4,
[18] Fix | Delete
self::SEPARATOR_IPV6
[19] Fix | Delete
);
[20] Fix | Delete
[21] Fix | Delete
private $humanReadable;
[22] Fix | Delete
private $binary;
[23] Fix | Delete
private $type;
[24] Fix | Delete
[25] Fix | Delete
protected function __construct($humanReadable, $binary) {
[26] Fix | Delete
$this->humanReadable = $humanReadable;
[27] Fix | Delete
$this->binary = $binary;
[28] Fix | Delete
$this->type = self::resolveType($binary);
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
public function getHumanReadable() {
[32] Fix | Delete
return $this->humanReadable;
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
public function getBinary() {
[36] Fix | Delete
return $this->binary;
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
public function getType() {
[40] Fix | Delete
return $this->type;
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
private static function resolveType($binary) {
[44] Fix | Delete
return strlen($binary) === self::LENGTH_IPV6 ? self::TYPE_IPV6 : self::TYPE_IPV4;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Create an IpAddress instance from a human-readable string
[49] Fix | Delete
* @param string $humanReadable a human readable IP address
[50] Fix | Delete
* @return IpAddress
[51] Fix | Delete
* @throws InvalidIpAddressException if $humanReadable is not a valid human-readable IP address
[52] Fix | Delete
*/
[53] Fix | Delete
public static function createFromHumanReadable($humanReadable) {
[54] Fix | Delete
$binary = inet_pton($humanReadable);
[55] Fix | Delete
if ($binary === false)
[56] Fix | Delete
throw new InvalidIpAddressException("IP address \"{$humanReadable}\" is malformed");
[57] Fix | Delete
return new self($humanReadable, $binary);
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
/**
[61] Fix | Delete
* Create an IpAddress instance from a binary string
[62] Fix | Delete
* @param string $binary a binary IP address
[63] Fix | Delete
* @return IpAddress
[64] Fix | Delete
* @throws InvalidIpAddressException if $binary is not a valid binary IP address
[65] Fix | Delete
*/
[66] Fix | Delete
public static function createFromBinary($binary) {
[67] Fix | Delete
$humanReadable = inet_ntop($binary);
[68] Fix | Delete
if ($humanReadable === false)
[69] Fix | Delete
throw new InvalidIpAddressException("Binary IP address data is invalid: " . bin2hex($binary));
[70] Fix | Delete
return new self($humanReadable, $binary);
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Create an IpAddress instance from an unknown string representation
[75] Fix | Delete
* @param string $string either a human-readable or binary IP address
[76] Fix | Delete
* @return IpAddress
[77] Fix | Delete
* @throws InvalidIpAddressException if $string cannot be parsed as a valid IP address
[78] Fix | Delete
*/
[79] Fix | Delete
public static function createFromString($string) {
[80] Fix | Delete
foreach (self::$SEPARATORS as $separator) {
[81] Fix | Delete
if (strpos($string, $separator) !== false) {
[82] Fix | Delete
try {
[83] Fix | Delete
return self::createFromHumanReadable($string);
[84] Fix | Delete
}
[85] Fix | Delete
catch (InvalidIpAddressException $e) {
[86] Fix | Delete
break;
[87] Fix | Delete
}
[88] Fix | Delete
}
[89] Fix | Delete
}
[90] Fix | Delete
return self::createFromBinary($string);
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
public function __toString() {
[94] Fix | Delete
return $this->getHumanReadable();
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
}
[98] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function