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: NodeReader.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Wordfence\MmdbReader;
[2] Fix | Delete
[3] Fix | Delete
class NodeReader {
[4] Fix | Delete
[5] Fix | Delete
const SHARED_MASK_LEFT = 240; //0b11110000
[6] Fix | Delete
const SHARED_MASK_RIGHT = 15; //0b00001111
[7] Fix | Delete
[8] Fix | Delete
private $handle;
[9] Fix | Delete
private $nodeSize, $nodeCount;
[10] Fix | Delete
private $searchTreeSectionSize;
[11] Fix | Delete
private $recordWholeBytes, $recordBits;
[12] Fix | Delete
private $sharedByteOffset;
[13] Fix | Delete
[14] Fix | Delete
public function __construct($handle, $nodeSize, $nodeCount) {
[15] Fix | Delete
$this->handle = $handle;
[16] Fix | Delete
$this->nodeSize = $nodeSize;
[17] Fix | Delete
$this->nodeCount = $nodeCount;
[18] Fix | Delete
$this->searchTreeSectionSize = $nodeSize * $nodeCount;
[19] Fix | Delete
$this->computeRecordSizes();
[20] Fix | Delete
}
[21] Fix | Delete
[22] Fix | Delete
private function computeRecordSizes() {
[23] Fix | Delete
$this->recordWholeBytes = (int) ($this->nodeSize / 2);
[24] Fix | Delete
$this->recordBits = $this->nodeSize % 2;
[25] Fix | Delete
if ($this->recordBits > 0)
[26] Fix | Delete
$this->sharedByteOffset = $this->recordWholeBytes + 1;
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
public function read($position = 0) {
[30] Fix | Delete
if ($position > $this->nodeCount)
[31] Fix | Delete
throw new InvalidOperationException("Read requested for node at {$position}, but only {$this->nodeCount} nodes are present");
[32] Fix | Delete
$offset = $position * $this->nodeSize;
[33] Fix | Delete
$this->handle->seek($offset, SEEK_SET);
[34] Fix | Delete
$data = $this->handle->read($this->nodeSize);
[35] Fix | Delete
return new Node($this, $data);
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
private function hasSharedByte() {
[39] Fix | Delete
return $this->sharedByteOffset !== null;
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
private function getWholeByteOffset($side) {
[43] Fix | Delete
return $side === Node::SIDE_LEFT ? 0 : ($this->hasSharedByte() ? $this->sharedByteOffset : $this->recordWholeBytes);
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
public function extractRecord($nodeData, $side) {
[47] Fix | Delete
if ($this->hasSharedByte()) {
[48] Fix | Delete
$sharedByte = ord($nodeData[$this->sharedByteOffset]);
[49] Fix | Delete
if ($side === Node::SIDE_LEFT) {
[50] Fix | Delete
$value = $sharedByte >> 4;
[51] Fix | Delete
}
[52] Fix | Delete
else {
[53] Fix | Delete
$value = $sharedByte & self::SHARED_MASK_RIGHT;
[54] Fix | Delete
}
[55] Fix | Delete
}
[56] Fix | Delete
else {
[57] Fix | Delete
$value = 0;
[58] Fix | Delete
}
[59] Fix | Delete
$offset = $this->getWholeByteOffset($side);
[60] Fix | Delete
$end = $offset + $this->recordWholeBytes;
[61] Fix | Delete
for ($i = $offset; $i < $end; $i++) {
[62] Fix | Delete
$byte = ord($nodeData[$i]);
[63] Fix | Delete
$value = ($value << 8) | $byte;
[64] Fix | Delete
}
[65] Fix | Delete
return $value;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
public function getNodeCount() {
[69] Fix | Delete
return $this->nodeCount;
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
public function getSearchTreeSectionSize() {
[73] Fix | Delete
return $this->searchTreeSectionSize;
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
}
[77] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function