Passed
Push — main ( 426c16...9e04d2 )
by smiley
01:56
created

QRDataModeAbstract::convertEncoding()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
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
		$data = $this::convertEncoding($data);
36
37
		if(!$this::validateString($data)){
38
			throw new QRCodeDataException('invalid data');
39
		}
40
41
		$this->data = $data;
42
	}
43
44
	/**
45
	 * returns the character count of the $data string
46
	 */
47
	protected function getCharCount():int{
48
		return strlen($this->data);
49
	}
50
51
	/**
52
	 * @inheritDoc
53
	 */
54
	public function getDataMode():int{
55
		return $this::$datamode;
56
	}
57
58
	/**
59
	 * shortcut
60
	 */
61
	protected static function getLengthBits(int $versionNumber):int{
62
		return Mode::getLengthBitsForVersion(static::$datamode, $versionNumber);
63
	}
64
65
	/**
66
	 * encoding conversion helper
67
	 *
68
	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
69
	 */
70
	public static function convertEncoding(string $string):string{
71
		return $string;
72
	}
73
74
}
75