refactoring

This commit is contained in:
smiley
2016-02-08 14:39:58 +01:00
parent 0fe303d37d
commit a70bc50436
5 changed files with 185 additions and 189 deletions
+31 -4
View File
@@ -13,8 +13,8 @@
namespace chillerlan\QRCode\Data;
use chillerlan\QRCode\BitBuffer;
use chillerlan\QRCode\QRCodeException;
use chillerlan\QRCode\QRConst;
use chillerlan\QRCode\Util;
/**
*
@@ -38,21 +38,48 @@ class Number extends QRDataBase implements QRDataInterface{
$i = 0;
while($i + 2 < $this->dataLength){
$buffer->put(Util::parseInt(substr($this->data, $i, 3)), 10);
$buffer->put($this->parseInt(substr($this->data, $i, 3)), 10);
$i += 3;
}
if($i < $this->dataLength){
if($this->dataLength - $i === 1){
$buffer->put(Util::parseInt(substr($this->data, $i, $i + 1)), 4);
$buffer->put($this->parseInt(substr($this->data, $i, $i + 1)), 4);
}
else if($this->dataLength - $i === 2){
$buffer->put(Util::parseInt(substr($this->data, $i, $i + 2)), 7);
$buffer->put($this->parseInt(substr($this->data, $i, $i + 2)), 7);
}
}
}
/**
* @param string $string
*
* @return int
* @throws \chillerlan\QRCode\QRCodeException
*/
private static function parseInt($string){
$num = 0;
$len = strlen($string);
for($i = 0; $i < $len; $i++){
$c = ord($string[$i]);
$ord0 = ord('0');
if($ord0 <= $c && $c <= ord('9')){
$c = $c - $ord0;
}
else{
throw new QRCodeException('illegal char: '.$c);
}
$num = $num * 10 + $c;
}
return $num;
}
}