$data may be
- a UNIX timestamp (TOTP)
- a counter value (HOTP)

@param int|null $data

@return string
321207
public function code(int $data = null):string{

		if($this->options->mode === 'hotp'){
			$data = $data ?? 0;

			$hashdata = pack('NN', ($data & 0xFFFFFFFF00000000) >> 32, $data & 0x00000000FFFFFFFF);
		}
		else{
			$hashdata = pack('J', $data ?? $this->timeslice());
		}

		$hash = hash_hmac($this->options->algorithm, $hashdata, $this->secret, true);
		$code = unpack('N', substr($hash, ord(substr($hash, -1)) & 0xF, 4))[1] & 0x7FFFFFFF;

		// test values
		// HOTP: https://tools.ietf.org/html/rfc4226#page-32
		// TOTP: https://tools.ietf.org/html/rfc6238#page-14
#		var_dump(['data' => dechex($data), 'hash' => bin2hex($hash), 'truncated_hex' => dechex($code), 'truncated_int' => $code]);

		return str_pad($code % pow(10, $this->options->digits), $this->options->digits, '0', STR_PAD_LEFT);
	}
917928
public static function encode($data)
    {
        switch (gettype($data)) {
            case 'array':
                return self::encodeArray($data);
            case 'object':
                return self::encodeObject($data);
            case 'string':
                return self::encodeString($data);
            case 'integer':
                return self::encodeInteger($data);
            case 'boolean':
                return self::encodeBoolean($data);
            case 'double':
                return self::encodeDouble($data);
            case 'NULL':
                return self::encodeNull($data);
            case 'resource':
                // TODO
                break;
            default:
                throw new UnencodeableException('Contains unencodeable type', 3);
        }
    }
1137460
public static function maybeUn($data)
    {
        // If it isn't a string, it isn't serialized
        if (!is_string($data)) {
            return $data;
        }

        $data = trim($data);

        // Is it the serialized NULL value?
        if ($data === 'N;') {
            return null;
        }

        $length = strlen($data);

        // Check some basic requirements of all serialized strings
        if (self::checkBasic($data, $length)) {
            return $data;
        }

        // $data is the serialized false value
        if ($data === 'b:0;') {
            return false;
        }

        // Don't attempt to unserialize data that isn't serialized
        $uns = @unserialize($data, []);

        // Data failed to unserialize?
        if ($uns === false) {
            $uns = @unserialize(self::fix($data), []);

            if ($uns === false) {
                return $data;
            }
            return $uns;
        }

        return $uns;
    }
1174519
public function automaticUuid($data)
	{
		return sprintf(
			'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
			mt_rand(0, 0xffff), mt_rand(0, 0xffff),
			mt_rand(0, 0xffff),
			mt_rand(0, 0x0fff) | 0x4000,
			mt_rand(0, 0x3fff) | 0x8000,
			mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
		);
	}
945032
public function onData($data)
    {
        //if we're in encryption stage decrypt it first
        if($this->secret !== null) {
            mcrypt_generic_init($this->encryptor, $this->secret, $this->secret);
            $data = mdecrypt_generic($this->encryptor, $data);
            mcrypt_generic_deinit($this->encryptor);
        }

        //attempt to parse the data as a packet
        try {

            //add the data to the current buffer
            $this->packetBuffer .= $data;

            //for as long as we have data left in the buffer
            do {

                //read the packet length from the stream
                $packetLengthVarInt = VarInt::readUnsignedVarInt($this->packetBuffer);

                //not enough data to read the packet length, wait for more data
                if($packetLengthVarInt === false) {
                    return;
                }

                //total length of the packet is the length of the varint + it's value
                $totalLength = $packetLengthVarInt->getDataLength() + $packetLengthVarInt->getValue();

                //if we don't have enough data to read the entire packet wait for more data to enter
                $bufferLength = strlen($this->packetBuffer);
                if ($bufferLength < $totalLength) {
                    return;
                }

                //remove the packet length varint from the buffer
                $this->packetBuffer = substr($this->packetBuffer, $packetLengthVarInt->getDataLength());

                //read the packet ID from the buffer
                $packetDataWithPacketID = substr($this->packetBuffer, 0, $packetLengthVarInt->getValue());

                //remove the rest of the packet from the buffer
                $this->packetBuffer = substr($this->packetBuffer, $packetLengthVarInt->getValue());

                //read the packet ID
                $packetID = VarInt::readUnsignedVarInt($packetDataWithPacketID);

                //get the raw packet data
                $packetData = substr($packetDataWithPacketID, $packetID->getDataLength());

                $this->lastPacket = $this->currentTime();

                //trigger packet processing
                $this->processPacket($packetID->getValue(), $packetData);

                //if we have buffer left run again
            } while (strlen($this->packetBuffer) > 0);

            //if any exceptions are thrown (error parsing the packets e.t.c.) send a disconnect packet
        } catch (Exception $ex) {
            echo "EXCEPTION IN PACKET PARSING {$ex->getMessage()}\n";
            echo $ex->getTraceAsString();
            $dis = new DisconnectPacket();
            $dis->setReason('Internal Server Error: '.$ex->getMessage());
            $this->end($dis->encodePacket());
        }
    }
644506
static function createFromData($data) {
        $instance = new static();

        $instance->day = $data[0];
        $instance->hour = $data[1];
        $instance->numberCommits = $data[2];

        return $instance;
    }
653470
private function getDataType($data)
    {
        if (is_string($data)) {
            return "'".$data."'";
        }

        if (is_numeric($data)) {
            return $data;
        }

        if (is_array($data)) {
            return 'Array';
        }

        if (is_bool($data)) {
            return $data ? 'true' : 'false';
        }

        if (is_object($data)) {
            return get_class($data);
        }

        if (is_null($data)) {
            return 'null';
        }

        return 'unknown';
    }
1008245
protected function _normalizeData($data)
    {
        $data += [
            'name' => '',
            'empty' => false,
            'disabled' => null,
            'val' => null,
            'year' => [],
            'month' => [],
            'day' => [],
            'hour' => [],
            'minute' => [],
            'second' => [],
            'meridian' => null,
            'templateVars' => [],
        ];

        $timeFormat = isset($data['hour']['format']) ? $data['hour']['format'] : null;
        if ($timeFormat === 12 && !isset($data['meridian'])) {
            $data['meridian'] = [];
        }
        if ($timeFormat === 24) {
            $data['meridian'] = false;
        }

        return $data;
    }
1315386
public function getDataForJSON($data = null)
    {
        if (is_null($data)) {
            $data = $this->getData();
        }
        $dataForJSON = parent::getDataForJSON($data);
        if (!is_null($this->atomic)) {
            $dataForJSON['@atomic'] = $this->atomic;
        }
        if (isset($this->sourceId)) {
            $dataForJSON['@sourceId'] = $this->sourceId;
            $this->sourceId = null;
        }
        return $dataForJSON;
    }
868589
protected function getTstamp($time = null)
    {
        $time = !is_null($time) ? strtotime($time) : time();
        $month = date("M", $time);
        $day = substr("  " . date("j", $time), -2);
        $hhmmss = date("H:i:s", $time);
        return $month . " " . $day . " " . $hhmmss;
    }
813594
private function encodeString($data = null)
    {
        $data = is_null($data) ? $this->data : $data;
        return sprintf("%d:%s", strlen($data), $data);
    }
242414
private function processRspan($data) {
		$last = Array();
		$cspan = Array();
		for ($i = 0; $i < count($data); $i++) {
			$cspan[$i] = Array();
			for ($j = 0; $j < count($data[$i]); $j++) {
				$cspan[$i][$j] = 0;
				if (!isset($last[$j])) $last[$j] = 0;
				if ($data[$i][$j] === '#rspan') {
					$cspan[$last[$j]][$j]++;
				} else {
					$last[$j] = $i;
				}
			}
		}
		return $cspan;
	}
492411
protected function unPrepareData($data){
        $dataUn = @unserialize($data);
        if ($data === 'b:0;' || $dataUn !== false) {
            return $dataUn;
        } else {
            echo $data;
        }
    }
1269528
public static function maybe_unserialize($data)
    {
        // If it isn't a string, it isn't serialized
        if (!is_string($data)) {
            return $data;
        }

        $data = trim($data);

        // Is it the serialized NULL value?
        if ($data === 'N;') {
            return null;
        }

        $length = strlen($data);

        // Check some basic requirements of all serialized strings
        if ($length < 4 || $data[1] !== ':' || ($data[$length - 1] !== ';' && $data[$length - 1] !== '}')) {
            return $data;
        }

        // $data is the serialized false value
        if ($data === 'b:0;') {
            return false;
        }

        // Don't attempt to unserialize data that isn't serialized
        $uns = @unserialize($data);

        // Data failed to unserialize?
        if ($uns === false) {
            $uns = @unserialize(self::fix_broken_serialization($data));

            if ($uns === false) {
                return $data;
            } else {
                return $uns;
            }
        } else {
            return $uns;
        }
    }
1349629
public function to_serialized($data = null)
	{
		if ($data === null)
		{
			$data = $this->_data;
		}

		return serialize($data);
	}
456479
public function serializeData($data) {
		if(is_array($data)) {
			ksort($data);
			$return = '';
			foreach($data as $key => $value) {
				if(is_numeric($key)) {
					$return .= $this->serializeData($value);
				} else {
					$return .= $key . $this->serializeData($value);
				}
			}
			return $return;
		} else {
			return (string)$data;
		}
	}
241045
final public static function getInstance($data=null)
    {
        $class = get_called_class();
        if (empty($class)) return null;

        if (!isset(self::$_instance)){
            self::$_instance = new $class($data);
        }

        return self::$_instance;
    }