AbstractToken::not()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Maslosoft\Whitelist\Tokenizer;
10
11
use Maslosoft\Whitelist\Interfaces\TokenInterface;
12
use Maslosoft\Whitelist\Tokenizer\Tokens\EmptyToken;
13
14
/**
15
 * AbstractToken
16
 *
17
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
18
 */
19
abstract class AbstractToken
20
{
21
22
	public $line = 0;
23
	public $type = '';
24
	public $name = '';
25
	public $value = '';
26
27
	/**
28
	 *
29
	 * @var TokenInterface[]
30
	 */
31
	protected $tokens = [];
32
	protected $index = 0;
33
34
	//abstract public function __construct(&$data, &$tokens, $index);
35
36
	/**
37
	 *
38
	 * @param int $type
39
	 * @return bool
40
	 */
41
	public function is($type)
42
	{
43
		return $this->type === $type;
44
	}
45
46
	/**
47
	 *
48
	 * @param int $type
49
	 * @return bool
50
	 */
51
	public function not($type)
52
	{
53
		return $this->type !== $type;
54
	}
55
56
	/**
57
	 * Check token value
58
	 * @param string $value
59
	 */
60
	public function valIs($value)
61
	{
62
		return $this->value === $value;
63
	}
64
65
	/**
66
	 * Get token value
67
	 * @param string $value
68
	 */
69
	public function val()
70
	{
71
		return $this->value;
72
	}
73
74
	/**
75
	 * Get previous token, ignoring whitespace
76
	 * @return TokenInterface
77
	 */
78
	public function prev()
79
	{
80
		$i = $this->index - 1;
81
		if (isset($this->tokens[$i]))
82
		{
83
			$token = $this->tokens[$i];
84
			while ($token->is(T_WHITESPACE))
85
			{
86
				$token = $token->prev();
87
			}
88
			return $token;
89
		}
90
		return new EmptyToken();
91
	}
92
93
	/**
94
	 * Get next token, ignoring whitespace
95
	 * @return TokenInterface
96
	 */
97
	public function next()
98
	{
99
		$i = $this->index + 1;
100
		if (isset($this->tokens[$i]))
101
		{
102
			$token = $this->tokens[$i];
103
			while ($token->is(T_WHITESPACE))
104
			{
105
				$token = $token->next();
106
			}
107
			return $token;
108
		}
109
		return new EmptyToken();
110
	}
111
112
}
113