From 2aee933b1e66db0f690a5650968b162052c1a9d9 Mon Sep 17 00:00:00 2001 From: codemasher Date: Wed, 19 Sep 2018 20:35:16 +0200 Subject: [PATCH] :lipstick: --- examples/MyCustomOutput.php | 2 - src/Data/AlphaNum.php | 6 +- src/Data/Byte.php | 2 +- src/Data/Kanji.php | 2 +- src/Data/MaskPatternTester.php | 2 +- src/Data/Number.php | 6 +- src/Data/QRCodeDataException.php | 9 +-- src/Data/QRDataAbstract.php | 22 ++++---- src/Data/QRDataInterface.php | 11 ++-- src/Data/QRMatrix.php | 41 +++++++------- src/Helpers/BitBuffer.php | 4 -- src/Helpers/Polynomial.php | 12 ++-- src/Output/QRCodeOutputException.php | 11 +--- src/Output/QRImage.php | 9 ++- src/Output/QRImagick.php | 1 - src/Output/QRMarkup.php | 11 ++-- src/Output/QROutputAbstract.php | 8 +-- src/Output/QRString.php | 3 + src/QRCode.php | 71 ++++++++++-------------- src/QRCodeException.php | 9 +-- tests/Data/DatainterfaceTestAbstract.php | 4 +- tests/Data/MaskPatternTesterTest.php | 4 +- tests/Data/QRMatrixTest.php | 8 +-- tests/Helpers/BitBufferTest.php | 3 +- tests/Output/QRImageTest.php | 14 ++--- tests/Output/QRMarkupTest.php | 3 +- tests/Output/QROutputTestAbstract.php | 4 +- tests/Output/QRStringTest.php | 3 +- tests/QRCodeTest.php | 14 ++--- tests/QRTestAbstract.php | 4 +- 30 files changed, 134 insertions(+), 169 deletions(-) diff --git a/examples/MyCustomOutput.php b/examples/MyCustomOutput.php index 4e4e5bcb4..3c01f8646 100644 --- a/examples/MyCustomOutput.php +++ b/examples/MyCustomOutput.php @@ -14,8 +14,6 @@ namespace chillerlan\QRCodeExamples; use chillerlan\QRCode\Output\QROutputAbstract; -/** - */ class MyCustomOutput extends QROutputAbstract{ protected function setModuleValues():void{ diff --git a/src/Data/AlphaNum.php b/src/Data/AlphaNum.php index c1b90d7d0..f8436e158 100644 --- a/src/Data/AlphaNum.php +++ b/src/Data/AlphaNum.php @@ -19,7 +19,7 @@ use chillerlan\QRCode\QRCode; */ class AlphaNum extends QRDataAbstract{ - const CHAR_MAP = [ + public const CHAR_MAP = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', @@ -41,7 +41,7 @@ class AlphaNum extends QRDataAbstract{ /** * @inheritdoc */ - protected function write(string $data){ + protected function write(string $data):void{ for($i = 0; $i + 1 < $this->strlen; $i += 2){ $this->bitBuffer->put($this->getCharCode($data[$i]) * 45 + $this->getCharCode($data[$i + 1]), 11); @@ -59,7 +59,7 @@ class AlphaNum extends QRDataAbstract{ * @return int * @throws \chillerlan\QRCode\Data\QRCodeDataException */ - protected function getCharCode(string $chr):int { + protected function getCharCode(string $chr):int{ $i = array_search($chr, $this::CHAR_MAP); if($i !== false){ diff --git a/src/Data/Byte.php b/src/Data/Byte.php index d5128ec97..bdc5a77fd 100644 --- a/src/Data/Byte.php +++ b/src/Data/Byte.php @@ -32,7 +32,7 @@ class Byte extends QRDataAbstract{ /** * @inheritdoc */ - protected function write(string $data){ + protected function write(string $data):void{ $i = 0; while($i < $this->strlen){ diff --git a/src/Data/Kanji.php b/src/Data/Kanji.php index 050fa9b0b..be8d742de 100644 --- a/src/Data/Kanji.php +++ b/src/Data/Kanji.php @@ -42,7 +42,7 @@ class Kanji extends QRDataAbstract{ * @return void * @throws \chillerlan\QRCode\Data\QRCodeDataException */ - protected function write(string $data){ + protected function write(string $data):void{ $len = strlen($data); for($i = 0; $i + 1 < $len; $i += 2){ diff --git a/src/Data/MaskPatternTester.php b/src/Data/MaskPatternTester.php index 998597e53..3057ad84b 100644 --- a/src/Data/MaskPatternTester.php +++ b/src/Data/MaskPatternTester.php @@ -201,7 +201,7 @@ class MaskPatternTester{ * * @return float */ - protected function testLevel4():float { + protected function testLevel4():float{ $count = 0; foreach($this->matrix->matrix() as $y => $row){ diff --git a/src/Data/Number.php b/src/Data/Number.php index d8008767d..f65d8c92b 100644 --- a/src/Data/Number.php +++ b/src/Data/Number.php @@ -19,7 +19,7 @@ use chillerlan\QRCode\QRCode; */ class Number extends QRDataAbstract{ - const CHAR_MAP = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; + public const CHAR_MAP = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; /** * @inheritdoc @@ -34,7 +34,7 @@ class Number extends QRDataAbstract{ /** * @inheritdoc */ - protected function write(string $data){ + protected function write(string $data):void{ $i = 0; while($i + 2 < $this->strlen){ @@ -63,7 +63,7 @@ class Number extends QRDataAbstract{ * @return int * @throws \chillerlan\QRCode\Data\QRCodeDataException */ - protected function parseInt(string $string):int { + protected function parseInt(string $string):int{ $num = 0; $len = strlen($string); diff --git a/src/Data/QRCodeDataException.php b/src/Data/QRCodeDataException.php index 2d1049ad2..862f57ba0 100644 --- a/src/Data/QRCodeDataException.php +++ b/src/Data/QRCodeDataException.php @@ -12,11 +12,6 @@ namespace chillerlan\QRCode\Data; -use Exception; +use chillerlan\QRCode\QRCodeException; -/** - * Placeholder - */ -class QRCodeDataException extends Exception{ - -} +class QRCodeDataException extends QRCodeException{} diff --git a/src/Data/QRDataAbstract.php b/src/Data/QRDataAbstract.php index 9f335c4f6..b784608fe 100644 --- a/src/Data/QRDataAbstract.php +++ b/src/Data/QRDataAbstract.php @@ -150,7 +150,7 @@ abstract class QRDataAbstract implements QRDataInterface{ * @throws \chillerlan\QRCode\Data\QRCodeDataException * @codeCoverageIgnore */ - protected function getLengthBits():int { + protected function getLengthBits():int{ foreach([9, 26, 40] as $key => $breakpoint){ if($this->version <= $breakpoint){ @@ -200,7 +200,7 @@ abstract class QRDataAbstract implements QRDataInterface{ * * @return void */ - abstract protected function write(string $data); + abstract protected function write(string $data):void; /** * writes the string data to the BitBuffer @@ -210,7 +210,7 @@ abstract class QRDataAbstract implements QRDataInterface{ * @return \chillerlan\QRCode\Data\QRDataAbstract * @throws \chillerlan\QRCode\QRCodeException */ - protected function writeBitBuffer(string $data):QRDataInterface { + protected function writeBitBuffer(string $data):QRDataInterface{ $this->bitBuffer = new BitBuffer; // @todo: fixme, get real length @@ -267,13 +267,13 @@ abstract class QRDataAbstract implements QRDataInterface{ * * @return array */ - protected function maskECC():array { - list($l1, $l2, $b1, $b2) = $this::RSBLOCKS[$this->version][QRCode::ECC_MODES[$this->options->eccLevel]]; + 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]); - $rsCount = $l1 + $l2; - $this->ecdata = array_fill(0, $rsCount, null); - $this->dcdata = $this->ecdata; + $rsBlocks = array_fill(0, $l1, [$b1, $b2]); + $rsCount = $l1 + $l2; + $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])); @@ -285,7 +285,7 @@ abstract class QRDataAbstract implements QRDataInterface{ $offset = 0; foreach($rsBlocks as $key => $block){ - list($rsBlockTotal, $dcCount) = $block; + [$rsBlockTotal, $dcCount] = $block; $ecCount = $rsBlockTotal - $dcCount; $maxDcCount = max($maxDcCount, $dcCount); @@ -296,7 +296,7 @@ abstract class QRDataAbstract implements QRDataInterface{ $this->dcdata[$key][$a] = 0xff & $this->bitBuffer->buffer[$a + $offset]; } - list($num, $add) = $this->poly($key, $ecCount); + [$num, $add] = $this->poly($key, $ecCount); foreach($this->ecdata[$key] as $c => $_z){ $modIndex = $c + $add; diff --git a/src/Data/QRDataInterface.php b/src/Data/QRDataInterface.php index 8326ad160..d0c9bdea3 100644 --- a/src/Data/QRDataInterface.php +++ b/src/Data/QRDataInterface.php @@ -20,7 +20,8 @@ interface QRDataInterface{ /** * @link http://www.qrcode.com/en/about/version.html */ - const MAX_LENGTH =[ null, // start at 1 + const MAX_LENGTH =[ + null, // start at 1 // [NUMERIC => [L, M, Q, H ], ALPHANUM => [L, M, Q, H], BINARY => [L, M, Q, H ], KANJI => [L, M, Q, H ]] // modules [[ 41, 34, 27, 17], [ 25, 20, 16, 10], [ 17, 14, 11, 7], [ 10, 8, 7, 4]], // 21 [[ 77, 63, 48, 34], [ 47, 38, 29, 20], [ 32, 26, 20, 14], [ 20, 16, 12, 8]], // 25 @@ -64,7 +65,8 @@ interface QRDataInterface{ [[7089, 5596, 3993, 3057], [4296, 3391, 2420, 1852], [2953, 2331, 1663, 1273], [1817, 1435, 1024, 784]], // 177 ]; - const MAX_BITS = [ null, // start at 1 + const MAX_BITS = [ + null, // start at 1 // MAX_BITS => [L, M, Q, H ] [ 152, 128, 104, 72], [ 272, 224, 176, 128], @@ -111,7 +113,8 @@ interface QRDataInterface{ /** * @link http://www.thonky.com/qr-code-tutorial/error-correction-table */ - const RSBLOCKS = [ null, // start at 1 + const RSBLOCKS = [ + null, // start at 1 [[ 1, 0, 26, 19], [ 1, 0, 26, 16], [ 1, 0, 26, 13], [ 1, 0, 26, 9]], // 1 [[ 1, 0, 44, 34], [ 1, 0, 44, 28], [ 1, 0, 44, 22], [ 1, 0, 44, 16]], // [[ 1, 0, 70, 55], [ 1, 0, 70, 44], [ 2, 0, 35, 17], [ 2, 0, 35, 13]], // @@ -159,7 +162,7 @@ interface QRDataInterface{ * * @return \chillerlan\QRCode\Data\QRDataInterface */ - public function setData(string $data); + public function setData(string $data):QRDataInterface; /** * @param int $maskPattern diff --git a/src/Data/QRMatrix.php b/src/Data/QRMatrix.php index 0bbb45636..e0d5a9496 100755 --- a/src/Data/QRMatrix.php +++ b/src/Data/QRMatrix.php @@ -19,24 +19,25 @@ use chillerlan\QRCode\QRCode; */ class QRMatrix{ - const M_NULL = 0x00; - const M_DARKMODULE = 0x02; - const M_DATA = 0x04; - const M_FINDER = 0x06; - const M_SEPARATOR = 0x08; - const M_ALIGNMENT = 0x0a; - const M_TIMING = 0x0c; - const M_FORMAT = 0x0e; - const M_VERSION = 0x10; - const M_QUIETZONE = 0x12; - const M_LOGO = 0x14; // @todo + public const M_NULL = 0x00; + public const M_DARKMODULE = 0x02; + public const M_DATA = 0x04; + public const M_FINDER = 0x06; + public const M_SEPARATOR = 0x08; + public const M_ALIGNMENT = 0x0a; + public const M_TIMING = 0x0c; + public const M_FORMAT = 0x0e; + public const M_VERSION = 0x10; + public const M_QUIETZONE = 0x12; + public const M_LOGO = 0x14; // @todo - const M_TEST = 0xff; + public const M_TEST = 0xff; /** * @link http://www.thonky.com/qr-code-tutorial/alignment-pattern-locations */ - const alignmentPattern = [ null, // start at 1 + protected const alignmentPattern = [ + null, // start at 1 [], [6, 18], [6, 22], @@ -82,7 +83,7 @@ class QRMatrix{ /** * @link http://www.thonky.com/qr-code-tutorial/format-version-tables */ - const versionPattern = [ + protected const versionPattern = [ // 1-based version index null, // no version pattern for QR Codes < 7 @@ -92,7 +93,7 @@ class QRMatrix{ 0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64, 0x27541, 0x28c69, ]; - const formatPattern = [ + protected const formatPattern = [ [0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976], // L [0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0], // M [0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed], // Q @@ -151,28 +152,28 @@ class QRMatrix{ /** * @return array */ - public function matrix():array { + public function matrix():array{ return $this->matrix; } /** * @return int */ - public function version():int { + public function version():int{ return $this->version; } /** * @return int */ - public function eccLevel():int { + public function eccLevel():int{ return $this->eclevel; } /** * @return int */ - public function maskPattern():int { + public function maskPattern():int{ return $this->maskPattern; } @@ -539,7 +540,7 @@ class QRMatrix{ * @return int * @throws \chillerlan\QRCode\Data\QRCodeDataException */ - protected function getMask(int $x, int $y, int $maskPattern):int { + protected function getMask(int $x, int $y, int $maskPattern):int{ $a = $y + $x; $m = $y * $x; diff --git a/src/Helpers/BitBuffer.php b/src/Helpers/BitBuffer.php index 678dac153..a9e61e870 100644 --- a/src/Helpers/BitBuffer.php +++ b/src/Helpers/BitBuffer.php @@ -12,10 +12,6 @@ namespace chillerlan\QRCode\Helpers; -/** - * @property int[] $buffer - * @property int $length - */ class BitBuffer{ /** diff --git a/src/Helpers/Polynomial.php b/src/Helpers/Polynomial.php index adedc38bf..3706b0fcf 100644 --- a/src/Helpers/Polynomial.php +++ b/src/Helpers/Polynomial.php @@ -22,7 +22,7 @@ class Polynomial{ /** * @link http://www.thonky.com/qr-code-tutorial/log-antilog-table */ - const table = [ + protected const table = [ [ 1, 0], [ 2, 0], [ 4, 1], [ 8, 25], [ 16, 2], [ 32, 50], [ 64, 26], [128, 198], [ 29, 3], [ 58, 223], [116, 51], [232, 238], [205, 27], [135, 104], [ 19, 199], [ 38, 75], [ 76, 4], [152, 100], [ 45, 224], [ 90, 14], [180, 52], [117, 141], [234, 239], [201, 129], @@ -75,7 +75,7 @@ class Polynomial{ /** * @return array */ - public function getNum():array { + public function getNum():array{ return $this->num; } @@ -85,7 +85,7 @@ class Polynomial{ * * @return \chillerlan\QRCode\Helpers\Polynomial */ - public function setNum(array $num, int $shift = null):Polynomial { + public function setNum(array $num, int $shift = null):Polynomial{ $offset = 0; $numCount = count($num); @@ -107,7 +107,7 @@ class Polynomial{ * * @return \chillerlan\QRCode\Helpers\Polynomial */ - public function multiply(array $e):Polynomial { + public function multiply(array $e):Polynomial{ $n = array_fill(0, count($this->num) + count($e) - 1, 0); foreach($this->num as $i => $vi){ @@ -153,7 +153,7 @@ class Polynomial{ * @return int * @throws \chillerlan\QRCode\QRCodeException */ - public function glog(int $n):int { + public function glog(int $n):int{ if($n < 1){ throw new QRCodeException('log('.$n.')'); @@ -167,7 +167,7 @@ class Polynomial{ * * @return int */ - public function gexp(int $n):int { + public function gexp(int $n):int{ if($n < 0){ $n += 255; diff --git a/src/Output/QRCodeOutputException.php b/src/Output/QRCodeOutputException.php index 7bfc4422d..639bdd111 100644 --- a/src/Output/QRCodeOutputException.php +++ b/src/Output/QRCodeOutputException.php @@ -4,7 +4,7 @@ * * @filesource QRCodeOutputException.php * @created 09.12.2015 - * @package chillerlan\QRCode + * @package chillerlan\QRCode\Output * @author Smiley * @copyright 2015 Smiley * @license MIT @@ -12,11 +12,6 @@ namespace chillerlan\QRCode\Output; -use Exception; +use chillerlan\QRCode\QRCodeException; -/** - * Placeholder - */ -class QRCodeOutputException extends Exception{ - -} +class QRCodeOutputException extends QRCodeException{} diff --git a/src/Output/QRImage.php b/src/Output/QRImage.php index a183e9a3e..f3b700ec8 100644 --- a/src/Output/QRImage.php +++ b/src/Output/QRImage.php @@ -15,15 +15,20 @@ namespace chillerlan\QRCode\Output; use chillerlan\QRCode\QRCode; /** - * Converts the matrix into images, raw or base64 output + * Converts the matrix into GD images, raw or base64 output + * requires ext-gd + * @link http://php.net/manual/book.image.php */ class QRImage extends QROutputAbstract{ - const TRANSPARENCY_TYPES = [ + protected const TRANSPARENCY_TYPES = [ QRCode::OUTPUT_IMAGE_PNG, QRCode::OUTPUT_IMAGE_GIF, ]; + /** + * @var string + */ protected $defaultMode = QRCode::OUTPUT_IMAGE_PNG; /** diff --git a/src/Output/QRImagick.php b/src/Output/QRImagick.php index 259963b7d..e80f18355 100644 --- a/src/Output/QRImagick.php +++ b/src/Output/QRImagick.php @@ -45,7 +45,6 @@ class QRImagick extends QROutputAbstract{ * @param string|null $file * * @return string - * @throws \chillerlan\QRCode\Output\QRCodeOutputException */ public function dump(string $file = null):string{ $file = $file ?? $this->options->cachefile; diff --git a/src/Output/QRMarkup.php b/src/Output/QRMarkup.php index 84bf1837d..bc046db9e 100644 --- a/src/Output/QRMarkup.php +++ b/src/Output/QRMarkup.php @@ -19,6 +19,9 @@ use chillerlan\QRCode\QRCode; */ class QRMarkup extends QROutputAbstract{ + /** + * @var string + */ protected $defaultMode = QRCode::OUTPUT_MARKUP_SVG; /** @@ -43,9 +46,9 @@ class QRMarkup extends QROutputAbstract{ } /** - * @return string|bool + * @return string */ - protected function html(){ + protected function html():string{ $html = ''; foreach($this->matrix->matrix() as $row){ @@ -68,9 +71,9 @@ class QRMarkup extends QROutputAbstract{ /** * @link https://github.com/codemasher/php-qrcode/pull/5 * - * @return string|bool + * @return string */ - protected function svg(){ + protected function svg():string{ $scale = $this->options->scale; $length = $this->moduleCount * $scale; $matrix = $this->matrix->matrix(); diff --git a/src/Output/QROutputAbstract.php b/src/Output/QROutputAbstract.php index d9e656ee5..8a0a0f14f 100644 --- a/src/Output/QROutputAbstract.php +++ b/src/Output/QROutputAbstract.php @@ -95,22 +95,22 @@ abstract class QROutputAbstract implements QROutputInterface{ * @param string $data * @param string $file * - * @return bool|int + * @return bool * @throws \chillerlan\QRCode\Output\QRCodeOutputException */ - protected function saveToFile(string $data, string $file) { + protected function saveToFile(string $data, string $file):bool{ if(!is_writable(dirname($file))){ throw new QRCodeOutputException('Could not write data to cache file: '.$file); } - return file_put_contents($file, $data); + return (bool)file_put_contents($file, $data); } /** * @param string|null $file * - * @return string + * @return string|mixed */ public function dump(string $file = null){ $data = call_user_func([$this, $this->outputMode ?? $this->defaultMode]); diff --git a/src/Output/QRString.php b/src/Output/QRString.php index dd7418804..8caaf81ab 100644 --- a/src/Output/QRString.php +++ b/src/Output/QRString.php @@ -19,6 +19,9 @@ use chillerlan\QRCode\QRCode; */ class QRString extends QROutputAbstract{ + /** + * @var string + */ protected $defaultMode = QRCode::OUTPUT_STRING_TEXT; /** diff --git a/src/QRCode.php b/src/QRCode.php index fd44a4713..e4cd3c14c 100755 --- a/src/QRCode.php +++ b/src/QRCode.php @@ -32,54 +32,47 @@ class QRCode{ /** * API constants */ - const OUTPUT_MARKUP_HTML = 'html'; - const OUTPUT_MARKUP_SVG = 'svg'; -# const OUTPUT_MARKUP_EPS = 'eps'; -# const OUTPUT_MARKUP_XML = 'xml'; // anyone? + public const OUTPUT_MARKUP_HTML = 'html'; + public const OUTPUT_MARKUP_SVG = 'svg'; + public const OUTPUT_IMAGE_PNG = 'png'; + public const OUTPUT_IMAGE_JPG = 'jpg'; + public const OUTPUT_IMAGE_GIF = 'gif'; + public const OUTPUT_STRING_JSON = 'json'; + public const OUTPUT_STRING_TEXT = 'text'; + public const OUTPUT_IMAGICK = 'imagick'; + public const OUTPUT_CUSTOM = 'custom'; - const OUTPUT_IMAGE_PNG = 'png'; - const OUTPUT_IMAGE_JPG = 'jpg'; - const OUTPUT_IMAGE_GIF = 'gif'; + public const VERSION_AUTO = -1; + public const MASK_PATTERN_AUTO = -1; - const OUTPUT_STRING_JSON = 'json'; - const OUTPUT_STRING_TEXT = 'text'; + public const ECC_L = 0b01; // 7%. + public const ECC_M = 0b00; // 15%. + public const ECC_Q = 0b11; // 25%. + public const ECC_H = 0b10; // 30%. - const OUTPUT_IMAGICK = 'imagick'; + public const DATA_NUMBER = 0b0001; + public const DATA_ALPHANUM = 0b0010; + public const DATA_BYTE = 0b0100; + public const DATA_KANJI = 0b1000; - const OUTPUT_CUSTOM = 'custom'; - - const VERSION_AUTO = -1; - const MASK_PATTERN_AUTO = -1; - - const ECC_L = 0b01; // 7%. - const ECC_M = 0b00; // 15%. - const ECC_Q = 0b11; // 25%. - const ECC_H = 0b10; // 30%. - - const DATA_NUMBER = 0b0001; - const DATA_ALPHANUM = 0b0010; - const DATA_BYTE = 0b0100; - const DATA_KANJI = 0b1000; - - const ECC_MODES = [ + public const ECC_MODES = [ self::ECC_L => 0, self::ECC_M => 1, self::ECC_Q => 2, self::ECC_H => 3, ]; - const DATA_MODES = [ + public const DATA_MODES = [ self::DATA_NUMBER => 0, self::DATA_ALPHANUM => 1, self::DATA_BYTE => 2, self::DATA_KANJI => 3, ]; - const OUTPUT_MODES = [ + public const OUTPUT_MODES = [ QRMarkup::class => [ self::OUTPUT_MARKUP_SVG, self::OUTPUT_MARKUP_HTML, -# self::OUTPUT_MARKUP_EPS, ], QRImage::class => [ self::OUTPUT_IMAGE_PNG, @@ -136,10 +129,7 @@ class QRCode{ * @return \chillerlan\QRCode\Data\QRMatrix * @throws \chillerlan\QRCode\Data\QRCodeDataException */ - public function getMatrix(string $data):QRMatrix { - // https://github.com/chillerlan/php-qrcode/pull/15 - // NOTE: input sanitization should be done outside - // $data = trim($data); + public function getMatrix(string $data):QRMatrix{ if(empty($data)){ throw new QRCodeDataException('QRCode::getMatrix() No data given.'); @@ -151,10 +141,7 @@ class QRCode{ ? $this->getBestMaskPattern() : min(7, max(0, (int)$this->options->maskPattern)); - $matrix = $this - ->dataInterface - ->initMatrix($maskPattern) - ; + $matrix = $this->dataInterface->initMatrix($maskPattern); if((bool)$this->options->addQuietzone){ $matrix->setQuietZone($this->options->quietzoneSize); @@ -174,9 +161,7 @@ class QRCode{ $penalties = []; for($testPattern = 0; $testPattern < 8; $testPattern++){ - $matrix = $this - ->dataInterface - ->initMatrix($testPattern, true); + $matrix = $this->dataInterface->initMatrix($testPattern, true); $penalties[$testPattern] = (new MaskPatternTester($matrix))->testPattern(); } @@ -244,7 +229,7 @@ class QRCode{ * * @return bool */ - public function isNumber(string $string):bool { + public function isNumber(string $string):bool{ return $this->checkString($string, Number::CHAR_MAP); } @@ -255,7 +240,7 @@ class QRCode{ * * @return bool */ - public function isAlphaNum(string $string):bool { + public function isAlphaNum(string $string):bool{ return $this->checkString($string, AlphaNum::CHAR_MAP); } @@ -286,7 +271,7 @@ class QRCode{ * * @return bool */ - public function isKanji(string $string):bool { + public function isKanji(string $string):bool{ $i = 0; $len = strlen($string); diff --git a/src/QRCodeException.php b/src/QRCodeException.php index b59ec658b..68af380ff 100644 --- a/src/QRCodeException.php +++ b/src/QRCodeException.php @@ -12,11 +12,4 @@ namespace chillerlan\QRCode; -use Exception; - -/** - * Placeholder - */ -class QRCodeException extends Exception{ - -} +class QRCodeException extends \Exception{} diff --git a/tests/Data/DatainterfaceTestAbstract.php b/tests/Data/DatainterfaceTestAbstract.php index 87c9428ca..d8f040250 100644 --- a/tests/Data/DatainterfaceTestAbstract.php +++ b/tests/Data/DatainterfaceTestAbstract.php @@ -12,9 +12,7 @@ namespace chillerlan\QRCodeTest\Data; -use chillerlan\QRCode\Data\QRDataInterface; -use chillerlan\QRCode\Data\QRMatrix; -use chillerlan\QRCode\QROptions; +use chillerlan\QRCode\{QROptions, Data\QRDataInterface, Data\QRMatrix}; use chillerlan\QRCodeTest\QRTestAbstract; abstract class DatainterfaceTestAbstract extends QRTestAbstract{ diff --git a/tests/Data/MaskPatternTesterTest.php b/tests/Data/MaskPatternTesterTest.php index 1adfebdb6..208ff4160 100644 --- a/tests/Data/MaskPatternTesterTest.php +++ b/tests/Data/MaskPatternTesterTest.php @@ -12,9 +12,7 @@ namespace chillerlan\QRCodeTest\Data; -use chillerlan\QRCode\Data\Byte; -use chillerlan\QRCode\Data\MaskPatternTester; -use chillerlan\QRCode\QROptions; +use chillerlan\QRCode\{QROptions, Data\Byte, Data\MaskPatternTester}; use chillerlan\QRCodeTest\QRTestAbstract; class MaskPatternTesterTest extends QRTestAbstract{ diff --git a/tests/Data/QRMatrixTest.php b/tests/Data/QRMatrixTest.php index bbbb5a5de..7b77e44c3 100755 --- a/tests/Data/QRMatrixTest.php +++ b/tests/Data/QRMatrixTest.php @@ -12,9 +12,9 @@ namespace chillerlan\QRCodeTest\Data; -use chillerlan\QRCode\Data\QRMatrix; -use chillerlan\QRCode\QRCode; +use chillerlan\QRCode\{QRCode, Data\QRMatrix}; use chillerlan\QRCodeTest\QRTestAbstract; +use ReflectionClass; class QRMatrixTest extends QRTestAbstract{ @@ -104,7 +104,7 @@ class QRMatrixTest extends QRTestAbstract{ public function testVersionPattern() { foreach (self::VERSION_REF as $version => $mask) { $hexRef = base_convert(self::VERSION_REF[$version],2 ,16); - $hexImpl = dechex(QRMatrix::versionPattern[$version]); + $hexImpl = dechex((new ReflectionClass(QRMatrix::class))->getConstant('versionPattern')[$version]); $this->assertEquals($hexRef, $hexImpl); } @@ -157,7 +157,7 @@ class QRMatrixTest extends QRTestAbstract{ ->setAlignmentPattern() ; - $alignmentPattern = QRMatrix::alignmentPattern[$this->version]; + $alignmentPattern = (new ReflectionClass(QRMatrix::class))->getConstant('alignmentPattern')[$this->version]; foreach($alignmentPattern as $py){ foreach($alignmentPattern as $px){ diff --git a/tests/Helpers/BitBufferTest.php b/tests/Helpers/BitBufferTest.php index 0f2166b11..cfb3ff963 100644 --- a/tests/Helpers/BitBufferTest.php +++ b/tests/Helpers/BitBufferTest.php @@ -12,8 +12,7 @@ namespace chillerlan\QRCodeTest\Helpers; -use chillerlan\QRCode\Helpers\BitBuffer; -use chillerlan\QRCode\QRCode; +use chillerlan\QRCode\{QRCode, Helpers\BitBuffer}; use chillerlan\QRCodeTest\QRTestAbstract; class BitBufferTest extends QRTestAbstract{ diff --git a/tests/Output/QRImageTest.php b/tests/Output/QRImageTest.php index f27be9df7..5e0493f63 100644 --- a/tests/Output/QRImageTest.php +++ b/tests/Output/QRImageTest.php @@ -12,8 +12,7 @@ namespace chillerlan\QRCodeTest\Output; -use chillerlan\QRCode\Output\QRImage; -use chillerlan\QRCode\QRCode; +use chillerlan\QRCode\{QRCode, Output\QRImage}; class QRImageTest extends QROutputTestAbstract{ @@ -21,9 +20,9 @@ class QRImageTest extends QROutputTestAbstract{ public function types(){ return [ - [QRCode::OUTPUT_IMAGE_PNG], - [QRCode::OUTPUT_IMAGE_GIF], - [QRCode::OUTPUT_IMAGE_JPG], + 'png' => [QRCode::OUTPUT_IMAGE_PNG], + 'gif' => [QRCode::OUTPUT_IMAGE_GIF], + 'jpg' => [QRCode::OUTPUT_IMAGE_JPG], ]; } @@ -32,8 +31,9 @@ class QRImageTest extends QROutputTestAbstract{ * @param $type */ public function testImageOutput($type){ - $this->options->outputType = $type; - $this->options->cachefile = $this::cachefile.$type; + $this->options->outputType = $type; + $this->options->imageBase64 = false; + $this->setOutputInterface(); $this->outputInterface->dump($this::cachefile.$type); $img = $this->outputInterface->dump(); diff --git a/tests/Output/QRMarkupTest.php b/tests/Output/QRMarkupTest.php index caa646679..ab26e45e9 100644 --- a/tests/Output/QRMarkupTest.php +++ b/tests/Output/QRMarkupTest.php @@ -12,8 +12,7 @@ namespace chillerlan\QRCodeTest\Output; -use chillerlan\QRCode\Output\QRMarkup; -use chillerlan\QRCode\QRCode; +use chillerlan\QRCode\{QRCode, Output\QRMarkup}; class QRMarkupTest extends QROutputTestAbstract{ diff --git a/tests/Output/QROutputTestAbstract.php b/tests/Output/QROutputTestAbstract.php index 5311d35e2..ce2dc394c 100644 --- a/tests/Output/QROutputTestAbstract.php +++ b/tests/Output/QROutputTestAbstract.php @@ -12,9 +12,7 @@ namespace chillerlan\QRCodeTest\Output; -use chillerlan\QRCode\Data\Byte; -use chillerlan\QRCode\Output\QROutputInterface; -use chillerlan\QRCode\QROptions; +use chillerlan\QRCode\{QROptions, Data\Byte, Output\QROutputInterface}; use chillerlan\QRCodeTest\QRTestAbstract; /** diff --git a/tests/Output/QRStringTest.php b/tests/Output/QRStringTest.php index f023b8308..059159cf7 100644 --- a/tests/Output/QRStringTest.php +++ b/tests/Output/QRStringTest.php @@ -12,8 +12,7 @@ namespace chillerlan\QRCodeTest\Output; -use chillerlan\QRCode\Output\QRString; -use chillerlan\QRCode\QRCode; +use chillerlan\QRCode\{QRCode, Output\QRString}; class QRStringTest extends QROutputTestAbstract{ diff --git a/tests/QRCodeTest.php b/tests/QRCodeTest.php index db2d3b079..06bd3aec7 100755 --- a/tests/QRCodeTest.php +++ b/tests/QRCodeTest.php @@ -50,13 +50,13 @@ class QRCodeTest extends QRTestAbstract{ public function typeDataProvider(){ return [ - [QRCode::OUTPUT_IMAGE_PNG, 'data:image/png;base64,'], - [QRCode::OUTPUT_IMAGE_GIF, 'data:image/gif;base64,'], - [QRCode::OUTPUT_IMAGE_JPG, 'data:image/jpg;base64,'], - [QRCode::OUTPUT_MARKUP_SVG, ' [QRCode::OUTPUT_IMAGE_PNG, 'data:image/png;base64,'], + 'gif' => [QRCode::OUTPUT_IMAGE_GIF, 'data:image/gif;base64,'], + 'jpg' => [QRCode::OUTPUT_IMAGE_JPG, 'data:image/jpg;base64,'], + 'svg' => [QRCode::OUTPUT_MARKUP_SVG, ' [QRCode::OUTPUT_STRING_TEXT, '⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕'.PHP_EOL], + 'json' => [QRCode::OUTPUT_STRING_JSON, '[[18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18],'], ]; } diff --git a/tests/QRTestAbstract.php b/tests/QRTestAbstract.php index a6bf95495..830951c69 100644 --- a/tests/QRTestAbstract.php +++ b/tests/QRTestAbstract.php @@ -13,9 +13,7 @@ namespace chillerlan\QRCodeTest; use PHPUnit\Framework\TestCase; -use ReflectionClass; -use ReflectionMethod; -use ReflectionProperty; +use ReflectionClass, ReflectionMethod, ReflectionProperty; abstract class QRTestAbstract extends TestCase{