Completed
Push — master ( 8a12d1...a9e060 )
by Tom
01:46
created

Brackets   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A tokenize() 0 10 4
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\Tokenizer;
8
use \Transphporm\Parser\Tokenizer;
9
use \Transphporm\Parser\Tokens;
10
11
class Brackets implements \Transphporm\Parser\Tokenize {
12
13
	private $types =  [
14
			Tokenizer::OPEN_BRACKET => ['(', ')'],
15
			Tokenizer::OPEN_BRACE => ['{', '}'],
16
			Tokenizer::OPEN_SQUARE_BRACKET => ['[', ']']
17
	];
18
19
	public function tokenize(TokenizedString $str, Tokens $tokens) {
20
		foreach ($this->types as $type => $brackets) {
21
			if ($str->has() && $str->identifyChar() === $type) {
22
				$contents = $str->extractBrackets($brackets[0], $brackets[1]);
23
				$tokenizer = new Tokenizer($contents);
24
				$tokens->add(['type' => $type, 'value' => $tokenizer->getTokens(), 'string' => $contents, 'line' => $str->lineNo()]);
25
				$str->move(strlen($contents));
26
			}
27
		}
28
	}
29
}