HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux WebLive 5.15.0-79-generic #86-Ubuntu SMP Mon Jul 10 16:07:21 UTC 2023 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/wpwatermates_err/wp-content/plugins/defender-security/src/component/scan/tokens.php
<?php

namespace WP_Defender\Component\Scan;

use WP_Defender\Component;

class Tokens extends Component {
	public static $tokens = [];

	/**
	 * @param $line
	 *
	 * @return array
	 */
	public static function get_tokens_by_line( $line ): array {
		$catch = [];
		foreach ( self::$tokens as $token ) {
			if ( $line === $token['line'] ) {
				$catch[] = $token;
			}
		}

		return $catch;
	}

	/**
	 * @param $tokens
	 *
	 * @return string
	 */
	public static function formatter( $tokens ): string {
		$string = '';
		foreach ( $tokens as $token ) {
			$string .= $token['content'];
		}

		return $string;
	}

	/**
	 * @param $content
	 * @param $offset
	 *
	 * @return int
	 */
	public static function get_line_from_offset( $content, $offset ): int {
		// Polyfill for PHP version < 8.0.
		$offset = max( $offset, 1 );
		[$before] = str_split( $content, $offset );

		return strlen( $before ) - strlen( str_replace( PHP_EOL, '', $before ) ) + 1;
	}

	/**
	 * Get a list of [line,column] of each token. We will need to use this for highlight the code on frontend.
	 *
	 * @param array $tokens
	 *
	 * @return array
	 */
	public static function get_offsets_map( $tokens = [] ): array {
		$tmp = [];
		$mapper = [];
		foreach ( $tokens as $token ) {
			$tmp[ $token['line'] ][] = $token['column'] + $token['length'];
		}
		foreach ( $tmp as $line => &$cols ) {
			sort( $cols );
			$start = count( $cols ) > 1 ? current( $cols ) : 0;
			$range = [ $start, end( $cols ) ];
			$mapper[] = [
				'line' => $line,
				'range' => $range,
			];
		}

		return $mapper;
	}
}