فهرست منبع

:octocat: yo scrunitizer

codemasher 8 سال پیش
والد
کامیت
1dc4c77072
5فایلهای تغییر یافته به همراه31 افزوده شده و 31 حذف شده
  1. 4 4
      src/Helpers/Polynomial.php
  2. 3 1
      src/Output/QRImage.php
  3. 1 13
      src/Output/QRMarkup.php
  4. 18 0
      src/Output/QROutputAbstract.php
  5. 5 13
      src/Output/QRString.php

+ 4 - 4
src/Helpers/Polynomial.php

@@ -65,8 +65,8 @@ class Polynomial{
 	/**
 	 * Polynomial constructor.
 	 *
-	 * @param array $num
-	 * @param int   $shift
+	 * @param array|null $num
+	 * @param int|null   $shift
 	 */
 	public function __construct(array $num = null, int $shift = null){
 		$this->setNum($num ?? [1], $shift);
@@ -80,8 +80,8 @@ class Polynomial{
 	}
 
 	/**
-	 * @param array $num
-	 * @param int   $shift
+	 * @param array    $num
+	 * @param int|null $shift
 	 *
 	 * @return \chillerlan\QRCode\Helpers\Polynomial
 	 */

+ 3 - 1
src/Output/QRImage.php

@@ -24,6 +24,8 @@ class QRImage extends QROutputAbstract{
 		QRCode::OUTPUT_IMAGE_GIF,
 	];
 
+	protected $defaultMode  = QRCode::OUTPUT_IMAGE_PNG;
+
 	protected $moduleValues = [
 		// light
 		QRMatrix::M_DATA            => [255, 255, 255],
@@ -140,7 +142,7 @@ class QRImage extends QROutputAbstract{
 		ob_start();
 
 		try{
-			call_user_func([$this, $this->outputMode ?? QRCode::OUTPUT_IMAGE_PNG]);
+			call_user_func([$this, $this->outputMode ?? $this->defaultMode]);
 		}
 		// not going to cover edge cases
 		// @codeCoverageIgnoreStart

+ 1 - 13
src/Output/QRMarkup.php

@@ -19,19 +19,7 @@ use chillerlan\QRCode\QRCode;
  */
 class QRMarkup extends QROutputAbstract{
 
-	/**
-	 * @return string
-	 */
-	public function dump(){
-
-		$data = call_user_func([$this, $this->outputMode ?? QRCode::OUTPUT_MARKUP_SVG]);
-
-		if($this->options->cachefile !== null){
-			$this->saveToFile($data);
-		}
-
-		return $data;
-	}
+	protected $defaultMode = QRCode::OUTPUT_MARKUP_SVG;
 
 	/**
 	 * @return string|bool

+ 18 - 0
src/Output/QROutputAbstract.php

@@ -41,6 +41,11 @@ abstract class QROutputAbstract implements QROutputInterface{
 	 */
 	protected $outputMode;
 
+	/**
+	 * @var string;
+	 */
+	protected $defaultMode;
+
 	/**
 	 * QROutputAbstract constructor.
 	 *
@@ -77,4 +82,17 @@ abstract class QROutputAbstract implements QROutputInterface{
 		return file_put_contents($this->options->cachefile, $data);
 	}
 
+	/**
+	 * @return string
+	 */
+	public function dump(){
+		$data = call_user_func([$this, $this->outputMode ?? $this->defaultMode]);
+
+		if($this->options->cachefile !== null){
+			$this->saveToFile($data);
+		}
+
+		return $data;
+	}
+
 }

+ 5 - 13
src/Output/QRString.php

@@ -19,18 +19,7 @@ use chillerlan\QRCode\QRCode;
  */
 class QRString extends QROutputAbstract{
 
-	/**
-	 * @return string
-	 */
-	public function dump():string{
-		$data = call_user_func([$this, $this->outputMode ?? QRCode::OUTPUT_STRING_TEXT]);
-
-		if($this->options->cachefile !== null){
-			$this->saveToFile($data);
-		}
-
-		return $data;
-	}
+	protected $defaultMode = QRCode::OUTPUT_STRING_TEXT;
 
 	/**
 	 * @return string
@@ -60,7 +49,10 @@ class QRString extends QROutputAbstract{
 		return implode($this->options->eol, $str);
 	}
 
-	protected function json(){
+	/**
+	 * @return string
+	 */
+	protected function json():string{
 		return json_encode($this->matrix->matrix());
 	}