Passed
Push — main ( 38823d...9db842 )
by smiley
02:04
created

QRDataModeAbstract::getLengthBits()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
1
<?php
2
/**
3
 * Class QRDataModeAbstract
4
 *
5
 * @created      19.11.2020
6
 * @author       smiley <[email protected]>
7
 * @copyright    2020 smiley
8
 * @license      MIT
9
 */
10
11
namespace chillerlan\QRCode\Data;
12
13
use chillerlan\QRCode\Common\Mode;
14
15
/**
16
 */
17
abstract class QRDataModeAbstract implements QRDataModeInterface{
18
19
	/**
20
	 * the current data mode: Num, Alphanum, Kanji, Byte
21
	 */
22
	protected static int $datamode;
23
24
	/**
25
	 * The data to write
26
	 */
27
	protected string $data;
28
29
	/**
30
	 * QRDataModeAbstract constructor.
31
	 *
32
	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
33
	 */
34
	public function __construct(string $data){
35
36
		if(!$this::validateString($data)){
37
			throw new QRCodeDataException('invalid data');
38
		}
39
40
		$this->data = $data;
41
	}
42
43
	/**
44
	 * returns the character count of the $data string
45
	 */
46
	protected function getCharCount():int{
47
		return strlen($this->data);
48
	}
49
50
	/**
51
	 * @inheritDoc
52
	 */
53
	public function getDataMode():int{
54
		return $this::$datamode;
55
	}
56
57
	/**
58
	 * shortcut
59
	 */
60
	protected static function getLengthBits(int $versionNumber):int{
61
		return Mode::getLengthBitsForVersion(static::$datamode, $versionNumber);
62
	}
63
64
}
65