Tokenizer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 7
dl 0
loc 58
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A getTokens() 0 12 3
1
<?php
2
/* @description     Transformation Style Sheets - Revolutionising PHP templating    *
3
 * @author          Tom Butler [email protected]                                             *
4
 * @copyright       2017 Tom Butler <[email protected]> | https://r.je/                      *
5
 * @license         http://www.opensource.org/licenses/bsd-license.php  BSD License *
6
 * @version         1.2                                                             */
7
namespace Transphporm\Parser;
8
class Tokenizer {
9
	private $str;
10
	private $tokenizeRules = [];
11
12
	const NAME = 'LITERAL';
13
	const STRING = 'STRING';
14
	const OPEN_BRACKET = 'OPEN_BRACKET';
15
	const CLOSE_BRACKET = 'CLOSE_BRACKET';
16
	const OPEN_SQUARE_BRACKET = 'SQUARE_BRACKET';
17
	const CLOSE_SQUARE_BRACKET = 'CLOSE_SQUARE_BRACKET';
18
	const CONCAT = 'CONCAT';
19
	const ARG = 'ARG';
20
	const WHITESPACE = 'WHITESPACE';
21
	const NEW_LINE = 'NEW_LINE';
22
	const DOT = 'DOT';
23
	const NUMERIC = 'NUMERIC';
24
	const EQUALS = 'EQUALS';
25
	const NOT = 'NOT';
26
	const OPEN_BRACE = 'OPEN_BRACE';
27
	const CLOSE_BRACE = 'CLOSE_BRACE';
28
	const BOOL = 'BOOL';
29
	const IN = 'IN';
30
	const COLON = 'COLON';
31
	const SEMI_COLON = 'SEMI_COLON';
32
	const NUM_SIGN = 'NUM_SIGN';
33
	const GREATER_THAN = 'GREATER_THAN';
34
	const LOWER_THAN = 'LOWER_THAN';
35
	const AT_SIGN = 'AT_SIGN';
36
	const SUBTRACT = 'SUBTRACT';
37
	const MULTIPLY = 'MULTIPLY';
38
	const DIVIDE = 'DIVIDE';
39
40
	public function __construct($str) {
41
		$this->str = new Tokenizer\TokenizedString($str);
42
43
		$this->tokenizeRules = [
44
			new Tokenizer\Comments,
45
			new Tokenizer\BasicChars,
46
			new Tokenizer\Literals,
47
			new Tokenizer\Strings,
48
			new Tokenizer\Brackets
49
		];
50
	}
51
52
	public function getTokens() {
53
		$tokens = new Tokens;
54
		$this->str->reset();
55
56
		while ($this->str->next()) {
57
			foreach ($this->tokenizeRules as $tokenizer) {
58
				$tokenizer->tokenize($this->str, $tokens);
59
			}
60
		}
61
62
		return $tokens;
63
	}
64
65
}
66