# defender-security/3.0.1/src/component/scan/tokens.php

Defender Security – Malware Scanner, Login Security &amp; Firewall, version 3.0.1. 80 lines.

- Page: https://pluginprobe.com/plugins/defender-security/3.0.1/code/src/component/scan/tokens.php
- Raw: https://pluginprobe.com/plugins/defender-security/3.0.1/raw/src/component/scan/tokens.php
- Modified: 2022-06-16T08:36:34+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/defender-security/3.0.1/code/src/component/scan/tokens.php#L10-L20`.

```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 ) {
		$catch = [];
		foreach ( self::$tokens as $token ) {
			if ( $line === $token['line'] ) {
				$catch[] = $token;
			}
		}

		return $catch;
	}

	/**
	 * @param $tokens
	 *
	 * @return string
	 */
	public static function formatter( $tokens ) {
		$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 ) {
		[$before] = str_split( $content, $offset );
		$line_number = strlen( $before ) - strlen( str_replace( PHP_EOL, "", $before ) ) + 1;

		return $line_number;
	}

	/**
	 * 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 = [] ) {
		$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;
	}
}

```
