瀏覽代碼

added @property mode

smiley 9 年之前
父節點
當前提交
3c4102d4b5
共有 2 個文件被更改,包括 6 次插入5 次删除
  1. 1 0
      src/Data/QRDataInterface.php
  2. 5 5
      src/QRCode.php

+ 1 - 0
src/Data/QRDataInterface.php

@@ -17,6 +17,7 @@ use chillerlan\QRCode\BitBuffer;
 /**
  * @property string data
  * @property int    dataLength
+ * @property int    mode
  */
 interface QRDataInterface{
 

+ 5 - 5
src/QRCode.php

@@ -16,7 +16,6 @@ use chillerlan\QRCode\Data\AlphaNum;
 use chillerlan\QRCode\Data\Byte;
 use chillerlan\QRCode\Data\Kanji;
 use chillerlan\QRCode\Data\Number;
-use chillerlan\QRCode\Data\QRDataInterface;
 use chillerlan\QRCode\Output\QROutputInterface;
 
 /**
@@ -162,10 +161,11 @@ class QRCode{
 	 * @throws \chillerlan\QRCode\QRCodeException
 	 */
 	protected function getTypeNumber($mode){
-		/** @noinspection PhpUndefinedFieldInspection */
-		$length = $this->qrDataInterface->mode === QRConst::MODE_KANJI
-			? floor($this->qrDataInterface->dataLength / 2)
-			: $this->qrDataInterface->dataLength;
+		$length = $this->qrDataInterface->dataLength;
+
+		if($this->qrDataInterface->mode === QRConst::MODE_KANJI){
+			$length = floor($this->qrDataInterface->dataLength / 2);
+		}
 
 		foreach(range(1, 10) as $type){
 			if($length <= Util::getMaxLength($type, $mode, $this->errorCorrectLevel)){