diff --git a/src/Helpers/Polynomial.php b/src/Helpers/Polynomial.php index ff1468759..adedc38bf 100644 --- a/src/Helpers/Polynomial.php +++ b/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 */ diff --git a/src/Output/QRImage.php b/src/Output/QRImage.php index 7e3d2fd36..b238b9b18 100644 --- a/src/Output/QRImage.php +++ b/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 diff --git a/src/Output/QRMarkup.php b/src/Output/QRMarkup.php index 86a45a445..7e8aa4373 100644 --- a/src/Output/QRMarkup.php +++ b/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 diff --git a/src/Output/QROutputAbstract.php b/src/Output/QROutputAbstract.php index c9f206f4e..3a73f0b05 100644 --- a/src/Output/QROutputAbstract.php +++ b/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; + } + } diff --git a/src/Output/QRString.php b/src/Output/QRString.php index 093722112..231dfb5ff 100644 --- a/src/Output/QRString.php +++ b/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()); }