PhpTokenBase::setLine()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Base class for PHP token manipulation
4
 *
5
 * @file      PhpTokenBase.php
6
 *
7
 * PHP version 8.0+
8
 *
9
 * @author    Yancharuk Alexander <alex at itvault dot info>
10
 * @copyright © 2012-2021 Alexander Yancharuk
11
 * @date      Tue Aug 26 17:43:40
12
 * @license   The BSD 3-Clause License
13
 *            <https://tldrlegal.com/license/bsd-3-clause-license-(revised)>
14
 */
15
16
namespace Veles\Tools;
17
18
use Veles\Validators\ValidatorInterface;
19
20
/**
21
 * Class PhpTokenBase
22
 *
23
 * @author  Yancharuk Alexander <alex at itvault dot info>
24
 */
25
class PhpTokenBase
26
{
27
	/** @var  int */
28
	protected $identifier = 0;
29
	/** @var  string */
30
	protected $name = 'UNKNOWN';
31
	/** @var  int */
32
	protected $line = 0;
33
	/** @var  string */
34
	protected $content = '';
35
36
	/**
37
	 * Token constructor
38
	 *
39
	 * @param string|array $token
40
	 * @param ValidatorInterface   $validator
41
	 *
42
	 * @throws \Exception
43
	 */
44 6
	public function __construct($token, ValidatorInterface $validator)
45
	{
46 6
		if (!$validator->check($token)) {
47 1
			throw new \Exception('Not valid token value');
48
		}
49
50 5
		if (is_string($token)) {
51 4
			$this->content = $token;
52
53 4
			return;
54
		}
55
56 1
		$this->identifier = $token[0];
57 1
		$this->content    = $token[1];
58 1
		$this->line       = $token[2];
59
	}
60
61
	/**
62
	 * @param string $content
63
	 */
64 1
	public function setContent($content)
65
	{
66 1
		$this->content = $content;
67
	}
68
69
	/**
70
	 * @return string
71
	 */
72 2
	public function getContent()
73
	{
74 2
		return $this->content;
75
	}
76
77
	/**
78
	 * @param int $identifier
79
	 */
80 2
	public function setId($identifier)
81
	{
82 2
		$this->identifier = $identifier;
83
	}
84
85
	/**
86
	 * @return int
87
	 */
88 3
	public function getId()
89
	{
90 3
		return $this->identifier;
91
	}
92
93
	/**
94
	 * @param int $line
95
	 */
96 1
	public function setLine($line)
97
	{
98 1
		$this->line = $line;
99
	}
100
101
	/**
102
	 * @return int
103
	 */
104 2
	public function getLine()
105
	{
106 2
		return $this->line;
107
	}
108
}
109