refactoring

This commit is contained in:
smiley
2016-03-21 00:00:52 +01:00
parent 3cb15c94fb
commit 2c2f4b8bec
8 changed files with 93 additions and 76 deletions
+68
View File
@@ -0,0 +1,68 @@
<?php
/**
* Class QRDataAbstract
*
* @filesource QRDataAbstract.php
* @created 25.11.2015
* @package chillerlan\QRCode\Data
* @author Smiley <smiley@chillerlan.net>
* @copyright 2015 Smiley
* @license MIT
*/
namespace chillerlan\QRCode\Data;
/**
*
*/
abstract class QRDataAbstract implements QRDataInterface{
/**
* @var string
*/
public $data;
/**
* @var int
*/
public $dataLength;
/**
* @var array
*/
protected $lengthBits = [0, 0, 0];
/**
* QRDataAbstract constructor.
*
* @param string $data
*/
public function __construct($data){
$this->data = $data;
$this->dataLength = strlen($data);
}
/**
* @param int $type
*
* @return int
* @throws \chillerlan\QRCode\Data\QRCodeDataException
* @see QRCode::createData()
* @codeCoverageIgnore
*/
public function getLengthInBits($type){
switch(true){
case $type >= 1 && $type <= 9:
return $this->lengthBits[0]; // 1 - 9
case $type <= 26:
return $this->lengthBits[1]; // 10 - 26
case $type <= 40:
return $this->lengthBits[2]; // 27 - 40
default:
throw new QRCodeDataException('$type: '.$type);
}
}
}