TokenTracker   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 0
loc 57
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A visitToken() 0 5 1
A getNextToken() 0 3 1
A getPrevToken() 0 3 1
A isLastToken() 0 3 1
A nextToken() 0 11 2
A prevToken() 0 11 2
1
<?php
2
namespace gossi\formatter\parser;
3
4
use phootwork\tokenizer\Token;
5
use phootwork\tokenizer\TokenCollection;
6
use phootwork\tokenizer\TokenVisitorInterface;
7
8
class TokenTracker implements TokenVisitorInterface {
9
10
	private $tokens;
11
	private $context;
12
13
	private $next;
14
	private $prev;
15
16 10
	public function __construct(TokenCollection $tokens, Context $contextManager) {
17 10
		$this->tokens = $tokens;
18 10
		$this->context = $contextManager;
19 10
		$this->context->setTracker($this);
20 10
	}
21
22 10
	public function visitToken(Token $token) {
23 10
		$this->next = $this->nextToken($token);
24 10
		$this->prev = $this->prevToken($token);
25 10
		$this->context->visitToken($token);
26 10
	}
27
28 3
	public function getNextToken() {
29 3
		return $this->next;
30
	}
31
32 10
	public function getPrevToken() {
33 10
		return $this->prev;
34
	}
35
36 10
	public function nextToken(Token $token, $offset = 1) {
37 10
		$index = $this->tokens->indexOf($token);
38 10
		$index += $offset;
39 10
		$token = $this->tokens->get($index);
40
41 10
		if ($token === null) {
42 10
			$token = new Token();
43
		}
44
45 10
		return $token;
46
	}
47
48 10
	public function prevToken($token, $offset = 1) {
49 10
		$index = $this->tokens->indexOf($token);
50 10
		$index -= $offset;
51 10
		$token = $this->tokens->get($index);
52
53 10
		if ($token === null) {
54 10
			$token = new Token();
55
		}
56
57 10
		return $token;
58
	}
59
60 10
	public function isLastToken(Token $token) {
61 10
		return $this->tokens->indexOf($token) == $this->tokens->size() - 1;
62
	}
63
64
}
65