From 83d5ce91df4d92a290f8cd56b1f15dd853173fa3 Mon Sep 17 00:00:00 2001 From: smiley Date: Sun, 7 Jan 2024 00:59:42 +0100 Subject: [PATCH] :shower: --- .phan/config.php | 14 ++++++------- src/Common/EccLevel.php | 1 - src/Common/GenericGFPoly.php | 1 - src/Common/MaskPattern.php | 7 +------ src/Data/AlphaNum.php | 1 - src/Data/Byte.php | 1 - src/Data/Hanzi.php | 1 - src/Data/Kanji.php | 1 - src/Data/Number.php | 1 - src/Data/QRData.php | 4 +--- src/Data/ReedSolomonEncoder.php | 6 +++--- src/Decoder/DecoderResult.php | 4 ++-- src/Decoder/ReedSolomonDecoder.php | 15 +++++++------- src/Detector/Detector.php | 3 +-- src/Output/QRGdImageJPEG.php | 4 +--- src/Output/QRGdImagePNG.php | 4 +--- src/Output/QRGdImageWEBP.php | 4 +--- src/Output/QRMarkupSVG.php | 27 ++++++++++++++----------- src/Output/QROutputAbstract.php | 32 +++++++++++++++--------------- src/Output/QRStringJSON.php | 3 +++ src/Output/QRStringText.php | 7 +------ src/QROptionsTrait.php | 11 ++++++++++ tests/Common/ECICharsetTest.php | 2 +- tests/Common/EccLevelTest.php | 3 +-- tests/Common/MaskPatternTest.php | 4 ++-- tests/Common/ModeTest.php | 2 +- tests/Common/VersionTest.php | 3 +-- 27 files changed, 77 insertions(+), 89 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index 72b796fa2..fe9461f71 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -14,8 +14,8 @@ return [ // Note that the **only** effect of choosing `'5.6'` is to infer // that functions removed in php 7.0 exist. // (See `backward_compatibility_checks` for additional options) - 'target_php_version' => null, - 'minimum_target_php_version' => '7.4', + 'target_php_version' => null, + 'minimum_target_php_version' => '7.4', // A list of directories that should be parsed for class and // method information. After excluding the directories @@ -24,19 +24,19 @@ return [ // // Thus, both first-party and third-party code being used by // your application should be included in this list. - 'directory_list' => [ + 'directory_list' => [ 'examples', 'src', 'tests', 'vendor', - '.phan/stubs' + '.phan/stubs', ], // A regex used to match every file name that you want to // exclude from parsing. Actual value will exclude every // "test", "tests", "Test" and "Tests" folders found in // "vendor/" directory. - 'exclude_file_regex' => '@^vendor/.*/(tests?|Tests?)/@', + 'exclude_file_regex' => '@^vendor/.*/(tests?|Tests?)/@', // A directory list that defines files that will be excluded // from static analysis, but whose class and method @@ -51,9 +51,9 @@ return [ // and `exclude_analysis_directory_list` arrays. 'exclude_analysis_directory_list' => [ 'vendor/', - '.phan/stubs' + '.phan/stubs', ], - 'suppress_issue_types' => [ + 'suppress_issue_types' => [ 'PhanAccessMethodInternal', 'PhanAccessOverridesFinalConstant', 'PhanDeprecatedClass', diff --git a/src/Common/EccLevel.php b/src/Common/EccLevel.php index 101785220..789d7f79d 100644 --- a/src/Common/EccLevel.php +++ b/src/Common/EccLevel.php @@ -11,7 +11,6 @@ namespace chillerlan\QRCode\Common; use chillerlan\QRCode\QRCodeException; - use function array_column; /** diff --git a/src/Common/GenericGFPoly.php b/src/Common/GenericGFPoly.php index 362853d61..ae361b9d0 100644 --- a/src/Common/GenericGFPoly.php +++ b/src/Common/GenericGFPoly.php @@ -12,7 +12,6 @@ namespace chillerlan\QRCode\Common; use chillerlan\QRCode\QRCodeException; - use function array_fill, array_slice, array_splice, count; /** diff --git a/src/Common/MaskPattern.php b/src/Common/MaskPattern.php index 177d25648..c99733716 100644 --- a/src/Common/MaskPattern.php +++ b/src/Common/MaskPattern.php @@ -11,8 +11,8 @@ namespace chillerlan\QRCode\Common; -use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\QRCodeException; +use chillerlan\QRCode\Data\QRMatrix; use Closure; use function abs, array_column, array_search, intdiv, min; @@ -94,11 +94,6 @@ final class MaskPattern{ /** * Returns a closure that applies the mask for the chosen mask pattern. * - * Encapsulates data masks for the data bits in a QR code, per ISO 18004:2006 6.8. Implementations - * of this class can un-mask a raw BitMatrix. For simplicity, they will unmask the entire BitMatrix, - * including areas used for finder patterns, timing patterns, etc. These areas should be unused - * after the point they are unmasked anyway. - * * Note that the diagram in section 6.8.1 is misleading since it indicates that $i is column position * and $j is row position. In fact, as the text says, $i is row position and $j is column position. * diff --git a/src/Data/AlphaNum.php b/src/Data/AlphaNum.php index 81d0ff3f3..77242d728 100644 --- a/src/Data/AlphaNum.php +++ b/src/Data/AlphaNum.php @@ -11,7 +11,6 @@ namespace chillerlan\QRCode\Data; use chillerlan\QRCode\Common\{BitBuffer, Mode}; - use function array_flip, ceil, intdiv, str_split; /** diff --git a/src/Data/Byte.php b/src/Data/Byte.php index a86522602..10ab85262 100644 --- a/src/Data/Byte.php +++ b/src/Data/Byte.php @@ -11,7 +11,6 @@ namespace chillerlan\QRCode\Data; use chillerlan\QRCode\Common\{BitBuffer, Mode}; - use function chr, ord; /** diff --git a/src/Data/Hanzi.php b/src/Data/Hanzi.php index e11a81d9d..4476ad9d2 100644 --- a/src/Data/Hanzi.php +++ b/src/Data/Hanzi.php @@ -11,7 +11,6 @@ namespace chillerlan\QRCode\Data; use chillerlan\QRCode\Common\{BitBuffer, Mode}; - use Throwable; use function chr, implode, intdiv, is_string, mb_convert_encoding, mb_detect_encoding, mb_detect_order, mb_internal_encoding, mb_strlen, ord, sprintf, strlen; diff --git a/src/Data/Kanji.php b/src/Data/Kanji.php index d6b6de5f7..e42f96dc3 100644 --- a/src/Data/Kanji.php +++ b/src/Data/Kanji.php @@ -11,7 +11,6 @@ namespace chillerlan\QRCode\Data; use chillerlan\QRCode\Common\{BitBuffer, Mode}; - use Throwable; use function chr, implode, intdiv, is_string, mb_convert_encoding, mb_detect_encoding, mb_detect_order, mb_internal_encoding, mb_strlen, ord, sprintf, strlen; diff --git a/src/Data/Number.php b/src/Data/Number.php index a2a7cee18..285be3736 100644 --- a/src/Data/Number.php +++ b/src/Data/Number.php @@ -11,7 +11,6 @@ namespace chillerlan\QRCode\Data; use chillerlan\QRCode\Common\{BitBuffer, Mode}; - use function array_flip, ceil, intdiv, str_split, substr, unpack; /** diff --git a/src/Data/QRData.php b/src/Data/QRData.php index e16dedb4f..7056b63e7 100644 --- a/src/Data/QRData.php +++ b/src/Data/QRData.php @@ -12,9 +12,7 @@ namespace chillerlan\QRCode\Data; use chillerlan\QRCode\Common\{BitBuffer, EccLevel, Mode, Version}; use chillerlan\Settings\SettingsContainerInterface; - -use function count; -use function sprintf; +use function count, sprintf; /** * Processes the binary data and maps it on a QRMatrix which is then being returned diff --git a/src/Data/ReedSolomonEncoder.php b/src/Data/ReedSolomonEncoder.php index 30cbd22a8..60444378c 100644 --- a/src/Data/ReedSolomonEncoder.php +++ b/src/Data/ReedSolomonEncoder.php @@ -23,8 +23,8 @@ final class ReedSolomonEncoder{ private Version $version; private EccLevel $eccLevel; - private array $interleavedData; - private int $interleavedDataIndex; + private array $interleavedData; + private int $interleavedDataIndex; /** * ReedSolomonDecoder constructor @@ -35,7 +35,7 @@ final class ReedSolomonEncoder{ } /** - * ECC interleaving + * ECC encoding and interleaving * * @throws \chillerlan\QRCode\QRCodeException */ diff --git a/src/Decoder/DecoderResult.php b/src/Decoder/DecoderResult.php index 79486f13b..02b4d7931 100644 --- a/src/Decoder/DecoderResult.php +++ b/src/Decoder/DecoderResult.php @@ -11,8 +11,8 @@ namespace chillerlan\QRCode\Decoder; -use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Common\{BitBuffer, EccLevel, MaskPattern, Version}; +use chillerlan\QRCode\Data\QRMatrix; use function property_exists; /** @@ -85,7 +85,7 @@ final class DecoderResult{ } /** - * Returns a QRMatrix instance with thesettings and data of the reader result + * Returns a QRMatrix instance with the settings and data of the reader result */ public function getQRMatrix():QRMatrix{ return (new QRMatrix($this->version, $this->eccLevel)) diff --git a/src/Decoder/ReedSolomonDecoder.php b/src/Decoder/ReedSolomonDecoder.php index ec6ac9dd7..2bd539aad 100644 --- a/src/Decoder/ReedSolomonDecoder.php +++ b/src/Decoder/ReedSolomonDecoder.php @@ -12,7 +12,6 @@ namespace chillerlan\QRCode\Decoder; use chillerlan\QRCode\Common\{BitBuffer, EccLevel, GenericGFPoly, GF256, Version}; -use chillerlan\QRCode\QRCodeException; use function array_fill, array_reverse, count; /** @@ -167,7 +166,7 @@ final class ReedSolomonDecoder{ * @param int $numEccCodewords number of error-correction codewords available * * @return int[] - * @throws \chillerlan\QRCode\QRCodeException if decoding fails for any reason + * @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException if decoding fails for any reason */ private function decodeWords(array $received, int $numEccCodewords):array{ $poly = new GenericGFPoly($received); @@ -201,7 +200,7 @@ final class ReedSolomonDecoder{ $position = ($receivedCount - 1 - GF256::log($errorLocations[$i])); if($position < 0){ - throw new QRCodeException('Bad error location'); + throw new QRCodeDecoderException('Bad error location'); } $received[$position] ^= $errorMagnitudes[$i]; @@ -212,7 +211,7 @@ final class ReedSolomonDecoder{ /** * @return \chillerlan\QRCode\Common\GenericGFPoly[] [sigma, omega] - * @throws \chillerlan\QRCode\QRCodeException + * @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException */ private function runEuclideanAlgorithm(GenericGFPoly $a, GenericGFPoly $b, int $z):array{ // Assume a's degree is >= b's @@ -240,14 +239,14 @@ final class ReedSolomonDecoder{ $t = $q->multiply($tLast)->addOrSubtract($tLastLast); if($r->getDegree() >= $rLast->getDegree()){ - throw new QRCodeException('Division algorithm failed to reduce polynomial?'); + throw new QRCodeDecoderException('Division algorithm failed to reduce polynomial?'); } } $sigmaTildeAtZero = $t->getCoefficient(0); if($sigmaTildeAtZero === 0){ - throw new QRCodeException('sigmaTilde(0) was zero'); + throw new QRCodeDecoderException('sigmaTilde(0) was zero'); } $inverse = GF256::inverse($sigmaTildeAtZero); @@ -256,7 +255,7 @@ final class ReedSolomonDecoder{ } /** - * @throws \chillerlan\QRCode\QRCodeException + * @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException */ private function findErrorLocations(GenericGFPoly $errorLocator):array{ // This is a direct application of Chien's search @@ -277,7 +276,7 @@ final class ReedSolomonDecoder{ } if($e !== $numErrors){ - throw new QRCodeException('Error locator degree does not match number of roots'); + throw new QRCodeDecoderException('Error locator degree does not match number of roots'); } return $result; diff --git a/src/Detector/Detector.php b/src/Detector/Detector.php index 949aebd53..e43798b9f 100644 --- a/src/Detector/Detector.php +++ b/src/Detector/Detector.php @@ -11,9 +11,8 @@ namespace chillerlan\QRCode\Detector; -use chillerlan\QRCode\Decoder\Binarizer; use chillerlan\QRCode\Common\{LuminanceSourceInterface, Version}; -use chillerlan\QRCode\Decoder\BitMatrix; +use chillerlan\QRCode\Decoder\{Binarizer, BitMatrix}; use function abs, intdiv, is_nan, max, min, round; use const NAN; diff --git a/src/Output/QRGdImageJPEG.php b/src/Output/QRGdImageJPEG.php index aa60f473e..6be36e2fe 100644 --- a/src/Output/QRGdImageJPEG.php +++ b/src/Output/QRGdImageJPEG.php @@ -12,9 +12,7 @@ namespace chillerlan\QRCode\Output; -use function imagejpeg; -use function max; -use function min; +use function imagejpeg, max, min; /** * GdImage jpeg output diff --git a/src/Output/QRGdImagePNG.php b/src/Output/QRGdImagePNG.php index c97a868ee..2db3fd5b4 100644 --- a/src/Output/QRGdImagePNG.php +++ b/src/Output/QRGdImagePNG.php @@ -12,9 +12,7 @@ namespace chillerlan\QRCode\Output; -use function imagepng; -use function max; -use function min; +use function imagepng, max, min; /** * GdImage png output diff --git a/src/Output/QRGdImageWEBP.php b/src/Output/QRGdImageWEBP.php index 4f00e3cb9..cf8dfa9a5 100644 --- a/src/Output/QRGdImageWEBP.php +++ b/src/Output/QRGdImageWEBP.php @@ -12,9 +12,7 @@ namespace chillerlan\QRCode\Output; -use function imagewebp; -use function max; -use function min; +use function imagewebp, max, min; /** * GdImage webp output diff --git a/src/Output/QRMarkupSVG.php b/src/Output/QRMarkupSVG.php index a7f85d49b..735c4180b 100644 --- a/src/Output/QRMarkupSVG.php +++ b/src/Output/QRMarkupSVG.php @@ -18,7 +18,10 @@ use function array_chunk, implode, is_string, preg_match, sprintf, trim; * @see https://github.com/codemasher/php-qrcode/pull/5 * @see https://developer.mozilla.org/en-US/docs/Web/SVG * @see https://www.sarasoueidan.com/demos/interactive-svg-coordinate-system/ - * @see http://apex.infogridpacific.com/SVG/svg-tutorial-contents.html + * @see https://lea.verou.me/blog/2019/05/utility-convert-svg-path-to-all-relative-or-all-absolute-commands/ + * @see https://codepen.io/leaverou/full/RmwzKv + * @see https://jakearchibald.github.io/svgomg/ + * @see https://web.archive.org/web/20200220211445/http://apex.infogridpacific.com/SVG/svg-tutorial-contents.html */ class QRMarkupSVG extends QRMarkup{ @@ -54,6 +57,17 @@ class QRMarkupSVG extends QRMarkup{ return [$this->moduleCount, $this->moduleCount]; } + /** + * @inheritDoc + */ + protected function getCssClass(int $M_TYPE = 0):string{ + return implode(' ', [ + 'qr-'.($this::LAYERNAMES[$M_TYPE] ?? $M_TYPE), + $this->matrix->isDark($M_TYPE) ? 'dark' : 'light', + $this->options->cssClass, + ]); + } + /** * @inheritDoc */ @@ -159,17 +173,6 @@ class QRMarkupSVG extends QRMarkup{ return sprintf('', $this->getCssClass($M_TYPE), $path); } - /** - * @inheritDoc - */ - protected function getCssClass(int $M_TYPE = 0):string{ - return implode(' ', [ - 'qr-'.($this::LAYERNAMES[$M_TYPE] ?? $M_TYPE), - $this->matrix->isDark($M_TYPE) ? 'dark' : 'light', - $this->options->cssClass, - ]); - } - /** * returns a path segment for a single module * diff --git a/src/Output/QROutputAbstract.php b/src/Output/QROutputAbstract.php index d8c44cc9a..fe6e08611 100644 --- a/src/Output/QROutputAbstract.php +++ b/src/Output/QROutputAbstract.php @@ -145,6 +145,22 @@ abstract class QROutputAbstract implements QROutputInterface{ } + /** + * Prepares the value for the given input () + * + * @param mixed $value + * + * @return mixed|null return value depends on the output class + */ + abstract protected function prepareModuleValue($value); + + /** + * Returns a default value for either dark or light modules + * + * @return mixed|null return value depends on the output class + */ + abstract protected function getDefaultModuleValue(bool $isDark); + /** * Returns the prepared value for the given $M_TYPE * @@ -169,22 +185,6 @@ abstract class QROutputAbstract implements QROutputInterface{ return $this->getModuleValue($this->matrix->get($x, $y)); } - /** - * Prepares the value for the given input () - * - * @param mixed $value - * - * @return mixed|null return value depends on the output class - */ - abstract protected function prepareModuleValue($value); - - /** - * Returns a default value for either dark or light modules - * - * @return mixed|null return value depends on the output class - */ - abstract protected function getDefaultModuleValue(bool $isDark); - /** * Returns a base64 data URI for the given string and mime type */ diff --git a/src/Output/QRStringJSON.php b/src/Output/QRStringJSON.php index cd942a74e..6f2e7d5e0 100644 --- a/src/Output/QRStringJSON.php +++ b/src/Output/QRStringJSON.php @@ -38,6 +38,7 @@ class QRStringJSON extends QROutputAbstract{ * unused - required by interface * * @inheritDoc + * @codeCoverageIgnore */ protected function prepareModuleValue($value):string{ return ''; @@ -47,6 +48,7 @@ class QRStringJSON extends QROutputAbstract{ * unused - required by interface * * @inheritDoc + * @codeCoverageIgnore */ protected function getDefaultModuleValue(bool $isDark):string{ return ''; @@ -56,6 +58,7 @@ class QRStringJSON extends QROutputAbstract{ * unused - required by interface * * @inheritDoc + * @codeCoverageIgnore */ public static function moduleValueIsValid($value):bool{ return true; diff --git a/src/Output/QRStringText.php b/src/Output/QRStringText.php index 3de86f9de..f475a2a68 100644 --- a/src/Output/QRStringText.php +++ b/src/Output/QRStringText.php @@ -10,12 +10,7 @@ namespace chillerlan\QRCode\Output; -use function array_map; -use function implode; -use function is_string; -use function max; -use function min; -use function sprintf; +use function array_map, implode, is_string, max, min, sprintf; /** * diff --git a/src/QROptionsTrait.php b/src/QROptionsTrait.php index 3c93b9712..d2bc8c2ce 100644 --- a/src/QROptionsTrait.php +++ b/src/QROptionsTrait.php @@ -240,12 +240,23 @@ trait QROptionsTrait{ /** * Whether to connect the paths for the several module types to avoid weird glitches when using gradients etc. * + * This option is exclusive to output classes that use the module collector `QROutputAbstract::collectModules()`, + * which converts the `$M_TYPE` of all modules to `QRMatrix::M_DATA` and `QRMatrix::M_DATA_DARK` respectively. + * + * Module types that should not be added to the connected path can be excluded via `QROptions::$excludeFromConnect`. + * + * Currentty used in `QREps` and `QRMarkupSVG`. + * + * @see \chillerlan\QRCode\Output\QROutputAbstract::collectModules() + * @see \chillerlan\QRCode\QROptionsTrait::$excludeFromConnect * @see https://github.com/chillerlan/php-qrcode/issues/57 */ protected bool $connectPaths = false; /** * Specify which paths/patterns to exclude from connecting if `QROptions::$connectPaths` is set to `true` + * + * @see \chillerlan\QRCode\QROptionsTrait::$connectPaths */ protected array $excludeFromConnect = []; diff --git a/tests/Common/ECICharsetTest.php b/tests/Common/ECICharsetTest.php index 56cb027bb..660f2cf17 100644 --- a/tests/Common/ECICharsetTest.php +++ b/tests/Common/ECICharsetTest.php @@ -10,8 +10,8 @@ namespace chillerlan\QRCodeTest\Common; -use chillerlan\QRCode\Common\ECICharset; use chillerlan\QRCode\QRCodeException; +use chillerlan\QRCode\Common\ECICharset; use PHPUnit\Framework\TestCase; final class ECICharsetTest extends TestCase{ diff --git a/tests/Common/EccLevelTest.php b/tests/Common/EccLevelTest.php index 428c84266..eec7422ad 100644 --- a/tests/Common/EccLevelTest.php +++ b/tests/Common/EccLevelTest.php @@ -10,9 +10,8 @@ namespace chillerlan\QRCodeTest\Common; -use chillerlan\QRCode\Common\EccLevel; -use chillerlan\QRCode\Common\MaskPattern; use chillerlan\QRCode\QRCodeException; +use chillerlan\QRCode\Common\{EccLevel, MaskPattern}; use PHPUnit\Framework\TestCase; /** diff --git a/tests/Common/MaskPatternTest.php b/tests/Common/MaskPatternTest.php index f64d1be92..413e7d650 100644 --- a/tests/Common/MaskPatternTest.php +++ b/tests/Common/MaskPatternTest.php @@ -13,10 +13,10 @@ namespace chillerlan\QRCodeTest\Common; -use chillerlan\QRCode\Common\MaskPattern; use chillerlan\QRCode\QRCodeException; -use Closure; +use chillerlan\QRCode\Common\MaskPattern; use PHPUnit\Framework\TestCase; +use Closure; /** * @see https://github.com/zxing/zxing/blob/f4f3c2971dc794346d8b6e14752200008cb90716/core/src/test/java/com/google/zxing/qrcode/encoder/MaskUtilTestCase.java diff --git a/tests/Common/ModeTest.php b/tests/Common/ModeTest.php index bd729129f..7e8c5f671 100644 --- a/tests/Common/ModeTest.php +++ b/tests/Common/ModeTest.php @@ -10,8 +10,8 @@ namespace chillerlan\QRCodeTest\Common; -use chillerlan\QRCode\Common\Mode; use chillerlan\QRCode\QRCodeException; +use chillerlan\QRCode\Common\Mode; use PHPUnit\Framework\TestCase; /** diff --git a/tests/Common/VersionTest.php b/tests/Common/VersionTest.php index a30c5d78a..3b6196cbc 100644 --- a/tests/Common/VersionTest.php +++ b/tests/Common/VersionTest.php @@ -10,9 +10,8 @@ namespace chillerlan\QRCodeTest\Common; -use chillerlan\QRCode\Common\EccLevel; -use chillerlan\QRCode\Common\Version; use chillerlan\QRCode\QRCodeException; +use chillerlan\QRCode\Common\{EccLevel, Version}; use PHPUnit\Framework\TestCase; /**