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

QRDataAbstract   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 51
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B getLengthInBits() 0 14 5
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