From 6d8ccee5167383d67a9e5d188b96ed9360551260 Mon Sep 17 00:00:00 2001 From: codemasher Date: Tue, 6 Aug 2019 22:55:47 +0200 Subject: [PATCH 01/11] :octocat: shameless advertising --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 025279339..6385c7718 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,10 @@ namespaced, cleaned up, improved and other stuff. [donate-badge]: https://img.shields.io/badge/donate-paypal-ff33aa.svg?style=flat-square [donate]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WLYUNAT9ZTJZ4 +- [php-oauth-core](https://github.com/chillerlan/php-oauth-core) - an OAuth 1/2 client library along with a bunch of [providers](https://github.com/chillerlan/php-oauth-providers) +- [php-httpinterface](https://github.com/chillerlan/php-httpinterface) - a PSR-7/15/17/18 implemetation +- [php-database](https://github.com/chillerlan/php-database) - a database client & querybuilder for MySQL, Postgres, SQLite, MSSQL, Firebird + ## Documentation ### Installation From 4bf2b09a9133e6df154c84e173e38049d65d6748 Mon Sep 17 00:00:00 2001 From: codemasher Date: Tue, 6 Aug 2019 22:56:48 +0200 Subject: [PATCH 02/11] :octocat: --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6385c7718..745dd0e25 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ namespaced, cleaned up, improved and other stuff. [donate-badge]: https://img.shields.io/badge/donate-paypal-ff33aa.svg?style=flat-square [donate]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WLYUNAT9ZTJZ4 +Hi, please check out my other projects that are way cooler than qrcodes! + - [php-oauth-core](https://github.com/chillerlan/php-oauth-core) - an OAuth 1/2 client library along with a bunch of [providers](https://github.com/chillerlan/php-oauth-providers) - [php-httpinterface](https://github.com/chillerlan/php-httpinterface) - a PSR-7/15/17/18 implemetation - [php-database](https://github.com/chillerlan/php-database) - a database client & querybuilder for MySQL, Postgres, SQLite, MSSQL, Firebird From 9b0018524bdb7a4416293caeef076cc3be75118d Mon Sep 17 00:00:00 2001 From: codemasher Date: Fri, 9 Aug 2019 18:18:46 +0200 Subject: [PATCH 03/11] :octocat: PHPUnit 8.3 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c07a8b0ed..febcc749a 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "chillerlan/php-settings-container": "^1.1" }, "require-dev": { - "phpunit/phpunit": "^8.0" + "phpunit/phpunit": "^8.3" }, "suggest": { "chillerlan/php-authenticator": "^3.0" From adb1230e10732b2d07eed404e5eab75ec20dd7bf Mon Sep 17 00:00:00 2001 From: codemasher Date: Fri, 9 Aug 2019 18:31:02 +0200 Subject: [PATCH 04/11] :octocat: replace __set() with setters for SettingsContainerInterface --- src/QROptionsTrait.php | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/src/QROptionsTrait.php b/src/QROptionsTrait.php index a1d7fcfe0..a18354968 100644 --- a/src/QROptionsTrait.php +++ b/src/QROptionsTrait.php @@ -239,30 +239,6 @@ trait QROptionsTrait{ */ protected $moduleValues; - /** - * set/clamp some special values, call the parent setter otherwise - * - * @param string $property - * @param mixed $value - * - * @return void - */ - public function __set(string $property, $value):void{ - - if($property === 'versionMin'){ - $this->setMinMaxVersion($value, $this->versionMax); - - return; - } - elseif($property === 'versionMax'){ - $this->setMinMaxVersion($this->versionMin, $value); - - return; - } - - parent::__set($property, $value); - } - /** * clamp min/max version number * @@ -279,6 +255,24 @@ trait QROptionsTrait{ $this->versionMax = \max($min, $max); } + /** + * @param int $version + * + * @return void + */ + protected function set_versionMin(int $version):void{ + $this->setMinMaxVersion($version, $this->versionMax); + } + + /** + * @param int $version + * + * @return void + */ + protected function set_versionMax(int $version):void{ + $this->setMinMaxVersion($this->versionMin, $version); + } + /** * @param int $eccLevel * From 2905bee4702c22993915c36a47ec30a7433211c4 Mon Sep 17 00:00:00 2001 From: codemasher Date: Fri, 9 Aug 2019 19:34:55 +0200 Subject: [PATCH 05/11] :octocat: +ext-gd --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index febcc749a..b65135d39 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ ], "require": { "php": "^7.2", + "ext-gd": "*", "ext-json": "*", "ext-mbstring": "*", "chillerlan/php-settings-container": "^1.1" From 42244afddaf687f7286434f4ce0d5f9ce668c707 Mon Sep 17 00:00:00 2001 From: codemasher Date: Fri, 9 Aug 2019 20:18:46 +0200 Subject: [PATCH 06/11] :octocat: use function (could've done that before...) --- src/Data/AlphaNum.php | 6 +++-- src/Data/Byte.php | 4 ++- src/Data/Kanji.php | 8 +++--- src/Data/MaskPatternTester.php | 6 +++-- src/Data/Number.php | 8 +++--- src/Data/QRDataAbstract.php | 29 ++++++++++---------- src/Data/QRMatrix.php | 28 +++++++++++--------- src/Helpers/BitBuffer.php | 6 +++-- src/Helpers/Polynomial.php | 10 ++++--- src/Output/QRImage.php | 47 ++++++++++++++++++--------------- src/Output/QRImagick.php | 2 ++ src/Output/QRMarkup.php | 8 +++--- src/Output/QROutputAbstract.php | 10 ++++--- src/Output/QRString.php | 8 +++--- src/QRCode.php | 24 +++++++++-------- src/QROptionsTrait.php | 22 ++++++++------- 16 files changed, 130 insertions(+), 96 deletions(-) diff --git a/src/Data/AlphaNum.php b/src/Data/AlphaNum.php index f3ad0dbb8..95070a16f 100644 --- a/src/Data/AlphaNum.php +++ b/src/Data/AlphaNum.php @@ -14,6 +14,8 @@ namespace chillerlan\QRCode\Data; use chillerlan\QRCode\QRCode; +use function array_search, ord; + /** * Alphanumeric mode: 0 to 9, A to Z, space, $ % * + - . / : */ @@ -51,13 +53,13 @@ class AlphaNum extends QRDataAbstract{ * @throws \chillerlan\QRCode\Data\QRCodeDataException */ protected function getCharCode(string $chr):int{ - $i = \array_search($chr, $this::ALPHANUM_CHAR_MAP); + $i = array_search($chr, $this::ALPHANUM_CHAR_MAP); if($i !== false){ return $i; } - throw new QRCodeDataException('illegal char: "'.$chr.'" ['.\ord($chr).']'); + throw new QRCodeDataException('illegal char: "'.$chr.'" ['.ord($chr).']'); } } diff --git a/src/Data/Byte.php b/src/Data/Byte.php index bb5f33d1b..f1955645a 100644 --- a/src/Data/Byte.php +++ b/src/Data/Byte.php @@ -14,6 +14,8 @@ namespace chillerlan\QRCode\Data; use chillerlan\QRCode\QRCode; +use function ord; + /** * Byte mode, ISO-8859-1 or UTF-8 */ @@ -36,7 +38,7 @@ class Byte extends QRDataAbstract{ $i = 0; while($i < $this->strlen){ - $this->bitBuffer->put(\ord($data[$i]), 8); + $this->bitBuffer->put(ord($data[$i]), 8); $i++; } diff --git a/src/Data/Kanji.php b/src/Data/Kanji.php index e5c01dfaa..139b7d1a1 100644 --- a/src/Data/Kanji.php +++ b/src/Data/Kanji.php @@ -14,6 +14,8 @@ namespace chillerlan\QRCode\Data; use chillerlan\QRCode\QRCode; +use function mb_strlen, ord, strlen; + /** * Kanji mode: double-byte characters from the Shift JIS character set */ @@ -33,7 +35,7 @@ class Kanji extends QRDataAbstract{ * @inheritdoc */ protected function getLength(string $data):int{ - return \mb_strlen($data, 'SJIS'); + return mb_strlen($data, 'SJIS'); } /** @@ -43,10 +45,10 @@ class Kanji extends QRDataAbstract{ * @throws \chillerlan\QRCode\Data\QRCodeDataException */ protected function write(string $data):void{ - $len = \strlen($data); + $len = strlen($data); for($i = 0; $i + 1 < $len; $i += 2){ - $c = ((0xff & \ord($data[$i])) << 8) | (0xff & \ord($data[$i + 1])); + $c = ((0xff & ord($data[$i])) << 8) | (0xff & ord($data[$i + 1])); if(0x8140 <= $c && $c <= 0x9FFC){ $c -= 0x8140; diff --git a/src/Data/MaskPatternTester.php b/src/Data/MaskPatternTester.php index 1a91de8ed..c2a87205c 100644 --- a/src/Data/MaskPatternTester.php +++ b/src/Data/MaskPatternTester.php @@ -12,6 +12,8 @@ namespace chillerlan\QRCode\Data; +use function abs, call_user_func; + /** * The sole purpose of this class is to receive a QRMatrix object and run the pattern tests on it. * @@ -56,7 +58,7 @@ class MaskPatternTester{ $penalty = 0; for($level = 1; $level <= 4; $level++){ - $penalty += \call_user_func([$this, 'testLevel'.$level]); + $penalty += call_user_func([$this, 'testLevel'.$level]); } return (int)$penalty; @@ -212,7 +214,7 @@ class MaskPatternTester{ } } - return (\abs(100 * $count / $this->moduleCount / $this->moduleCount - 50) / 5) * 10; + return (abs(100 * $count / $this->moduleCount / $this->moduleCount - 50) / 5) * 10; } } diff --git a/src/Data/Number.php b/src/Data/Number.php index fc21a0029..a6ba0545a 100644 --- a/src/Data/Number.php +++ b/src/Data/Number.php @@ -14,6 +14,8 @@ namespace chillerlan\QRCode\Data; use chillerlan\QRCode\QRCode; +use function substr; + /** * Numeric mode: decimal digits 0 through 9 */ @@ -36,18 +38,18 @@ class Number extends QRDataAbstract{ $i = 0; while($i + 2 < $this->strlen){ - $this->bitBuffer->put($this->parseInt(\substr($data, $i, 3)), 10); + $this->bitBuffer->put($this->parseInt(substr($data, $i, 3)), 10); $i += 3; } if($i < $this->strlen){ if($this->strlen - $i === 1){ - $this->bitBuffer->put($this->parseInt(\substr($data, $i, $i + 1)), 4); + $this->bitBuffer->put($this->parseInt(substr($data, $i, $i + 1)), 4); } // @codeCoverageIgnoreStart elseif($this->strlen - $i === 2){ - $this->bitBuffer->put($this->parseInt(\substr($data, $i, $i + 2)), 7); + $this->bitBuffer->put($this->parseInt(substr($data, $i, $i + 2)), 7); } // @codeCoverageIgnoreEnd diff --git a/src/Data/QRDataAbstract.php b/src/Data/QRDataAbstract.php index a26b4c0b9..307802c53 100644 --- a/src/Data/QRDataAbstract.php +++ b/src/Data/QRDataAbstract.php @@ -16,6 +16,8 @@ use chillerlan\QRCode\{QRCode, QRCodeException}; use chillerlan\QRCode\Helpers\{BitBuffer, Polynomial}; use chillerlan\Settings\SettingsContainerInterface; +use function array_fill, array_merge, count, max, range, strlen; + /** * Processes the binary data and maps it on a matrix which is then being returned */ @@ -169,7 +171,7 @@ abstract class QRDataAbstract implements QRDataInterface{ * @return int */ protected function getLength(string $data):int{ - return \strlen($data); + return strlen($data); } /** @@ -182,7 +184,7 @@ abstract class QRDataAbstract implements QRDataInterface{ $maxlength = 0; // guess the version number within the given range - foreach(\range($this->options->versionMin, $this->options->versionMax) as $version){ + foreach(range($this->options->versionMin, $this->options->versionMax) as $version){ $maxlength = $this::MAX_LENGTH[$version][QRCode::DATA_MODES[$this->datamode]][QRCode::ECC_MODES[$this->options->eccLevel]]; if($this->strlen <= $maxlength){ @@ -213,7 +215,6 @@ abstract class QRDataAbstract implements QRDataInterface{ protected function writeBitBuffer(string $data):QRDataInterface{ $this->bitBuffer = new BitBuffer; - // @todo: fixme, get real length $MAX_BITS = $this::MAX_BITS[$this->version][QRCode::ECC_MODES[$this->options->eccLevel]]; $this->bitBuffer @@ -270,13 +271,13 @@ abstract class QRDataAbstract implements QRDataInterface{ protected function maskECC():array{ [$l1, $l2, $b1, $b2] = $this::RSBLOCKS[$this->version][QRCode::ECC_MODES[$this->options->eccLevel]]; - $rsBlocks = \array_fill(0, $l1, [$b1, $b2]); + $rsBlocks = array_fill(0, $l1, [$b1, $b2]); $rsCount = $l1 + $l2; - $this->ecdata = \array_fill(0, $rsCount, null); + $this->ecdata = array_fill(0, $rsCount, null); $this->dcdata = $this->ecdata; if($l2 > 0){ - $rsBlocks = \array_merge($rsBlocks, \array_fill(0, $l2, [$b1 + 1, $b2 + 1])); + $rsBlocks = array_merge($rsBlocks, array_fill(0, $l2, [$b1 + 1, $b2 + 1])); } $totalCodeCount = 0; @@ -288,9 +289,9 @@ abstract class QRDataAbstract implements QRDataInterface{ [$rsBlockTotal, $dcCount] = $block; $ecCount = $rsBlockTotal - $dcCount; - $maxDcCount = \max($maxDcCount, $dcCount); - $maxEcCount = \max($maxEcCount, $ecCount); - $this->dcdata[$key] = \array_fill(0, $dcCount, null); + $maxDcCount = max($maxDcCount, $dcCount); + $maxEcCount = max($maxEcCount, $ecCount); + $this->dcdata[$key] = array_fill(0, $dcCount, null); foreach($this->dcdata[$key] as $a => $_z){ $this->dcdata[$key][$a] = 0xff & $this->bitBuffer->buffer[$a + $offset]; @@ -307,13 +308,13 @@ abstract class QRDataAbstract implements QRDataInterface{ $totalCodeCount += $rsBlockTotal; } - $data = \array_fill(0, $totalCodeCount, null); + $data = array_fill(0, $totalCodeCount, null); $index = 0; $mask = function($arr, $count) use (&$data, &$index, $rsCount){ for($x = 0; $x < $count; $x++){ for($y = 0; $y < $rsCount; $y++){ - if($x < \count($arr[$y])){ + if($x < count($arr[$y])){ $data[$index] = $arr[$y][$x]; $index++; } @@ -342,19 +343,19 @@ abstract class QRDataAbstract implements QRDataInterface{ $rsPoly->multiply($modPoly->getNum()); } - $rsPolyCount = \count($rsPoly->getNum()); + $rsPolyCount = count($rsPoly->getNum()); $modPoly ->setNum($this->dcdata[$key], $rsPolyCount - 1) ->mod($rsPoly->getNum()) ; - $this->ecdata[$key] = \array_fill(0, $rsPolyCount - 1, null); + $this->ecdata[$key] = array_fill(0, $rsPolyCount - 1, null); $num = $modPoly->getNum(); return [ $num, - \count($num) - \count($this->ecdata[$key]), + count($num) - count($this->ecdata[$key]), ]; } diff --git a/src/Data/QRMatrix.php b/src/Data/QRMatrix.php index 9ea5ac7c4..75d9e066e 100755 --- a/src/Data/QRMatrix.php +++ b/src/Data/QRMatrix.php @@ -14,6 +14,8 @@ namespace chillerlan\QRCode\Data; use chillerlan\QRCode\QRCode; +use function array_fill, array_key_exists, array_push, array_unshift, count, floor, in_array, max, min, range; + /** * @link http://www.thonky.com/qr-code-tutorial/format-version-information */ @@ -202,18 +204,18 @@ class QRMatrix{ */ public function __construct(int $version, int $eclevel){ - if(!\in_array($version, \range(1, 40), true)){ + if(!in_array($version, range(1, 40), true)){ throw new QRCodeDataException('invalid QR Code version'); } - if(!\array_key_exists($eclevel, QRCode::ECC_MODES)){ + if(!array_key_exists($eclevel, QRCode::ECC_MODES)){ throw new QRCodeDataException('invalid ecc level'); } $this->version = $version; $this->eclevel = $eclevel; $this->moduleCount = $this->version * 4 + 17; - $this->matrix = \array_fill(0, $this->moduleCount, \array_fill(0, $this->moduleCount, $this::M_NULL)); + $this->matrix = array_fill(0, $this->moduleCount, array_fill(0, $this->moduleCount, $this::M_NULL)); } /** @@ -412,7 +414,7 @@ class QRMatrix{ */ public function setTimingPattern():QRMatrix{ - foreach(\range(8, $this->moduleCount - 8 - 1) as $i){ + foreach(range(8, $this->moduleCount - 8 - 1) as $i){ if($this->matrix[6][$i] !== $this::M_NULL || $this->matrix[$i][6] !== $this::M_NULL){ continue; @@ -440,7 +442,7 @@ class QRMatrix{ if($bits !== false){ for($i = 0; $i < 18; $i++){ - $a = (int)\floor($i / 3); + $a = (int)floor($i / 3); $b = $i % 3 + $this->moduleCount - 8 - 3; $v = !$test && (($bits >> $i) & 1) === 1; @@ -509,23 +511,23 @@ class QRMatrix{ } $size = $size !== null - ? \max(0, \min($size, \floor($this->moduleCount / 2))) + ? max(0, min($size, floor($this->moduleCount / 2))) : 4; for($y = 0; $y < $this->moduleCount; $y++){ for($i = 0; $i < $size; $i++){ - \array_unshift($this->matrix[$y], $this::M_QUIETZONE); - \array_push($this->matrix[$y], $this::M_QUIETZONE); + array_unshift($this->matrix[$y], $this::M_QUIETZONE); + array_push($this->matrix[$y], $this::M_QUIETZONE); } } $this->moduleCount += ($size * 2); - $r = \array_fill(0, $this->moduleCount, $this::M_QUIETZONE); + $r = array_fill(0, $this->moduleCount, $this::M_QUIETZONE); for($i = 0; $i < $size; $i++){ - \array_unshift($this->matrix, $r); - \array_push($this->matrix, $r); + array_unshift($this->matrix, $r); + array_push($this->matrix, $r); } return $this; @@ -543,7 +545,7 @@ class QRMatrix{ */ public function mapData(array $data, int $maskPattern):QRMatrix{ $this->maskPattern = $maskPattern; - $byteCount = \count($data); + $byteCount = count($data); $size = $this->moduleCount - 1; for($i = $size, $y = $size, $inc = -1, $byteIndex = 0, $bitIndex = 7; $i > 0; $i -= 2){ @@ -616,7 +618,7 @@ class QRMatrix{ $y % 2, $x % 3, $a % 3, - (\floor($y / 2) + \floor($x / 3)) % 2, + (floor($y / 2) + floor($x / 3)) % 2, $m % 2 + $m % 3, ($m % 2 + $m % 3) % 2, ($m % 3 + $a % 2) % 2 diff --git a/src/Helpers/BitBuffer.php b/src/Helpers/BitBuffer.php index cd35fd60e..25ef80cc6 100644 --- a/src/Helpers/BitBuffer.php +++ b/src/Helpers/BitBuffer.php @@ -12,6 +12,8 @@ namespace chillerlan\QRCode\Helpers; +use function count, floor; + class BitBuffer{ /** @@ -55,9 +57,9 @@ class BitBuffer{ * @return \chillerlan\QRCode\Helpers\BitBuffer */ public function putBit(bool $bit):BitBuffer{ - $bufIndex = \floor($this->length / 8); + $bufIndex = floor($this->length / 8); - if(\count($this->buffer) <= $bufIndex){ + if(count($this->buffer) <= $bufIndex){ $this->buffer[] = 0; } diff --git a/src/Helpers/Polynomial.php b/src/Helpers/Polynomial.php index e032dab87..e0032f95c 100644 --- a/src/Helpers/Polynomial.php +++ b/src/Helpers/Polynomial.php @@ -14,6 +14,8 @@ namespace chillerlan\QRCode\Helpers; use chillerlan\QRCode\QRCodeException; +use function array_fill, count; + /** * @link http://www.thonky.com/qr-code-tutorial/error-correction-coding */ @@ -87,13 +89,13 @@ class Polynomial{ */ public function setNum(array $num, int $shift = null):Polynomial{ $offset = 0; - $numCount = \count($num); + $numCount = count($num); while($offset < $numCount && $num[$offset] === 0){ $offset++; } - $this->num = \array_fill(0, $numCount - $offset + ($shift ?? 0), 0); + $this->num = array_fill(0, $numCount - $offset + ($shift ?? 0), 0); for($i = 0; $i < $numCount - $offset; $i++){ $this->num[$i] = $num[$i + $offset]; @@ -108,7 +110,7 @@ class Polynomial{ * @return \chillerlan\QRCode\Helpers\Polynomial */ public function multiply(array $e):Polynomial{ - $n = \array_fill(0, \count($this->num) + \count($e) - 1, 0); + $n = array_fill(0, count($this->num) + count($e) - 1, 0); foreach($this->num as $i => $vi){ $vi = $this->glog($vi); @@ -132,7 +134,7 @@ class Polynomial{ public function mod(array $e):Polynomial{ $n = $this->num; - if(\count($n) - \count($e) < 0){ + if(count($n) - count($e) < 0){ return $this; } diff --git a/src/Output/QRImage.php b/src/Output/QRImage.php index 52531e144..e5d62f677 100644 --- a/src/Output/QRImage.php +++ b/src/Output/QRImage.php @@ -13,6 +13,11 @@ namespace chillerlan\QRCode\Output; use chillerlan\QRCode\QRCode; +use Exception; + +use function array_values, base64_encode, call_user_func, count, imagecolorallocate, imagecolortransparent, + imagecreatetruecolor, imagedestroy, imagefilledrectangle, imagegif, imagejpeg, imagepng, in_array, + is_array, ob_end_clean, ob_get_contents, ob_start, range; /** * Converts the matrix into GD images, raw or base64 output @@ -45,13 +50,13 @@ class QRImage extends QROutputAbstract{ foreach($this::DEFAULT_MODULE_VALUES as $M_TYPE => $defaultValue){ $v = $this->options->moduleValues[$M_TYPE] ?? null; - if(!\is_array($v) || \count($v) < 3){ + if(!is_array($v) || count($v) < 3){ $this->moduleValues[$M_TYPE] = $defaultValue ? [0, 0, 0] : [255, 255, 255]; } else{ - $this->moduleValues[$M_TYPE] = \array_values($v); + $this->moduleValues[$M_TYPE] = array_values($v); } } @@ -64,18 +69,18 @@ class QRImage extends QROutputAbstract{ * @return string */ public function dump(string $file = null):string{ - $this->image = \imagecreatetruecolor($this->length, $this->length); + $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); + $background = imagecolorallocate($this->image, ...$tbg); - if((bool)$this->options->imageTransparent && \in_array($this->options->outputType, $this::TRANSPARENCY_TYPES, true)){ - \imagecolortransparent($this->image, $background); + if((bool)$this->options->imageTransparent && in_array($this->options->outputType, $this::TRANSPARENCY_TYPES, true)){ + imagecolortransparent($this->image, $background); } - \imagefilledrectangle($this->image, 0, 0, $this->length, $this->length, $background); + imagefilledrectangle($this->image, 0, 0, $this->length, $this->length, $background); foreach($this->matrix->matrix() as $y => $row){ foreach($row as $x => $M_TYPE){ @@ -86,7 +91,7 @@ class QRImage extends QROutputAbstract{ $imageData = $this->dumpImage($file); if((bool)$this->options->imageBase64){ - $imageData = 'data:image/'.$this->options->outputType.';base64,'.\base64_encode($imageData); + $imageData = 'data:image/'.$this->options->outputType.';base64,'.base64_encode($imageData); } return $imageData; @@ -100,13 +105,13 @@ class QRImage extends QROutputAbstract{ * @return void */ protected function setPixel(int $x, int $y, array $rgb):void{ - \imagefilledrectangle( + imagefilledrectangle( $this->image, $x * $this->scale, $y * $this->scale, ($x + 1) * $this->scale, ($y + 1) * $this->scale, - \imagecolorallocate($this->image, ...$rgb) + imagecolorallocate($this->image, ...$rgb) ); } @@ -120,22 +125,22 @@ class QRImage extends QROutputAbstract{ protected function dumpImage(string $file = null):string{ $file = $file ?? $this->options->cachefile; - \ob_start(); + ob_start(); try{ - \call_user_func([$this, $this->outputMode ?? $this->defaultMode]); + call_user_func([$this, $this->outputMode ?? $this->defaultMode]); } // not going to cover edge cases // @codeCoverageIgnoreStart - catch(\Exception $e){ + catch(Exception $e){ throw new QRCodeOutputException($e->getMessage()); } // @codeCoverageIgnoreEnd - $imageData = \ob_get_contents(); - \imagedestroy($this->image); + $imageData = ob_get_contents(); + imagedestroy($this->image); - \ob_end_clean(); + ob_end_clean(); if($file !== null){ $this->saveToFile($imageData, $file); @@ -148,10 +153,10 @@ class QRImage extends QROutputAbstract{ * @return void */ protected function png():void{ - \imagepng( + imagepng( $this->image, null, - \in_array($this->options->pngCompression, \range(-1, 9), true) + in_array($this->options->pngCompression, range(-1, 9), true) ? $this->options->pngCompression : -1 ); @@ -162,17 +167,17 @@ class QRImage extends QROutputAbstract{ * @return void */ protected function gif():void{ - \imagegif($this->image); + imagegif($this->image); } /** * @return void */ protected function jpg():void{ - \imagejpeg( + imagejpeg( $this->image, null, - \in_array($this->options->jpegQuality, \range(0, 100), true) + in_array($this->options->jpegQuality, range(0, 100), true) ? $this->options->jpegQuality : 85 ); diff --git a/src/Output/QRImagick.php b/src/Output/QRImagick.php index e80f18355..6fa8a1a16 100644 --- a/src/Output/QRImagick.php +++ b/src/Output/QRImagick.php @@ -14,6 +14,8 @@ namespace chillerlan\QRCode\Output; use Imagick, ImagickDraw, ImagickPixel; +use function is_string; + /** * ImageMagick output module * requires ext-imagick diff --git a/src/Output/QRMarkup.php b/src/Output/QRMarkup.php index b970850ca..06458aef4 100644 --- a/src/Output/QRMarkup.php +++ b/src/Output/QRMarkup.php @@ -14,6 +14,8 @@ namespace chillerlan\QRCode\Output; use chillerlan\QRCode\QRCode; +use function is_string, sprintf, strip_tags, trim; + /** * Converts the matrix into markup types: HTML, SVG, ... */ @@ -39,13 +41,13 @@ class QRMarkup extends QROutputAbstract{ foreach($this::DEFAULT_MODULE_VALUES as $M_TYPE => $defaultValue){ $v = $this->options->moduleValues[$M_TYPE] ?? null; - if(!\is_string($v)){ + if(!is_string($v)){ $this->moduleValues[$M_TYPE] = $defaultValue ? $this->options->markupDark : $this->options->markupLight; } else{ - $this->moduleValues[$M_TYPE] = \trim(\strip_tags($v), '\'"'); + $this->moduleValues[$M_TYPE] = trim(strip_tags($v), '\'"'); } } @@ -85,7 +87,7 @@ class QRMarkup extends QROutputAbstract{ protected function svg():string{ $matrix = $this->matrix->matrix(); - $svg = \sprintf($this->svgHeader, $this->options->cssClass, $this->options->svgViewBoxSize ?? $this->moduleCount) + $svg = sprintf($this->svgHeader, $this->options->cssClass, $this->options->svgViewBoxSize ?? $this->moduleCount) .$this->options->eol .''.$this->options->svgDefs.'' .$this->options->eol; diff --git a/src/Output/QROutputAbstract.php b/src/Output/QROutputAbstract.php index 3e0736262..ce474554d 100644 --- a/src/Output/QROutputAbstract.php +++ b/src/Output/QROutputAbstract.php @@ -15,6 +15,8 @@ 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; + /** * common output abstract */ @@ -73,7 +75,7 @@ abstract class QROutputAbstract implements QROutputInterface{ $this->scale = $this->options->scale; $this->length = $this->moduleCount * $this->scale; - $class = \get_called_class(); + $class = get_called_class(); if(\array_key_exists($class, QRCode::OUTPUT_MODES) && \in_array($this->options->outputType, QRCode::OUTPUT_MODES[$class])){ $this->outputMode = $this->options->outputType; @@ -100,11 +102,11 @@ abstract class QROutputAbstract implements QROutputInterface{ */ protected function saveToFile(string $data, string $file):bool{ - if(!\is_writable(\dirname($file))){ + if(!is_writable(dirname($file))){ throw new QRCodeOutputException('Could not write data to cache file: '.$file); } - return (bool)\file_put_contents($file, $data); + return (bool)file_put_contents($file, $data); } /** @@ -113,7 +115,7 @@ abstract class QROutputAbstract implements QROutputInterface{ * @return string|mixed */ public function dump(string $file = null){ - $data = \call_user_func([$this, $this->outputMode ?? $this->defaultMode]); + $data = call_user_func([$this, $this->outputMode ?? $this->defaultMode]); $file = $file ?? $this->options->cachefile; if($file !== null){ diff --git a/src/Output/QRString.php b/src/Output/QRString.php index 4fb4cdeed..85507cde2 100644 --- a/src/Output/QRString.php +++ b/src/Output/QRString.php @@ -14,6 +14,8 @@ namespace chillerlan\QRCode\Output; use chillerlan\QRCode\QRCode; +use function implode, is_string, json_encode; + /** * Converts the matrix data into string types */ @@ -58,17 +60,17 @@ class QRString extends QROutputAbstract{ $r[] = $this->moduleValues[$M_TYPE]; } - $str[] = \implode('', $r); + $str[] = implode('', $r); } - return \implode($this->options->eol, $str); + return implode($this->options->eol, $str); } /** * @return string */ protected function json():string{ - return \json_encode($this->matrix->matrix()); + return json_encode($this->matrix->matrix()); } } diff --git a/src/QRCode.php b/src/QRCode.php index 55774e41b..4923c8b62 100755 --- a/src/QRCode.php +++ b/src/QRCode.php @@ -20,6 +20,8 @@ use chillerlan\QRCode\Output\{ }; use chillerlan\Settings\SettingsContainerInterface; +use function array_search, call_user_func_array, class_exists, in_array, mb_internal_encoding, min, ord, strlen; + /** * Turns a text string into a Model 2 QR Code * @@ -111,9 +113,9 @@ class QRCode{ */ public function __construct(SettingsContainerInterface $options = null){ // save the current mb encoding (in case it differs from UTF-8) - $this->mbCurrentEncoding = \mb_internal_encoding(); + $this->mbCurrentEncoding = mb_internal_encoding(); // use UTF-8 from here on - \mb_internal_encoding('UTF-8'); + mb_internal_encoding('UTF-8'); $this->options = $options ?? new QROptions; } @@ -123,7 +125,7 @@ class QRCode{ */ public function __destruct(){ // restore the previous mb_internal_encoding, so that we don't mess up the rest of the script - \mb_internal_encoding($this->mbCurrentEncoding); + mb_internal_encoding($this->mbCurrentEncoding); } /** @@ -183,7 +185,7 @@ class QRCode{ $penalties[$pattern] = $tester->testPattern(); } - return \array_search(\min($penalties), $penalties, true); + return array_search(min($penalties), $penalties, true); } /** @@ -199,7 +201,7 @@ class QRCode{ foreach(['Number', 'AlphaNum', 'Kanji', 'Byte'] as $mode){ $dataInterface = __NAMESPACE__.'\\Data\\'.$mode; - if(\call_user_func_array([$this, 'is'.$mode], [$data]) && \class_exists($dataInterface)){ + if(call_user_func_array([$this, 'is'.$mode], [$data]) && class_exists($dataInterface)){ return new $dataInterface($this->options, $data); } @@ -218,13 +220,13 @@ class QRCode{ */ protected function initOutputInterface(string $data):QROutputInterface{ - if($this->options->outputType === $this::OUTPUT_CUSTOM && \class_exists($this->options->outputInterface)){ + if($this->options->outputType === $this::OUTPUT_CUSTOM && class_exists($this->options->outputInterface)){ return new $this->options->outputInterface($this->options, $this->getMatrix($data)); } foreach($this::OUTPUT_MODES as $outputInterface => $modes){ - if(in_array($this->options->outputType, $modes, true) && \class_exists($outputInterface)){ + if(in_array($this->options->outputType, $modes, true) && class_exists($outputInterface)){ return new $outputInterface($this->options, $this->getMatrix($data)); } @@ -264,10 +266,10 @@ class QRCode{ * @return bool */ protected function checkString(string $string, array $charmap):bool{ - $len = \strlen($string); + $len = strlen($string); for($i = 0; $i < $len; $i++){ - if(!\in_array($string[$i], $charmap, true)){ + if(!in_array($string[$i], $charmap, true)){ return false; } } @@ -284,10 +286,10 @@ class QRCode{ */ public function isKanji(string $string):bool{ $i = 0; - $len = \strlen($string); + $len = strlen($string); while($i + 1 < $len){ - $c = ((0xff&\ord($string[$i])) << 8)|(0xff&\ord($string[$i + 1])); + $c = ((0xff & ord($string[$i])) << 8) | (0xff & ord($string[$i + 1])); if(!($c >= 0x8140 && $c <= 0x9FFC) && !($c >= 0xE040 && $c <= 0xEBBF)){ return false; diff --git a/src/QROptionsTrait.php b/src/QROptionsTrait.php index a18354968..8f8d72f35 100644 --- a/src/QROptionsTrait.php +++ b/src/QROptionsTrait.php @@ -12,6 +12,8 @@ namespace chillerlan\QRCode; +use function array_values, count, is_array, is_numeric, max, min; + trait QROptionsTrait{ /** @@ -248,11 +250,11 @@ trait QROptionsTrait{ * @return void */ protected function setMinMaxVersion(int $versionMin, int $versionMax):void{ - $min = \max(1, \min(40, $versionMin)); - $max = \max(1, \min(40, $versionMax)); + $min = max(1, min(40, $versionMin)); + $max = max(1, min(40, $versionMax)); - $this->versionMin = \min($min, $max); - $this->versionMax = \max($min, $max); + $this->versionMin = min($min, $max); + $this->versionMax = max($min, $max); } /** @@ -296,7 +298,7 @@ trait QROptionsTrait{ protected function set_maskPattern(int $maskPattern):void{ if($maskPattern !== QRCode::MASK_PATTERN_AUTO){ - $this->maskPattern = \max(0, \min(7, $maskPattern)); + $this->maskPattern = max(0, min(7, $maskPattern)); } } @@ -310,7 +312,7 @@ trait QROptionsTrait{ protected function set_imageTransparencyBG($imageTransparencyBG):void{ // invalid value - set to white as default - if(!\is_array($imageTransparencyBG) || \count($imageTransparencyBG) < 3){ + if(!is_array($imageTransparencyBG) || count($imageTransparencyBG) < 3){ $this->imageTransparencyBG = [255, 255, 255]; return; @@ -318,16 +320,16 @@ trait QROptionsTrait{ foreach($imageTransparencyBG as $k => $v){ - if(!\is_numeric($v)){ + if(!is_numeric($v)){ throw new QRCodeException('Invalid RGB value.'); } // clamp the values - $this->imageTransparencyBG[$k] = \max(0, \min(255, (int)$v)); + $this->imageTransparencyBG[$k] = max(0, min(255, (int)$v)); } // use the array values to not run into errors with the spread operator (...$arr) - $this->imageTransparencyBG = \array_values($this->imageTransparencyBG); + $this->imageTransparencyBG = array_values($this->imageTransparencyBG); } /** @@ -338,7 +340,7 @@ trait QROptionsTrait{ protected function set_version(int $version):void{ if($version !== QRCode::VERSION_AUTO){ - $this->version = \max(1, \min(40, $version)); + $this->version = max(1, min(40, $version)); } } From c550846be9930df6766aed3cba9e04a25f6ee2cc Mon Sep 17 00:00:00 2001 From: codemasher Date: Fri, 9 Aug 2019 20:19:32 +0200 Subject: [PATCH 07/11] :octocat: array_key_exists() -> isset() --- src/Output/QROutputAbstract.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Output/QROutputAbstract.php b/src/Output/QROutputAbstract.php index ce474554d..6dab31659 100644 --- a/src/Output/QROutputAbstract.php +++ b/src/Output/QROutputAbstract.php @@ -77,7 +77,7 @@ abstract class QROutputAbstract implements QROutputInterface{ $class = get_called_class(); - if(\array_key_exists($class, QRCode::OUTPUT_MODES) && \in_array($this->options->outputType, QRCode::OUTPUT_MODES[$class])){ + if(isset(QRCode::OUTPUT_MODES[$class]) && in_array($this->options->outputType, QRCode::OUTPUT_MODES[$class])){ $this->outputMode = $this->options->outputType; } From 34e244261685c9fecf62723fc4250c08de2b6e47 Mon Sep 17 00:00:00 2001 From: codemasher Date: Fri, 9 Aug 2019 20:20:00 +0200 Subject: [PATCH 08/11] :octocat: de-uglify --- src/Output/QRMarkup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Output/QRMarkup.php b/src/Output/QRMarkup.php index 06458aef4..db79ae2ae 100644 --- a/src/Output/QRMarkup.php +++ b/src/Output/QRMarkup.php @@ -109,7 +109,7 @@ class QRMarkup extends QROutputAbstract{ $start = $x; } - if($row[$x + 1] ?? false){ + if(isset($row[$x + 1])){ continue; } } From d6b3e6bc3b757931a45e4ced65a733a90f204208 Mon Sep 17 00:00:00 2001 From: codemasher Date: Fri, 9 Aug 2019 20:20:23 +0200 Subject: [PATCH 09/11] :octocat: comment unused constant --- src/Data/QRMatrix.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/QRMatrix.php b/src/Data/QRMatrix.php index 75d9e066e..7e750ba56 100755 --- a/src/Data/QRMatrix.php +++ b/src/Data/QRMatrix.php @@ -31,7 +31,7 @@ class QRMatrix{ public const M_FORMAT = 0x0e; public const M_VERSION = 0x10; public const M_QUIETZONE = 0x12; - public const M_LOGO = 0x14; // @todo +# public const M_LOGO = 0x14; // @todo public const M_TEST = 0xff; From ab7a11f225a41601bcbacc68fe07ebc4fb4a56bc Mon Sep 17 00:00:00 2001 From: codemasher Date: Fri, 9 Aug 2019 21:14:00 +0200 Subject: [PATCH 10/11] :shower: sprintf'd some things --- src/Data/AlphaNum.php | 4 ++-- src/Data/Kanji.php | 6 +++--- src/Data/Number.php | 9 ++++----- src/Data/QRDataAbstract.php | 10 +++++----- src/Helpers/Polynomial.php | 4 ++-- src/Output/QRImage.php | 4 ++-- src/Output/QRMarkup.php | 4 ++-- src/Output/QROutputAbstract.php | 4 ++-- src/QROptionsTrait.php | 4 ++-- 9 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/Data/AlphaNum.php b/src/Data/AlphaNum.php index 95070a16f..c6d34e76f 100644 --- a/src/Data/AlphaNum.php +++ b/src/Data/AlphaNum.php @@ -14,7 +14,7 @@ namespace chillerlan\QRCode\Data; use chillerlan\QRCode\QRCode; -use function array_search, ord; +use function array_search, ord, sprintf; /** * Alphanumeric mode: 0 to 9, A to Z, space, $ % * + - . / : @@ -59,7 +59,7 @@ class AlphaNum extends QRDataAbstract{ return $i; } - throw new QRCodeDataException('illegal char: "'.$chr.'" ['.ord($chr).']'); + throw new QRCodeDataException(sprintf('illegal char: "%s" [%d]', $chr, ord($chr))); } } diff --git a/src/Data/Kanji.php b/src/Data/Kanji.php index 139b7d1a1..9faf4fc54 100644 --- a/src/Data/Kanji.php +++ b/src/Data/Kanji.php @@ -14,7 +14,7 @@ namespace chillerlan\QRCode\Data; use chillerlan\QRCode\QRCode; -use function mb_strlen, ord, strlen; +use function mb_strlen, ord, sprintf, strlen; /** * Kanji mode: double-byte characters from the Shift JIS character set @@ -57,7 +57,7 @@ class Kanji extends QRDataAbstract{ $c -= 0xC140; } else{ - throw new QRCodeDataException('illegal char at '.($i + 1).' ['.$c.']'); + throw new QRCodeDataException(sprintf('illegal char at %d [%d]', $i + 1, $c)); } $this->bitBuffer->put((($c >> 8) & 0xff) * 0xC0 + ($c & 0xff), 13); @@ -65,7 +65,7 @@ class Kanji extends QRDataAbstract{ } if($i < $len){ - throw new QRCodeDataException('illegal char at '.($i + 1)); + throw new QRCodeDataException(sprintf('illegal char at %d', $i + 1)); } } diff --git a/src/Data/Number.php b/src/Data/Number.php index a6ba0545a..976536462 100644 --- a/src/Data/Number.php +++ b/src/Data/Number.php @@ -14,7 +14,7 @@ namespace chillerlan\QRCode\Data; use chillerlan\QRCode\QRCode; -use function substr; +use function ord, sprintf, substr; /** * Numeric mode: decimal digits 0 through 9 @@ -68,14 +68,13 @@ class Number extends QRDataAbstract{ $len = strlen($string); for($i = 0; $i < $len; $i++){ - $c = \ord($string[$i]); + $c = ord($string[$i]); if(!in_array($string[$i], $this::NUMBER_CHAR_MAP, true)){ - throw new QRCodeDataException('illegal char: "'.$string[$i].'" ['.$c.']'); + throw new QRCodeDataException(sprintf('illegal char: "%s" [%d]', $string[$i], $c)); } - $c = $c - \ord('0'); - + $c = $c - 48; // ord('0') $num = $num * 10 + $c; } diff --git a/src/Data/QRDataAbstract.php b/src/Data/QRDataAbstract.php index 307802c53..d4c66936d 100644 --- a/src/Data/QRDataAbstract.php +++ b/src/Data/QRDataAbstract.php @@ -16,7 +16,7 @@ use chillerlan\QRCode\{QRCode, QRCodeException}; use chillerlan\QRCode\Helpers\{BitBuffer, Polynomial}; use chillerlan\Settings\SettingsContainerInterface; -use function array_fill, array_merge, count, max, range, strlen; +use function array_fill, array_merge, count, max, mb_convert_encoding, mb_detect_encoding, range, sprintf, strlen; /** * Processes the binary data and maps it on a matrix which is then being returned @@ -106,7 +106,7 @@ abstract class QRDataAbstract implements QRDataInterface{ public function setData(string $data):QRDataInterface{ if($this->datamode === QRCode::DATA_KANJI){ - $data = \mb_convert_encoding($data, 'SJIS', \mb_detect_encoding($data)); + $data = mb_convert_encoding($data, 'SJIS', mb_detect_encoding($data)); } $this->strlen = $this->getLength($data); @@ -160,7 +160,7 @@ abstract class QRDataAbstract implements QRDataInterface{ } } - throw new QRCodeDataException('invalid version number: '.$this->version); + throw new QRCodeDataException(sprintf('invalid version number: %d', $this->version)); } /** @@ -192,7 +192,7 @@ abstract class QRDataAbstract implements QRDataInterface{ } } - throw new QRCodeDataException('data exceeds '.$maxlength.' characters'); + throw new QRCodeDataException(sprintf('data exceeds %d characters', $maxlength)); } /** @@ -227,7 +227,7 @@ abstract class QRDataAbstract implements QRDataInterface{ // there was an error writing the BitBuffer data, which is... unlikely. if($this->bitBuffer->length > $MAX_BITS){ - throw new QRCodeException('code length overflow. ('.$this->bitBuffer->length.' > '.$MAX_BITS.'bit)'); // @codeCoverageIgnore + throw new QRCodeException(sprintf('code length overflow. (%d > %d bit)', $this->bitBuffer->length, $MAX_BITS)); // @codeCoverageIgnore } // end code. diff --git a/src/Helpers/Polynomial.php b/src/Helpers/Polynomial.php index e0032f95c..abe11d0cc 100644 --- a/src/Helpers/Polynomial.php +++ b/src/Helpers/Polynomial.php @@ -14,7 +14,7 @@ namespace chillerlan\QRCode\Helpers; use chillerlan\QRCode\QRCodeException; -use function array_fill, count; +use function array_fill, count, sprintf; /** * @link http://www.thonky.com/qr-code-tutorial/error-correction-coding @@ -158,7 +158,7 @@ class Polynomial{ public function glog(int $n):int{ if($n < 1){ - throw new QRCodeException('log('.$n.')'); + throw new QRCodeException(sprintf('log(%s)', $n)); } return Polynomial::table[$n][1]; diff --git a/src/Output/QRImage.php b/src/Output/QRImage.php index e5d62f677..4d8576117 100644 --- a/src/Output/QRImage.php +++ b/src/Output/QRImage.php @@ -17,7 +17,7 @@ use Exception; use function array_values, base64_encode, call_user_func, count, imagecolorallocate, imagecolortransparent, imagecreatetruecolor, imagedestroy, imagefilledrectangle, imagegif, imagejpeg, imagepng, in_array, - is_array, ob_end_clean, ob_get_contents, ob_start, range; + is_array, ob_end_clean, ob_get_contents, ob_start, range, sprintf; /** * Converts the matrix into GD images, raw or base64 output @@ -91,7 +91,7 @@ class QRImage extends QROutputAbstract{ $imageData = $this->dumpImage($file); if((bool)$this->options->imageBase64){ - $imageData = 'data:image/'.$this->options->outputType.';base64,'.base64_encode($imageData); + $imageData = sprintf('data:image/%s;base64,%s', $this->options->outputType, base64_encode($imageData)); } return $imageData; diff --git a/src/Output/QRMarkup.php b/src/Output/QRMarkup.php index db79ae2ae..4472d34c0 100644 --- a/src/Output/QRMarkup.php +++ b/src/Output/QRMarkup.php @@ -116,7 +116,7 @@ class QRMarkup extends QROutputAbstract{ if($count > 0){ $len = $count; - $path .= 'M' .$start. ' ' .$y. ' h'.$len.' v1 h-'.$len.'Z '; + $path .= sprintf('M%s %s h%s v1 h-%sZ ', $start, $y, $len, $len); // reset count $count = 0; @@ -128,7 +128,7 @@ class QRMarkup extends QROutputAbstract{ } if(!empty($path)){ - $svg .= ''; + $svg .= sprintf('', $M_TYPE, $this->options->cssClass, $value, $this->options->svgOpacity, $path); } } diff --git a/src/Output/QROutputAbstract.php b/src/Output/QROutputAbstract.php index 6dab31659..05c909e82 100644 --- a/src/Output/QROutputAbstract.php +++ b/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; +use function call_user_func, dirname, file_put_contents, get_called_class, in_array, is_writable, sprintf; /** * common output abstract @@ -103,7 +103,7 @@ abstract class QROutputAbstract implements QROutputInterface{ protected function saveToFile(string $data, string $file):bool{ if(!is_writable(dirname($file))){ - throw new QRCodeOutputException('Could not write data to cache file: '.$file); + throw new QRCodeOutputException(sprintf('Could not write data to cache file: %s', $file)); } return (bool)file_put_contents($file, $data); diff --git a/src/QROptionsTrait.php b/src/QROptionsTrait.php index 8f8d72f35..40d935feb 100644 --- a/src/QROptionsTrait.php +++ b/src/QROptionsTrait.php @@ -12,7 +12,7 @@ namespace chillerlan\QRCode; -use function array_values, count, is_array, is_numeric, max, min; +use function array_values, count, is_array, is_numeric, max, min, sprintf; trait QROptionsTrait{ @@ -284,7 +284,7 @@ trait QROptionsTrait{ protected function set_eccLevel(int $eccLevel):void{ if(!isset(QRCode::ECC_MODES[$eccLevel])){ - throw new QRCodeException('Invalid error correct level: '.$eccLevel); + throw new QRCodeException(sprintf('Invalid error correct level: %s', $eccLevel)); } $this->eccLevel = $eccLevel; From 464667f452d74d1fafd1e600ecee23a26587f60c Mon Sep 17 00:00:00 2001 From: codemasher Date: Fri, 9 Aug 2019 21:41:17 +0200 Subject: [PATCH 11/11] :octocat: --- README.md | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 745dd0e25..d8e7bc3c1 100644 --- a/README.md +++ b/README.md @@ -65,18 +65,12 @@ Profit! - [gaara 嘎啦](https://github.com/xutengx/gaara) ### Usage -We want to encode this data into a QRcode image: +We want to encode this URI for a mobile authenticator into a QRcode image: ```php -// 10 reasons why QR codes are awesome -$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s'; - -// no, for serious, we want to display a QR code for a mobile authenticator $data = 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net'; -``` -Quick and simple: -```php -echo ''; +//quick and simple: +echo 'QR Code'; ```

@@ -160,7 +154,7 @@ To map the values and properly render the modules for the given `QROutputInterfa ```php $options = new QROptions; -// for HTML and SVG +// for HTML, SVG and ImageMagick $options->moduleValues = [ // finder 1536 => '#A71111', // dark (true) @@ -201,8 +195,6 @@ $options->moduleValues = [ ]; ``` -Combined with a custom output interface and your imagination you can create some cool effects that way! - #### Custom `QROutputInterface` Instead of bloating your code you can simply create your own output interface by extending `QROutputAbstract`. Have a look at the [built-in output modules](https://github.com/chillerlan/php-qrcode/tree/master/src/Output). @@ -270,7 +262,7 @@ $myCustomOptions = new MyCustomOptions($myOptions); // using the SettingsContainerInterface $myCustomOptions = new class($myOptions) extends SettingsContainerAbstract{ - use QROptions, MyCustomOptionsTrait; + use QROptionsTrait, MyCustomOptionsTrait; }; ``` @@ -329,6 +321,9 @@ property | type | default | allowed | description `$eol` | string | `PHP_EOL` | * | newline string (HTML, SVG, TEXT) `$scale` | int | 5 | * | size of a QR code pixel (SVG, IMAGE_*), HTML -> via CSS `$cssClass` | string | `null` | * | a common css class +`$svgOpacity` | float | 1.0 | 0...1 | +`$svgDefs` | string | * | * | anything between [``](https://developer.mozilla.org/docs/Web/SVG/Element/defs) +`$svgViewBoxSize` | int | `null` | * | a positive integer which defines width/height of the [viewBox attribute](https://css-tricks.com/scale-svg/#article-header-id-3) `$textDark` | string | '🔴' | * | string substitute for dark `$textLight` | string | '⭕' | * | string substitute for light `$markupDark` | string | '#000' | * | markup substitute for dark (CSS value) @@ -359,7 +354,7 @@ method | return | description name | light (false) | dark (true) | description ---- | ------------- | ----------- | ----------- `M_NULL` | 0 | - | module not set (should never appear. if so, there's an error) -`M_DARKMODULE` | - (2) | 512 | once per matrix at `$xy = [8, 4 * $version + 9]` +`M_DARKMODULE` | - | 512 | once per matrix at `$xy = [8, 4 * $version + 9]` `M_DATA` | 4 | 1024 | the actual encoded data `M_FINDER` | 6 | 1536 | the 7x7 finder patterns `M_SEPARATOR` | 8 | - | separator lines around the finder patterns