Completed
Push — master ( f5a4f7...862e70 )
by Richard
02:25
created

SheetTokenizer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 24
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getTokens() 0 3 1
A stripComments() 0 10 3
1
<?php
2
namespace Transphporm\Parser;
3
class SheetTokenizer {
4
    private $tokenizer;
5
6
    public function __construct($tss) {
7
        $tss = $this->stripComments($tss, '//', "\n");
8
		$tss = $this->stripComments($tss, '/*', '*/');
9
		$this->tokenizer = new Tokenizer($tss);
10
    }
11
12
    public function getTokens() {
13
		return $this->tokenizer->getTokens();
14
    }
15
16
    private function stripComments($str, $open, $close) {
17
		$pos = 0;
18
		while (($pos = strpos($str, $open, $pos)) !== false) {
19
			$end = strpos($str, $close, $pos);
20
			if ($end === false) break;
21
			$str = substr_replace($str, '', $pos, $end-$pos+strlen($close));
22
		}
23
24
		return $str;
25
	}
26
}
27