Passed
Push — main ( f13300...83daa4 )
by smiley
13:11
created

QRDataModeAbstract::getDataMode()   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
c 0
b 0
f 0
nc 1
nop 0
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
 * abstract methods for the several data modes
17
 */
18
abstract class QRDataModeAbstract implements QRDataModeInterface{
19
20
	/**
21
	 * The data to write
22
	 */
23
	protected string $data;
24
25
	/**
26
	 * QRDataModeAbstract constructor.
27
	 *
28
	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
29
	 */
30
	public function __construct(string $data){
31
		$data = $this::convertEncoding($data);
32
33
		if(!$this::validateString($data)){
34
			throw new QRCodeDataException('invalid data');
35
		}
36
37
		$this->data = $data;
38
	}
39
40
	/**
41
	 * returns the character count of the $data string
42
	 */
43
	protected function getCharCount():int{
44
		return strlen($this->data);
45
	}
46
47
	/**
48
	 * @inheritDoc
49
	 */
50
	public static function convertEncoding(string $string):string{
51
		return $string;
52
	}
53
54
	/**
55
	 * shortcut
56
	 */
57
	protected static function getLengthBits(int $versionNumber):int{
58
		return Mode::getLengthBitsForVersion(static::DATAMODE, $versionNumber);
59
	}
60
61
}
62