diff options
Diffstat (limited to 'vendor/chillerlan/php-qrcode/src/Output')
7 files changed, 112 insertions, 99 deletions
diff --git a/vendor/chillerlan/php-qrcode/src/Output/QRFpdf.php b/vendor/chillerlan/php-qrcode/src/Output/QRFpdf.php index a706685af..a15ae9ff3 100644 --- a/vendor/chillerlan/php-qrcode/src/Output/QRFpdf.php +++ b/vendor/chillerlan/php-qrcode/src/Output/QRFpdf.php @@ -69,7 +69,7 @@ class QRFpdf extends QROutputAbstract{ * @return string|\FPDF */ public function dump(string $file = null){ - $file = $file ?? $this->options->cachefile; + $file ??= $this->options->cachefile; $fpdf = new FPDF('P', $this->options->fpdfMeasureUnit, [$this->length, $this->length]); $fpdf->AddPage(); @@ -83,6 +83,7 @@ class QRFpdf extends QROutputAbstract{ $color = $this->moduleValues[$M_TYPE]; if($prevColor === null || $prevColor !== $color){ + /** @phan-suppress-next-line PhanParamTooFewUnpack */ $fpdf->SetFillColor(...$color); $prevColor = $color; } diff --git a/vendor/chillerlan/php-qrcode/src/Output/QRImage.php b/vendor/chillerlan/php-qrcode/src/Output/QRImage.php index 598948c94..8f533d341 100644 --- a/vendor/chillerlan/php-qrcode/src/Output/QRImage.php +++ b/vendor/chillerlan/php-qrcode/src/Output/QRImage.php @@ -19,30 +19,36 @@ use chillerlan\QRCode\{QRCode, QRCodeException}; use chillerlan\Settings\SettingsContainerInterface; use Exception; -use function array_values, base64_encode, call_user_func, count, imagecolorallocate, imagecolortransparent, +use function array_values, base64_encode, call_user_func, count, extension_loaded, imagecolorallocate, imagecolortransparent, imagecreatetruecolor, imagedestroy, imagefilledrectangle, imagegif, imagejpeg, imagepng, in_array, is_array, ob_end_clean, ob_get_contents, ob_start, range, sprintf; /** - * Converts the matrix into GD images, raw or base64 output - * requires ext-gd - * @link http://php.net/manual/book.image.php + * Converts the matrix into GD images, raw or base64 output (requires ext-gd) + * + * @see http://php.net/manual/book.image.php */ class QRImage extends QROutputAbstract{ + /** + * GD image types that support transparency + * + * @var string[] + */ protected const TRANSPARENCY_TYPES = [ QRCode::OUTPUT_IMAGE_PNG, QRCode::OUTPUT_IMAGE_GIF, ]; - /** - * @var string - */ - protected $defaultMode = QRCode::OUTPUT_IMAGE_PNG; + protected string $defaultMode = QRCode::OUTPUT_IMAGE_PNG; /** + * The GD image resource + * * @see imagecreatetruecolor() - * @var resource + * @var resource|\GdImage + * + * @phan-suppress PhanUndeclaredTypeProperty */ protected $image; @@ -84,15 +90,20 @@ class QRImage extends QROutputAbstract{ /** * @inheritDoc * - * @return string|resource + * @return string|resource|\GdImage + * + * @phan-suppress PhanUndeclaredTypeReturnType, PhanTypeMismatchReturn */ public function dump(string $file = null){ + $file ??= $this->options->cachefile; + $this->image = imagecreatetruecolor($this->length, $this->length); // avoid: Indirect modification of overloaded property $imageTransparencyBG has no effect // https://stackoverflow.com/a/10455217 - $tbg = $this->options->imageTransparencyBG; - $background = imagecolorallocate($this->image, ...$tbg); + $tbg = $this->options->imageTransparencyBG; + /** @phan-suppress-next-line PhanParamTooFewInternalUnpack */ + $background = imagecolorallocate($this->image, ...$tbg); if((bool)$this->options->imageTransparent && in_array($this->options->outputType, $this::TRANSPARENCY_TYPES, true)){ imagecolortransparent($this->image, $background); @@ -110,7 +121,11 @@ class QRImage extends QROutputAbstract{ return $this->image; } - $imageData = $this->dumpImage($file); + $imageData = $this->dumpImage(); + + if($file !== null){ + $this->saveToFile($imageData, $file); + } if($this->options->imageBase64){ $imageData = sprintf('data:image/%s;base64,%s', $this->options->outputType, base64_encode($imageData)); @@ -120,11 +135,7 @@ class QRImage extends QROutputAbstract{ } /** - * @param int $x - * @param int $y - * @param array $rgb - * - * @return void + * Creates a single QR pixel with the given settings */ protected function setPixel(int $x, int $y, array $rgb):void{ imagefilledrectangle( @@ -133,20 +144,17 @@ class QRImage extends QROutputAbstract{ $y * $this->scale, ($x + 1) * $this->scale, ($y + 1) * $this->scale, + /** @phan-suppress-next-line PhanParamTooFewInternalUnpack */ imagecolorallocate($this->image, ...$rgb) ); } /** - * @param string|null $file + * Creates the final image by calling the desired GD output function * - * @return string - * @throws \chillerlan\QRCode\Output\QRCodeOutputException */ - protected function dumpImage(string $file = null):string{ - $file = $file ?? $this->options->cachefile; - + protected function dumpImage():string{ ob_start(); try{ @@ -164,14 +172,12 @@ class QRImage extends QROutputAbstract{ ob_end_clean(); - if($file !== null){ - $this->saveToFile($imageData, $file); - } - return $imageData; } /** + * PNG output + * * @return void */ protected function png():void{ @@ -186,6 +192,7 @@ class QRImage extends QROutputAbstract{ /** * Jiff - like... JitHub! + * * @return void */ protected function gif():void{ @@ -193,6 +200,8 @@ class QRImage extends QROutputAbstract{ } /** + * JPG output + * * @return void */ protected function jpg():void{ diff --git a/vendor/chillerlan/php-qrcode/src/Output/QRImagick.php b/vendor/chillerlan/php-qrcode/src/Output/QRImagick.php index 03886cf3b..49516d30e 100644 --- a/vendor/chillerlan/php-qrcode/src/Output/QRImagick.php +++ b/vendor/chillerlan/php-qrcode/src/Output/QRImagick.php @@ -19,24 +19,20 @@ use chillerlan\QRCode\QRCodeException; use chillerlan\Settings\SettingsContainerInterface; use Imagick, ImagickDraw, ImagickPixel; -use function is_string; +use function extension_loaded, is_string; /** - * ImageMagick output module - * requires ext-imagick - * @link http://php.net/manual/book.imagick.php - * @link http://phpimagick.com + * ImageMagick output module (requires ext-imagick) + * + * @see http://php.net/manual/book.imagick.php + * @see http://phpimagick.com */ class QRImagick extends QROutputAbstract{ - /** - * @var \Imagick - */ - protected $imagick; + protected Imagick $imagick; /** * @inheritDoc - * @throws \chillerlan\QRCode\QRCodeException */ public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){ @@ -72,7 +68,7 @@ class QRImagick extends QROutputAbstract{ * @return string|\Imagick */ public function dump(string $file = null){ - $file = $file ?? $this->options->cachefile; + $file ??= $this->options->cachefile; $this->imagick = new Imagick; $this->imagick->newImage( @@ -98,7 +94,7 @@ class QRImagick extends QROutputAbstract{ } /** - * @return void + * Creates the QR image via ImagickDraw */ protected function drawImage():void{ $draw = new ImagickDraw; diff --git a/vendor/chillerlan/php-qrcode/src/Output/QRMarkup.php b/vendor/chillerlan/php-qrcode/src/Output/QRMarkup.php index 15559dae0..06d6e88cb 100644 --- a/vendor/chillerlan/php-qrcode/src/Output/QRMarkup.php +++ b/vendor/chillerlan/php-qrcode/src/Output/QRMarkup.php @@ -21,17 +21,13 @@ use function is_string, sprintf, strip_tags, trim; */ class QRMarkup extends QROutputAbstract{ - /** - * @var string - */ - protected $defaultMode = QRCode::OUTPUT_MARKUP_SVG; + protected string $defaultMode = QRCode::OUTPUT_MARKUP_SVG; /** * @see \sprintf() - * - * @var string */ - protected $svgHeader = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="qr-svg %1$s" style="width: 100%%; height: auto;" viewBox="0 0 %2$d %2$d">'; + protected string $svgHeader = '<svg xmlns="http://www.w3.org/2000/svg" class="qr-svg %1$s" '. + 'style="width: 100%%; height: auto;" viewBox="0 0 %2$d %2$d">'; /** * @inheritDoc @@ -55,10 +51,15 @@ class QRMarkup extends QROutputAbstract{ } /** - * @return string + * HTML output */ - protected function html():string{ - $html = '<div class="'.$this->options->cssClass.'">'.$this->options->eol; + protected function html(string $file = null):string{ + + $html = empty($this->options->cssClass) + ? '<div>' + : '<div class="'.$this->options->cssClass.'">'; + + $html .= $this->options->eol; foreach($this->matrix->matrix() as $row){ $html .= '<div>'; @@ -72,19 +73,21 @@ class QRMarkup extends QROutputAbstract{ $html .= '</div>'.$this->options->eol; - if($this->options->cachefile){ - return '<!DOCTYPE html><head><meta charset="UTF-8"></head><body>'.$this->options->eol.$html.'</body>'; + if($file !== null){ + return '<!DOCTYPE html>'. + '<head><meta charset="UTF-8"><title>QR Code</title></head>'. + '<body>'.$this->options->eol.$html.'</body>'; } return $html; } /** - * @link https://github.com/codemasher/php-qrcode/pull/5 + * SVG output * - * @return string + * @see https://github.com/codemasher/php-qrcode/pull/5 */ - protected function svg():string{ + protected function svg(string $file = null):string{ $matrix = $this->matrix->matrix(); $svg = sprintf($this->svgHeader, $this->options->cssClass, $this->options->svgViewBoxSize ?? $this->moduleCount) @@ -115,7 +118,9 @@ class QRMarkup extends QROutputAbstract{ } if($count > 0){ - $len = $count; + $len = $count; + $start ??= 0; // avoid type coercion in sprintf() - phan happy + $path .= sprintf('M%s %s h%s v1 h-%sZ ', $start, $y, $len, $len); // reset count @@ -128,7 +133,10 @@ class QRMarkup extends QROutputAbstract{ } if(!empty($path)){ - $svg .= sprintf('<path class="qr-%s %s" stroke="transparent" fill="%s" fill-opacity="%s" d="%s" />', $M_TYPE, $this->options->cssClass, $value, $this->options->svgOpacity, $path); + $svg .= sprintf( + '<path class="qr-%s %s" stroke="transparent" fill="%s" fill-opacity="%s" d="%s" />', + $M_TYPE, $this->options->cssClass, $value, $this->options->svgOpacity, $path + ); } } @@ -137,8 +145,9 @@ class QRMarkup extends QROutputAbstract{ $svg .= '</svg>'.$this->options->eol; // if saving to file, append the correct headers - if($this->options->cachefile){ - return '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'.$this->options->eol.$svg; + if($file !== null){ + return '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'. + $this->options->eol.$svg; } if($this->options->imageBase64){ diff --git a/vendor/chillerlan/php-qrcode/src/Output/QROutputAbstract.php b/vendor/chillerlan/php-qrcode/src/Output/QROutputAbstract.php index 4ec47de24..d4ed3d0c9 100644 --- a/vendor/chillerlan/php-qrcode/src/Output/QROutputAbstract.php +++ b/vendor/chillerlan/php-qrcode/src/Output/QROutputAbstract.php @@ -15,7 +15,7 @@ namespace chillerlan\QRCode\Output; use chillerlan\QRCode\{Data\QRMatrix, QRCode}; use chillerlan\Settings\SettingsContainerInterface; -use function call_user_func, dirname, file_put_contents, get_called_class, in_array, is_writable, sprintf; +use function call_user_func_array, dirname, file_put_contents, get_called_class, in_array, is_writable, sprintf; /** * common output abstract @@ -23,50 +23,53 @@ use function call_user_func, dirname, file_put_contents, get_called_class, in_ar abstract class QROutputAbstract implements QROutputInterface{ /** - * @var int + * the current size of the QR matrix + * + * @see \chillerlan\QRCode\Data\QRMatrix::size() */ - protected $moduleCount; + protected int $moduleCount; /** - * @param \chillerlan\QRCode\Data\QRMatrix $matrix + * the current output mode + * + * @see \chillerlan\QRCode\QROptions::$outputType */ - protected $matrix; + protected string $outputMode; /** - * @var \chillerlan\QRCode\QROptions + * the default output mode of the current output module */ - protected $options; + protected string $defaultMode; /** - * @var string + * the current scaling for a QR pixel + * + * @see \chillerlan\QRCode\QROptions::$scale */ - protected $outputMode; + protected int $scale; /** - * @var string; + * the side length of the QR image (modules * scale) */ - protected $defaultMode; + protected int $length; /** - * @var int + * an (optional) array of color values for the several QR matrix parts */ - protected $scale; + protected array $moduleValues; /** - * @var int + * the (filled) data matrix object */ - protected $length; + protected QRMatrix $matrix; /** - * @var array + * @var \chillerlan\Settings\SettingsContainerInterface|\chillerlan\QRCode\QROptions */ - protected $moduleValues; + protected SettingsContainerInterface $options; /** * QROutputAbstract constructor. - * - * @param \chillerlan\Settings\SettingsContainerInterface $options - * @param \chillerlan\QRCode\Data\QRMatrix $matrix */ public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){ $this->options = $options; @@ -86,8 +89,6 @@ abstract class QROutputAbstract implements QROutputInterface{ /** * Sets the initial module values (clean-up & defaults) - * - * @return void */ abstract protected function setModuleValues():void; @@ -97,10 +98,6 @@ abstract class QROutputAbstract implements QROutputInterface{ * @see file_put_contents() * @see \chillerlan\QRCode\QROptions::cachefile * - * @param string $data - * @param string $file - * - * @return bool * @throws \chillerlan\QRCode\Output\QRCodeOutputException */ protected function saveToFile(string $data, string $file):bool{ @@ -116,9 +113,11 @@ abstract class QROutputAbstract implements QROutputInterface{ * @inheritDoc */ public function dump(string $file = null){ - // call the built-in output method - $data = call_user_func([$this, $this->outputMode ?? $this->defaultMode]); - $file = $file ?? $this->options->cachefile; + $file ??= $this->options->cachefile; + + // call the built-in output method with the optional file path as parameter + // to make the called method aware if a cache file was given + $data = call_user_func_array([$this, $this->outputMode ?? $this->defaultMode], [$file]); if($file !== null){ $this->saveToFile($data, $file); diff --git a/vendor/chillerlan/php-qrcode/src/Output/QROutputInterface.php b/vendor/chillerlan/php-qrcode/src/Output/QROutputInterface.php index d9149b0f7..b07b8e7a5 100644 --- a/vendor/chillerlan/php-qrcode/src/Output/QROutputInterface.php +++ b/vendor/chillerlan/php-qrcode/src/Output/QROutputInterface.php @@ -21,6 +21,7 @@ interface QROutputInterface{ const DEFAULT_MODULE_VALUES = [ // light + QRMatrix::M_NULL => false, // 0 QRMatrix::M_DATA => false, // 4 QRMatrix::M_FINDER => false, // 6 QRMatrix::M_SEPARATOR => false, // 8 @@ -46,8 +47,6 @@ interface QROutputInterface{ /** * generates the output, optionally dumps it to a file, and returns it * - * @param string|null $file - * * @return mixed */ public function dump(string $file = null); diff --git a/vendor/chillerlan/php-qrcode/src/Output/QRString.php b/vendor/chillerlan/php-qrcode/src/Output/QRString.php index ba8d83675..3ed5153e1 100644 --- a/vendor/chillerlan/php-qrcode/src/Output/QRString.php +++ b/vendor/chillerlan/php-qrcode/src/Output/QRString.php @@ -8,6 +8,9 @@ * @author Smiley <[email protected]> * @copyright 2015 Smiley * @license MIT + * + * @noinspection PhpUnusedParameterInspection + * @noinspection PhpComposerExtensionStubsInspection */ namespace chillerlan\QRCode\Output; @@ -21,10 +24,7 @@ use function implode, is_string, json_encode; */ class QRString extends QROutputAbstract{ - /** - * @var string - */ - protected $defaultMode = QRCode::OUTPUT_STRING_TEXT; + protected string $defaultMode = QRCode::OUTPUT_STRING_TEXT; /** * @inheritDoc @@ -48,9 +48,9 @@ class QRString extends QROutputAbstract{ } /** - * @return string + * string output */ - protected function text():string{ + protected function text(string $file = null):string{ $str = []; foreach($this->matrix->matrix() as $row){ @@ -67,9 +67,9 @@ class QRString extends QROutputAbstract{ } /** - * @return string + * JSON output */ - protected function json():string{ + protected function json(string $file = null):string{ return json_encode($this->matrix->matrix()); } |