Completed
Push — master ( 3cb15c...9044bc )
by smiley
02:37
created

QRDataAbstract::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * Class QRDataAbstract
4
 *
5
 * @filesource   QRDataAbstract.php
6
 * @created      25.11.2015
7
 * @package      chillerlan\QRCode\Data
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2015 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\QRCode\Data;
14
15
/**
16
 *
17
 */
18
abstract class QRDataAbstract implements QRDataInterface{
19
20
	/**
21
	 * @var string
22
	 */
23
	public $data;
24
25
	/**
26
	 * @var int
27
	 */
28
	public $dataLength;
29
30
	/**
31
	 * @var array
32
	 */
33
	protected $lengthBits = [0, 0, 0];
34
35
	/**
36
	 * QRDataAbstract constructor.
37
	 *
38
	 * @param string $data
39
	 */
40
	public function __construct($data){
41
		$this->data = $data;
42
		$this->dataLength = strlen($data);
43
	}
44
45
	/**
46
	 * @param int $type
47
	 *
48
	 * @return int
49
	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
50
	 * @see QRCode::createData()
51
	 * @codeCoverageIgnore
52
	 */
53
	public function getLengthInBits($type){
54
55
		switch(true){
56
			case $type >= 1 && $type <= 9:
57
				return $this->lengthBits[0]; //  1 -  9
58
			case $type <= 26:
59
				return $this->lengthBits[1]; // 10 - 26
60
			case $type <= 40:
61
				return $this->lengthBits[2]; // 27 - 40
62
			default:
63
				throw new QRCodeDataException('$type: '.$type);
64
		}
65
66
	}
67
68
}
69