From f32696c8a785da78cf691728ae12355af9ff02cd Mon Sep 17 00:00:00 2001 From: smiley Date: Sun, 21 Jul 2024 14:54:15 +0200 Subject: [PATCH] :octocat: fix PHPCS config, add Slevomat rules --- .github/workflows/ci.yml | 5 +- composer.json | 6 +- examples/custom_output.php | 12 - examples/eps.php | 2 +- examples/fpdf.php | 4 +- examples/imageWithLogo.php | 10 +- examples/imageWithRoundedShapes.php | 22 +- examples/imageWithText.php | 3 - examples/imagickConvertSVGtoPNG.php | 16 +- examples/imagickImageAsBackground.php | 6 - examples/imagickWithLogo.php | 4 +- examples/intervention-image.php | 3 - examples/qrcode-interactive.php | 4 +- examples/svg.php | 2 +- examples/svgConvertViaCanvas.php | 8 +- examples/svgMeltedModules.php | 11 +- examples/svgRandomColoredDots.php | 5 +- examples/svgRoundQuietzone.php | 15 +- examples/svgWithLogo.php | 10 +- examples/svgWithLogoAndCustomShapes.php | 12 +- examples/xml.php | 5 +- phpcs.xml.dist | 338 +++++++++++++++-------- src/Common/GDLuminanceSource.php | 5 - src/Common/GenericGFPoly.php | 13 - src/Common/IMagickLuminanceSource.php | 5 - src/Common/LuminanceSourceAbstract.php | 10 - src/Common/LuminanceSourceInterface.php | 1 + src/Data/AlphaNum.php | 14 +- src/Data/Byte.php | 12 - src/Data/ECI.php | 9 +- src/Data/Hanzi.php | 12 - src/Data/Kanji.php | 12 - src/Data/Number.php | 24 +- src/Data/QRData.php | 4 +- src/Data/QRDataModeAbstract.php | 3 - src/Data/QRMatrix.php | 2 + src/Decoder/Binarizer.php | 6 - src/Decoder/BitMatrix.php | 11 +- src/Decoder/Decoder.php | 6 - src/Decoder/DecoderResult.php | 11 +- src/Decoder/ReedSolomonDecoder.php | 4 +- src/Detector/AlignmentPattern.php | 2 +- src/Detector/AlignmentPatternFinder.php | 17 +- src/Detector/Detector.php | 9 +- src/Detector/FinderPattern.php | 24 +- src/Detector/FinderPatternFinder.php | 18 +- src/Detector/GridSampler.php | 18 +- src/Detector/PerspectiveTransform.php | 29 +- src/Detector/ResultPoint.php | 12 - src/Output/QREps.php | 14 +- src/Output/QRFpdf.php | 9 +- src/Output/QRGdImage.php | 24 +- src/Output/QRGdImageAVIF.php | 3 - src/Output/QRGdImageBMP.php | 3 - src/Output/QRGdImageGIF.php | 3 - src/Output/QRGdImageJPEG.php | 6 - src/Output/QRGdImagePNG.php | 3 - src/Output/QRGdImageWEBP.php | 3 - src/Output/QRImagick.php | 31 ++- src/Output/QRInterventionImage.php | 8 +- src/Output/QRMarkup.php | 3 - src/Output/QRMarkupHTML.php | 5 +- src/Output/QRMarkupSVG.php | 13 +- src/Output/QRMarkupXML.php | 9 +- src/Output/QRStringJSON.php | 15 +- src/Output/QRStringText.php | 8 +- src/QRCode.php | 4 +- src/QROptionsTrait.php | 7 +- tests/BuildDirTrait.php | 10 +- tests/Data/ByteTest.php | 6 - tests/Data/DataInterfaceTestAbstract.php | 2 +- tests/Data/HanziTest.php | 4 +- tests/Data/KanjiTest.php | 4 +- tests/Data/QRDataTest.php | 3 - tests/Data/QRMatrixTest.php | 2 +- tests/Output/QREpsTest.php | 5 +- tests/Output/QRFpdfTest.php | 8 +- tests/Output/QRGdImageAVIFTest.php | 5 +- tests/Output/QRGdImageBMPTest.php | 5 +- tests/Output/QRGdImageGIFTest.php | 5 +- tests/Output/QRGdImageJPGTest.php | 5 +- tests/Output/QRGdImagePNGTest.php | 5 +- tests/Output/QRGdImageTestAbstract.php | 6 - tests/Output/QRGdImageWEBPTest.php | 5 +- tests/Output/QRImagickTest.php | 8 +- tests/Output/QRInterventionImageTest.php | 8 +- tests/Output/QRMarkupHTMLTest.php | 5 +- tests/Output/QRMarkupSVGTest.php | 5 +- tests/Output/QRMarkupTestAbstract.php | 3 - tests/Output/QRMarkupXMLTest.php | 3 - tests/Output/QRStringJSONTest.php | 8 +- tests/Output/QRStringTextTest.php | 8 +- tests/QRCodeReaderGDTest.php | 2 +- tests/QRCodeReaderImagickTest.php | 2 +- tests/QRCodeReaderTestAbstract.php | 13 +- tests/QRMatrixDebugTrait.php | 2 +- tests/QRMaxLengthTrait.php | 2 +- 97 files changed, 462 insertions(+), 654 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 470d9bdb0..a35584289 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,11 +47,12 @@ jobs: - name: "Install dependencies with composer" uses: ramsey/composer-install@v3 - - name: "Run phan" - run: php vendor/bin/phan --target-php-version=${{ matrix.php-version }} - name: "Run PHPStan" run: php vendor/bin/phpstan + - name: "Run PHP_CodeSniffer" + run: php vendor/bin/phpstan + tests: name: "Unit Tests" diff --git a/composer.json b/composer.json index 9a8ca86a6..c49d95bcf 100644 --- a/composer.json +++ b/composer.json @@ -60,6 +60,7 @@ "phpstan/phpstan": "^1.11", "phpstan/phpstan-deprecation-rules": "^1.2", "setasign/fpdf": "^1.8.2", + "slevomat/coding-standard": "^8.15", "squizlabs/php_codesniffer": "^3.10" }, "suggest": { @@ -92,6 +93,9 @@ "config": { "lock": false, "sort-packages": true, - "platform-check": true + "platform-check": true, + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/examples/custom_output.php b/examples/custom_output.php index 69ec5737f..02d453778 100644 --- a/examples/custom_output.php +++ b/examples/custom_output.php @@ -21,33 +21,21 @@ require_once __DIR__.'/../vendor/autoload.php'; class MyCustomOutput extends QROutputAbstract{ - /** - * @inheritDoc - */ public static function moduleValueIsValid(mixed $value):bool{ // TODO: Implement moduleValueIsValid() method. (interface) return false; } - /** - * @inheritDoc - */ protected function prepareModuleValue(mixed $value):mixed{ // TODO: Implement prepareModuleValue() method. (abstract) return null; } - /** - * @inheritDoc - */ protected function getDefaultModuleValue(bool $isDark):mixed{ // TODO: Implement getDefaultModuleValue() method. (abstract) return null; } - /** - * @inheritDoc - */ public function dump(string|null $file = null):string{ $output = ''; diff --git a/examples/eps.php b/examples/eps.php index d68b18423..a15d17152 100644 --- a/examples/eps.php +++ b/examples/eps.php @@ -55,7 +55,7 @@ $options->moduleValues = [ $out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ', __DIR__.'/qrcode.eps'); -if(php_sapi_name() !== 'cli'){ +if(PHP_SAPI !== 'cli'){ // if viewed in the browser, we should push it as file download as EPS isn't usually supported header('Content-type: application/postscript'); header('Content-Disposition: filename="qrcode.eps"'); diff --git a/examples/fpdf.php b/examples/fpdf.php index f4f30fa11..f039f5828 100644 --- a/examples/fpdf.php +++ b/examples/fpdf.php @@ -11,7 +11,7 @@ use chillerlan\QRCode\{QRCode, QROptions}; use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Output\QRFpdf; -require_once __DIR__ . '/../vendor/autoload.php'; +require_once __DIR__.'/../vendor/autoload.php'; $options = new QROptions; @@ -53,7 +53,7 @@ $options->moduleValues = [ $out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ'); -if(php_sapi_name() !== 'cli'){ +if(PHP_SAPI !== 'cli'){ header('Content-type: application/pdf'); } diff --git a/examples/imageWithLogo.php b/examples/imageWithLogo.php index 35b447535..6aa92a1d3 100644 --- a/examples/imageWithLogo.php +++ b/examples/imageWithLogo.php @@ -24,13 +24,11 @@ require_once __DIR__.'/../vendor/autoload.php'; class QRImageWithLogo extends QRGdImagePNG{ /** - * @param string|null $file - * @param string|null $logo - * - * @return string * @throws \chillerlan\QRCode\Output\QRCodeOutputException */ public function dump(string|null $file = null, string|null $logo = null):string{ + $logo ??= ''; + // set returnResource to true to skip further processing for now $this->options->returnResource = true; @@ -45,6 +43,10 @@ class QRImageWithLogo extends QRGdImagePNG{ $im = imagecreatefrompng($logo); + if($im === false){ + throw new QRCodeOutputException('imagecreatefrompng() error'); + } + // get logo image size $w = imagesx($im); $h = imagesy($im); diff --git a/examples/imageWithRoundedShapes.php b/examples/imageWithRoundedShapes.php index bfaebebfc..5e349b207 100644 --- a/examples/imageWithRoundedShapes.php +++ b/examples/imageWithRoundedShapes.php @@ -19,7 +19,7 @@ use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Output\QRGdImagePNG; use chillerlan\Settings\SettingsContainerInterface; -require_once __DIR__ . '/../vendor/autoload.php'; +require_once __DIR__.'/../vendor/autoload.php'; // -------------------- // Class definition @@ -27,7 +27,6 @@ require_once __DIR__ . '/../vendor/autoload.php'; class QRGdRounded extends QRGdImagePNG{ - /** @inheritDoc */ public function __construct(SettingsContainerInterface|QROptions $options, QRMatrix $matrix){ // enable the internal scaling for better rounding results at scale < 20 $options->drawCircularModules = true; @@ -35,7 +34,6 @@ class QRGdRounded extends QRGdImagePNG{ parent::__construct($options, $matrix); } - /** @inheritDoc */ protected function module(int $x, int $y, int $M_TYPE):void{ /** @@ -121,7 +119,7 @@ class QRGdRounded extends QRGdImagePNG{ (int)($y * $this->scale + $this->scale / 2), ($this->scale - 1), ($this->scale - 1), - $light + $light, ); } @@ -133,14 +131,14 @@ class QRGdRounded extends QRGdImagePNG{ // -------------------- $options = new QROptions([ - 'version' => 7, - 'eccLevel' => EccLevel::H, - 'outputInterface' => QRGdRounded::class, - 'outputBase64' => false, - 'scale' => 30, - 'addLogoSpace' => true, - 'logoSpaceWidth' => 13, - 'logoSpaceHeight' => 13, + 'version' => 7, + 'eccLevel' => EccLevel::H, + 'outputInterface' => QRGdRounded::class, + 'outputBase64' => false, + 'scale' => 30, + 'addLogoSpace' => true, + 'logoSpaceWidth' => 13, + 'logoSpaceHeight' => 13, ]); diff --git a/examples/imageWithText.php b/examples/imageWithText.php index be71e220b..d80ea8f1f 100644 --- a/examples/imageWithText.php +++ b/examples/imageWithText.php @@ -23,9 +23,6 @@ require_once __DIR__.'/../vendor/autoload.php'; class QRImageWithText extends QRGdImagePNG{ - /** - * @inheritDoc - */ public function dump(string|null $file = null, string|null $text = null):string{ // set returnResource to true to skip further processing for now $this->options->returnResource = true; diff --git a/examples/imagickConvertSVGtoPNG.php b/examples/imagickConvertSVGtoPNG.php index c4351f39c..fa63568bc 100644 --- a/examples/imagickConvertSVGtoPNG.php +++ b/examples/imagickConvertSVGtoPNG.php @@ -14,17 +14,18 @@ * @author smiley * @copyright 2023 smiley * @license MIT + * + * @noinspection PhpComposerExtensionStubsInspection */ use chillerlan\QRCode\{QRCode, QROptions}; use chillerlan\QRCode\Data\QRMatrix; -use chillerlan\QRCode\Output\QRMarkupSVG; +use chillerlan\QRCode\Output\{QRCodeOutputException, QRMarkupSVG}; require_once __DIR__.'/../vendor/autoload.php'; class SVGConvert extends QRMarkupSVG{ - /** @inheritDoc */ protected function header():string{ [$width, $height] = $this->getOutputDimensions(); @@ -36,7 +37,7 @@ class SVGConvert extends QRMarkupSVG{ $this->options->svgPreserveAspectRatio, $this->options->eol, ($width * $this->scale), // use the scale option to modify the size - ($height * $this->scale) + ($height * $this->scale), ); if($this->options->svgAddXmlHeader){ @@ -46,7 +47,6 @@ class SVGConvert extends QRMarkupSVG{ return $header; } - /** @inheritDoc */ public function dump(string|null $file = null):string{ $base64 = $this->options->outputBase64; // we don't want the SVG in base64 @@ -70,7 +70,13 @@ class SVGConvert extends QRMarkupSVG{ if($base64){ // use finfo to guess the mime type - $imageData = $this->toBase64DataURI($imageData, (new finfo(FILEINFO_MIME_TYPE))->buffer($imageData)); + $mime = (new finfo(FILEINFO_MIME_TYPE))->buffer($imageData); + + if($mime === false){ + throw new QRCodeOutputException('unable to detect mime type'); + } + + $imageData = $this->toBase64DataURI($imageData); } return $imageData; diff --git a/examples/imagickImageAsBackground.php b/examples/imagickImageAsBackground.php index 1e5d039dc..815e1d048 100644 --- a/examples/imagickImageAsBackground.php +++ b/examples/imagickImageAsBackground.php @@ -16,17 +16,11 @@ require_once __DIR__.'/../vendor/autoload.php'; class QRImagickImageAsBackground extends QRImagick{ - /** - * @inheritDoc - */ protected function getDefaultModuleValue(bool $isDark):ImagickPixel{ // RGBA, adjust opacity to increase contrast return $this->prepareModuleValue(($isDark) ? '#00000040' : '#ffffffa0'); } - /** - * @inheritDoc - */ protected function createImage():Imagick{ $imagick = new Imagick($this->options->background); $width = $imagick->getImageWidth(); diff --git a/examples/imagickWithLogo.php b/examples/imagickWithLogo.php index b89b1fc02..be6cf89e6 100644 --- a/examples/imagickWithLogo.php +++ b/examples/imagickWithLogo.php @@ -55,7 +55,7 @@ class QRImagickWithLogo extends QRImagick{ $this->saveToFile($imageData, $file); if($this->options->outputBase64){ - $imageData = $this->toBase64DataURI($imageData, (new finfo(FILEINFO_MIME_TYPE))->buffer($imageData)); + $imageData = $this->toBase64DataURI($imageData, $this->guessMimeType($imageData)); } return $imageData; @@ -77,6 +77,8 @@ class ImagickWithLogoOptions extends QROptions{ * * of course, we could accept other formats too. * we're not checking for the file type either for simplicity reasons (assuming PNG) + * + * @throws \chillerlan\QRCode\QRCodeException */ protected function set_pngLogo(string $pngLogo):void{ diff --git a/examples/intervention-image.php b/examples/intervention-image.php index 3593216b6..33e863f2f 100644 --- a/examples/intervention-image.php +++ b/examples/intervention-image.php @@ -75,6 +75,3 @@ header('Content-type: image/png'); echo $out; exit; - - - diff --git a/examples/qrcode-interactive.php b/examples/qrcode-interactive.php index e602b72dd..1173513ea 100644 --- a/examples/qrcode-interactive.php +++ b/examples/qrcode-interactive.php @@ -56,7 +56,7 @@ try{ $moduleValues = array_map(function($v){ if(preg_match('/[a-f\d]{6}/i', $v) === 1){ - return in_array($_POST['output_type'], ['png', 'jpg', 'gif']) + return in_array($_POST['output_type'], ['png', 'jpg', 'gif'], true) ? array_map('hexdec', str_split($v, 2)) : '#'.$v ; } @@ -81,7 +81,7 @@ try{ $qrcode = (new QRCode($options))->render($_POST['inputstring']); - if(in_array($_POST['output_type'], ['png', 'jpg', 'gif', 'svg'])){ + if(in_array($_POST['output_type'], ['png', 'jpg', 'gif', 'svg'], true)){ $qrcode = 'qrcode'; } elseif($_POST['output_type'] === 'text'){ diff --git a/examples/svg.php b/examples/svg.php index e60561d2a..a04863515 100644 --- a/examples/svg.php +++ b/examples/svg.php @@ -60,7 +60,7 @@ catch(Throwable $e){ } -if(php_sapi_name() !== 'cli'){ +if(PHP_SAPI !== 'cli'){ header('Content-type: image/svg+xml'); if(extension_loaded('zlib')){ diff --git a/examples/svgConvertViaCanvas.php b/examples/svgConvertViaCanvas.php index ac9bf1f04..830cfa743 100644 --- a/examples/svgConvertViaCanvas.php +++ b/examples/svgConvertViaCanvas.php @@ -80,9 +80,9 @@ header('Content-type: text/html'); diff --git a/examples/svgMeltedModules.php b/examples/svgMeltedModules.php index b338e8000..7db76b3c8 100644 --- a/examples/svgMeltedModules.php +++ b/examples/svgMeltedModules.php @@ -26,17 +26,11 @@ require_once __DIR__.'/../vendor/autoload.php'; */ class MeltedSVGQRCodeOutput extends QRMarkupSVG{ - /** - * @inheritDoc - */ protected function path(string $path, int $M_TYPE):string{ // omit the "fill" and "opacity" attributes on the path element return sprintf('', $this->getCssClass($M_TYPE), $path); } - /** - * @inheritDoc - */ protected function collectModules(Closure $transform):array{ $paths = []; $melt = $this->options->melt; // avoid magic getter in long loops @@ -76,9 +70,6 @@ class MeltedSVGQRCodeOutput extends QRMarkupSVG{ return $paths; } - /** - * @inheritDoc - */ protected function module(int $x, int $y, int $M_TYPE):string{ $bits = $this->matrix->checkNeighbours($x, $y, null); $check = fn(int $all, int $any = 0):bool => ($bits & ($all | (~$any & 0xff))) === $all; @@ -289,7 +280,7 @@ $options->svgDefs = ' $out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ'); -if(php_sapi_name() !== 'cli'){ +if(PHP_SAPI !== 'cli'){ header('Content-type: image/svg+xml'); if(extension_loaded('zlib')){ diff --git a/examples/svgRandomColoredDots.php b/examples/svgRandomColoredDots.php index e6bb62068..5c86fdbe0 100644 --- a/examples/svgRandomColoredDots.php +++ b/examples/svgRandomColoredDots.php @@ -26,9 +26,6 @@ require_once __DIR__.'/../vendor/autoload.php'; // the extended SVG output module class RandomDotsSVGOutput extends QRMarkupSVG{ - /** - * @inheritDoc - */ protected function path(string $path, int $M_TYPE):string{ // omit the "fill" and "opacity" attributes on the path element return sprintf('', $this->getCssClass($M_TYPE), $path); @@ -160,7 +157,7 @@ $out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgX // dump the output -if(php_sapi_name() !== 'cli'){ +if(PHP_SAPI !== 'cli'){ header('content-type: image/svg+xml'); } diff --git a/examples/svgRoundQuietzone.php b/examples/svgRoundQuietzone.php index e8959b202..05407ca6f 100644 --- a/examples/svgRoundQuietzone.php +++ b/examples/svgRoundQuietzone.php @@ -31,9 +31,6 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{ protected float $center; - /** - * @inheritDoc - */ protected function createMarkup(bool $saveToFile):string{ // some Pythagorean magick $diameter = sqrt(2 * pow(($this->moduleCount + $this->options->additionalModules), 2)); @@ -69,9 +66,6 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{ return $svg; } - /** - * @inheritDoc - */ protected function path(string $path, int $M_TYPE):string{ // omit the "fill" and "opacity" attributes on the path element return sprintf('', $this->getCssClass($M_TYPE), $path); @@ -141,7 +135,7 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{ $this->center, round($radius, 5), ($this->options->circleRadius * 2), - $this->options->eol + $this->options->eol, ); } @@ -159,13 +153,10 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{ $this->options->svgLogoScale, $this->options->svgLogoCssClass, file_get_contents($this->options->svgLogo), - $this->options->eol + $this->options->eol, ); } - /** - * @inheritDoc - */ protected function collectModules(Closure $transform):array{ $paths = []; $dotColors = $this->options->dotColors; // avoid magic getter in long loops @@ -345,7 +336,7 @@ $options->keepAsSquare = [ $out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ'); -if(php_sapi_name() !== 'cli'){ +if(PHP_SAPI !== 'cli'){ header('Content-type: image/svg+xml'); if(extension_loaded('zlib')){ diff --git a/examples/svgWithLogo.php b/examples/svgWithLogo.php index d61cde436..bf0750ff2 100644 --- a/examples/svgWithLogo.php +++ b/examples/svgWithLogo.php @@ -26,9 +26,6 @@ require_once __DIR__.'/../vendor/autoload.php'; */ class QRSvgWithLogo extends QRMarkupSVG{ - /** - * @inheritDoc - */ protected function paths():string{ $size = (int)ceil($this->moduleCount * $this->options->svgLogoScale); @@ -41,9 +38,6 @@ class QRSvgWithLogo extends QRMarkupSVG{ return $svg; } - /** - * @inheritDoc - */ protected function path(string $path, int $M_TYPE):string{ // omit the "fill" and "opacity" attributes on the path element return sprintf('', $this->getCssClass($M_TYPE), $path); @@ -63,7 +57,7 @@ class QRSvgWithLogo extends QRMarkupSVG{ $this->options->svgLogoScale, $this->options->svgLogoCssClass, file_get_contents($this->options->svgLogo), - $this->options->eol + $this->options->eol, ); } @@ -146,7 +140,7 @@ $options->svgDefs = ' $out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ'); -if(php_sapi_name() !== 'cli'){ +if(PHP_SAPI !== 'cli'){ header('Content-type: image/svg+xml'); if(extension_loaded('zlib')){ diff --git a/examples/svgWithLogoAndCustomShapes.php b/examples/svgWithLogoAndCustomShapes.php index 924fe2a22..2298ded20 100644 --- a/examples/svgWithLogoAndCustomShapes.php +++ b/examples/svgWithLogoAndCustomShapes.php @@ -28,9 +28,6 @@ require_once __DIR__.'/../vendor/autoload.php'; */ class QRSvgWithLogoAndCustomShapes extends QRMarkupSVG{ - /** - * @inheritDoc - */ protected function paths():string{ // make sure connect paths is enabled $this->options->connectPaths = true; @@ -48,9 +45,6 @@ class QRSvgWithLogoAndCustomShapes extends QRMarkupSVG{ return $svg; } - /** - * @inheritDoc - */ protected function path(string $path, int $M_TYPE):string{ // omit the "fill" and "opacity" attributes on the path element return sprintf('', $this->getCssClass($M_TYPE), $path); @@ -103,7 +97,7 @@ class QRSvgWithLogoAndCustomShapes extends QRMarkupSVG{ '%s', $this->options->eol, $this->getCssClass(QRMatrix::M_FINDER_DARK), - implode(' ', $finder) + implode(' ', $finder), ); } @@ -121,7 +115,7 @@ class QRSvgWithLogoAndCustomShapes extends QRMarkupSVG{ $this->options->svgLogoScale, $this->options->svgLogoCssClass, file_get_contents($this->options->svgLogo), - $this->options->eol + $this->options->eol, ); } @@ -199,7 +193,7 @@ $options->svgDefs = ' $out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ'); -if(php_sapi_name() !== 'cli'){ +if(PHP_SAPI !== 'cli'){ header('Content-type: image/svg+xml'); if(extension_loaded('zlib')){ diff --git a/examples/xml.php b/examples/xml.php index 5ed68e2da..ad6a9a527 100644 --- a/examples/xml.php +++ b/examples/xml.php @@ -8,7 +8,8 @@ * @license MIT */ -use chillerlan\QRCode\{Data\QRMatrix, QRCode, QROptions}; +use chillerlan\QRCode\Data\QRMatrix; +use chillerlan\QRCode\{QRCode, QROptions}; use chillerlan\QRCode\Output\QRMarkupXML; require_once __DIR__.'/../vendor/autoload.php'; @@ -61,7 +62,7 @@ catch(Throwable $e){ } -if(php_sapi_name() !== 'cli'){ +if(PHP_SAPI !== 'cli'){ header('Content-type: '.QRMarkupXML::MIME_TYPE); } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 315dd3aa3..b7dbe05c3 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -9,35 +9,207 @@ tests + error + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + examples + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + examples + + + + examples + + + + + @@ -46,10 +218,17 @@ - + + examples + + + + + + @@ -65,127 +244,62 @@ - + - + - + - + + + + + - - - - - - - - - - - - + - + - - - - - - - - - - - - - - error - - - - error - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - examples + + + + - - examples + + + + - - examples - - - - examples - - - - examples + + + + diff --git a/src/Common/GDLuminanceSource.php b/src/Common/GDLuminanceSource.php index 60402683d..32f6be051 100644 --- a/src/Common/GDLuminanceSource.php +++ b/src/Common/GDLuminanceSource.php @@ -54,9 +54,6 @@ final class GDLuminanceSource extends LuminanceSourceAbstract{ $this->setLuminancePixels(); } - /** - * - */ private function setLuminancePixels():void{ for($j = 0; $j < $this->height; $j++){ @@ -70,12 +67,10 @@ final class GDLuminanceSource extends LuminanceSourceAbstract{ } - /** @inheritDoc */ public static function fromFile(string $path, SettingsContainerInterface|QROptions $options = new QROptions):static{ return new self(imagecreatefromstring(file_get_contents(self::checkFile($path))), $options); } - /** @inheritDoc */ public static function fromBlob(string $blob, SettingsContainerInterface|QROptions $options = new QROptions):static{ return new self(imagecreatefromstring($blob), $options); } diff --git a/src/Common/GenericGFPoly.php b/src/Common/GenericGFPoly.php index 161bc7635..da1fcaefc 100644 --- a/src/Common/GenericGFPoly.php +++ b/src/Common/GenericGFPoly.php @@ -31,7 +31,6 @@ final class GenericGFPoly{ /** * @param int[] $coefficients array coefficients as ints representing elements of GF(size), arranged * from most significant (highest-power term) coefficient to the least significant - * @param int|null $degree * * @throws \chillerlan\QRCode\QRCodeException if argument is null or empty, or if leading coefficient is 0 and this * is not a constant polynomial (that is, it is not the monomial "0") @@ -116,9 +115,6 @@ final class GenericGFPoly{ return $result; } - /** - * - */ public function multiply(GenericGFPoly $other):self{ if($this->isZero() || $other->isZero()){ @@ -163,9 +159,6 @@ final class GenericGFPoly{ } - /** - * - */ public function multiplyInt(int $scalar):self{ if($scalar === 0){ @@ -207,9 +200,6 @@ final class GenericGFPoly{ return new self($product); } - /** - * - */ public function mod(GenericGFPoly $other):self{ if((count($this->coefficients) - count($other->coefficients)) < 0){ @@ -225,9 +215,6 @@ final class GenericGFPoly{ return (new self($this->coefficients))->mod($other); } - /** - * - */ public function addOrSubtract(GenericGFPoly $other):self{ if($this->isZero()){ diff --git a/src/Common/IMagickLuminanceSource.php b/src/Common/IMagickLuminanceSource.php index 0ed37a62d..1e1b01b08 100644 --- a/src/Common/IMagickLuminanceSource.php +++ b/src/Common/IMagickLuminanceSource.php @@ -51,9 +51,6 @@ final class IMagickLuminanceSource extends LuminanceSourceAbstract{ $this->setLuminancePixels(); } - /** - * - */ private function setLuminancePixels():void{ $pixels = $this->imagick->exportImagePixels(1, 1, $this->width, $this->height, 'RGB', Imagick::PIXEL_CHAR); $count = count($pixels); @@ -63,12 +60,10 @@ final class IMagickLuminanceSource extends LuminanceSourceAbstract{ } } - /** @inheritDoc */ public static function fromFile(string $path, SettingsContainerInterface|QROptions $options = new QROptions):static{ return new self(new Imagick(self::checkFile($path)), $options); } - /** @inheritDoc */ public static function fromBlob(string $blob, SettingsContainerInterface|QROptions $options = new QROptions):static{ $im = new Imagick; $im->readImageBlob($blob); diff --git a/src/Common/LuminanceSourceAbstract.php b/src/Common/LuminanceSourceAbstract.php index a69e410e7..e92507b2a 100644 --- a/src/Common/LuminanceSourceAbstract.php +++ b/src/Common/LuminanceSourceAbstract.php @@ -31,9 +31,6 @@ abstract class LuminanceSourceAbstract implements LuminanceSourceInterface{ protected int $width; protected int $height; - /** - * - */ public function __construct(int $width, int $height, SettingsContainerInterface|QROptions $options = new QROptions){ $this->width = $width; $this->height = $height; @@ -42,22 +39,18 @@ abstract class LuminanceSourceAbstract implements LuminanceSourceInterface{ $this->luminances = []; } - /** @inheritDoc */ public function getLuminances():array{ return $this->luminances; } - /** @inheritDoc */ public function getWidth():int{ return $this->width; } - /** @inheritDoc */ public function getHeight():int{ return $this->height; } - /** @inheritDoc */ public function getRow(int $y):array{ if($y < 0 || $y >= $this->getHeight()){ @@ -71,9 +64,6 @@ abstract class LuminanceSourceAbstract implements LuminanceSourceInterface{ return $arr; } - /** - * - */ protected function setLuminancePixel(int $r, int $g, int $b):void{ $this->luminances[] = ($r === $g && $g === $b) // Image is already greyscale, so pick any channel. diff --git a/src/Common/LuminanceSourceInterface.php b/src/Common/LuminanceSourceInterface.php index 59efc8393..209b52af0 100644 --- a/src/Common/LuminanceSourceInterface.php +++ b/src/Common/LuminanceSourceInterface.php @@ -14,6 +14,7 @@ use chillerlan\QRCode\QROptions; use chillerlan\Settings\SettingsContainerInterface; /** + * Interface for the luminance sources */ interface LuminanceSourceInterface{ diff --git a/src/Data/AlphaNum.php b/src/Data/AlphaNum.php index 23a90ad23..4cfc9fb9d 100644 --- a/src/Data/AlphaNum.php +++ b/src/Data/AlphaNum.php @@ -27,7 +27,9 @@ final class AlphaNum extends QRDataModeAbstract{ * @var int[] */ private const CHAR_TO_ORD = [ + // phpcs:ignore '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, + // phpcs:ignore '8' => 8, '9' => 9, 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20, 'L' => 21, 'M' => 22, 'N' => 23, 'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27, 'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31, @@ -47,21 +49,12 @@ final class AlphaNum extends QRDataModeAbstract{ '+', '-', '.', '/', ':', ]; - /** - * @inheritDoc - */ public const DATAMODE = Mode::ALPHANUM; - /** - * @inheritDoc - */ public function getLengthInBits():int{ return (int)ceil($this->getCharCount() * (11 / 2)); } - /** - * @inheritDoc - */ public static function validateString(string $string):bool{ if($string === ''){ @@ -77,9 +70,6 @@ final class AlphaNum extends QRDataModeAbstract{ return true; } - /** - * @inheritDoc - */ public function write(BitBuffer $bitBuffer, int $versionNumber):static{ $len = $this->getCharCount(); diff --git a/src/Data/Byte.php b/src/Data/Byte.php index 77d090dea..7896530d0 100644 --- a/src/Data/Byte.php +++ b/src/Data/Byte.php @@ -21,28 +21,16 @@ use function chr, ord; */ final class Byte extends QRDataModeAbstract{ - /** - * @inheritDoc - */ public const DATAMODE = Mode::BYTE; - /** - * @inheritDoc - */ public function getLengthInBits():int{ return ($this->getCharCount() * 8); } - /** - * @inheritDoc - */ public static function validateString(string $string):bool{ return $string !== ''; } - /** - * @inheritDoc - */ public function write(BitBuffer $bitBuffer, int $versionNumber):static{ $len = $this->getCharCount(); diff --git a/src/Data/ECI.php b/src/Data/ECI.php index 396d5bbf7..bd4916ed6 100644 --- a/src/Data/ECI.php +++ b/src/Data/ECI.php @@ -22,9 +22,6 @@ use function mb_convert_encoding, mb_detect_encoding, mb_internal_encoding, spri */ final class ECI extends QRDataModeAbstract{ - /** - * @inheritDoc - */ public const DATAMODE = Mode::ECI; /** @@ -34,6 +31,7 @@ final class ECI extends QRDataModeAbstract{ /** * @inheritDoc + * @throws \chillerlan\QRCode\Data\QRCodeDataException * @noinspection PhpMissingParentConstructorInspection */ public function __construct(int $encoding){ @@ -45,9 +43,6 @@ final class ECI extends QRDataModeAbstract{ $this->encoding = $encoding; } - /** - * @inheritDoc - */ public function getLengthInBits():int{ if($this->encoding < 128){ @@ -107,7 +102,7 @@ final class ECI extends QRDataModeAbstract{ $id = ((($firstByte & 0b00011111) << 16) | $bitBuffer->read(16)); } else{ - throw new QRCodeDataException(sprintf('error decoding ECI value first byte: %08b', $firstByte)); // @codeCoverageIgnore + throw new QRCodeDataException(sprintf('error decoding ECI value first byte: %08b', $firstByte));// @codeCoverageIgnore } return new ECICharset($id); diff --git a/src/Data/Hanzi.php b/src/Data/Hanzi.php index ec96793ce..5c469187c 100644 --- a/src/Data/Hanzi.php +++ b/src/Data/Hanzi.php @@ -43,28 +43,16 @@ final class Hanzi extends QRDataModeAbstract{ */ public const GB2312_SUBSET = 0b0001; - /** - * @inheritDoc - */ public const DATAMODE = Mode::HANZI; - /** - * @inheritDoc - */ protected function getCharCount():int{ return mb_strlen($this->data, self::ENCODING); } - /** - * @inheritDoc - */ public function getLengthInBits():int{ return ($this->getCharCount() * 13); } - /** - * @inheritDoc - */ public static function convertEncoding(string $string):string{ mb_detect_order([mb_internal_encoding(), 'UTF-8', 'GB2312', 'GB18030', 'CP936', 'EUC-CN', 'HZ']); diff --git a/src/Data/Kanji.php b/src/Data/Kanji.php index 8c95cc71b..e27b65a36 100644 --- a/src/Data/Kanji.php +++ b/src/Data/Kanji.php @@ -36,28 +36,16 @@ final class Kanji extends QRDataModeAbstract{ */ public const ENCODING = 'SJIS'; - /** - * @inheritDoc - */ public const DATAMODE = Mode::KANJI; - /** - * @inheritDoc - */ protected function getCharCount():int{ return mb_strlen($this->data, self::ENCODING); } - /** - * @inheritDoc - */ public function getLengthInBits():int{ return ($this->getCharCount() * 13); } - /** - * @inheritDoc - */ public static function convertEncoding(string $string):string{ mb_detect_order([mb_internal_encoding(), 'UTF-8', 'SJIS', 'SJIS-2004']); diff --git a/src/Data/Number.php b/src/Data/Number.php index 83b61574d..4943ce9fb 100644 --- a/src/Data/Number.php +++ b/src/Data/Number.php @@ -35,21 +35,12 @@ final class Number extends QRDataModeAbstract{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ]; - /** - * @inheritDoc - */ public const DATAMODE = Mode::NUMBER; - /** - * @inheritDoc - */ public function getLengthInBits():int{ return (int)ceil($this->getCharCount() * (10 / 3)); } - /** - * @inheritDoc - */ public static function validateString(string $string):bool{ if($string === ''){ @@ -65,9 +56,6 @@ final class Number extends QRDataModeAbstract{ return true; } - /** - * @inheritDoc - */ public function write(BitBuffer $bitBuffer, int $versionNumber):static{ $len = $this->getCharCount(); @@ -102,12 +90,20 @@ final class Number extends QRDataModeAbstract{ /** * get the code for the given numeric string + * + * @throws \chillerlan\QRCode\Data\QRCodeDataException */ private function parseInt(string $string):int{ $num = 0; - foreach(unpack('C*', $string) as $chr){ - $num = ($num * 10 + $chr - 48); + $ords = unpack('C*', $string); + + if($ords === false){ + throw new QRCodeDataException('unpack() error'); + } + + foreach($ords as $ord){ + $num = ($num * 10 + $ord - 48); } return $num; diff --git a/src/Data/QRData.php b/src/Data/QRData.php index e3120b58c..4386ae22a 100644 --- a/src/Data/QRData.php +++ b/src/Data/QRData.php @@ -208,7 +208,7 @@ final class QRData{ /** * creates a BitBuffer and writes the string data to it * - * @throws \chillerlan\QRCode\QRCodeException on data overflow + * @throws \chillerlan\QRCode\Data\QRCodeDataException on data overflow */ private function writeBitBuffer():void{ $MAX_BITS = $this->eccLevel->getMaxBitsForVersion($this->version); @@ -220,7 +220,7 @@ final class QRData{ // overflow, likely caused due to invalid version setting if($this->bitBuffer->getLength() > $MAX_BITS){ throw new QRCodeDataException( - sprintf('code length overflow. (%d > %d bit)', $this->bitBuffer->getLength(), $MAX_BITS) + sprintf('code length overflow. (%d > %d bit)', $this->bitBuffer->getLength(), $MAX_BITS), ); } diff --git a/src/Data/QRDataModeAbstract.php b/src/Data/QRDataModeAbstract.php index 94b93ac0e..2a8b9d00c 100644 --- a/src/Data/QRDataModeAbstract.php +++ b/src/Data/QRDataModeAbstract.php @@ -44,9 +44,6 @@ abstract class QRDataModeAbstract implements QRDataModeInterface{ return strlen($this->data); } - /** - * @inheritDoc - */ public static function convertEncoding(string $string):string{ return $string; } diff --git a/src/Data/QRMatrix.php b/src/Data/QRMatrix.php index 1499e7992..ead50dddf 100755 --- a/src/Data/QRMatrix.php +++ b/src/Data/QRMatrix.php @@ -392,6 +392,7 @@ class QRMatrix{ foreach($pos as $c){ $this + // phpcs:ignore ->setArea( $c[0] , $c[1] , 7, 7, true, $this::M_FINDER) ->setArea(($c[0] + 1), ($c[1] + 1), 5, 5, false, $this::M_FINDER) ->setArea(($c[0] + 2), ($c[1] + 2), 3, 3, true, $this::M_FINDER_DOT) @@ -422,6 +423,7 @@ class QRMatrix{ for($c = 0; $c < 3; $c++){ for($i = 0; $i < 8; $i++){ + // phpcs:ignore $this->set( $h[$c][0] , ($h[$c][1] + $i), false, $this::M_SEPARATOR); $this->set(($v[$c][0] - $i), $v[$c][1] , false, $this::M_SEPARATOR); } diff --git a/src/Decoder/Binarizer.php b/src/Decoder/Binarizer.php index 1e8d5e245..54475734e 100644 --- a/src/Decoder/Binarizer.php +++ b/src/Decoder/Binarizer.php @@ -50,9 +50,6 @@ final class Binarizer{ /** @var int[] */ private array $luminances; - /** - * - */ public function __construct(LuminanceSourceInterface $source){ $this->source = $source; $this->luminances = $this->source->getLuminances(); @@ -162,9 +159,6 @@ final class Binarizer{ return $this->getHistogramBlackMatrix($width, $height); } - /** - * - */ private function getHistogramBlackMatrix(int $width, int $height):BitMatrix{ // Quickly calculates the histogram by sampling four rows from the image. This proved to be diff --git a/src/Decoder/BitMatrix.php b/src/Decoder/BitMatrix.php index 2f1bc6a91..97690e6dc 100644 --- a/src/Decoder/BitMatrix.php +++ b/src/Decoder/BitMatrix.php @@ -221,7 +221,7 @@ final class BitMatrix extends QRMatrix{ // Try again by actually masking the pattern first. $formatInfo = $this->doDecodeFormatInformation( ($formatInfoBits1 ^ $this::FORMAT_INFO_MASK_QR), - ($formatInfoBits2 ^ $this::FORMAT_INFO_MASK_QR) + ($formatInfoBits2 ^ $this::FORMAT_INFO_MASK_QR), ); // still nothing??? @@ -237,9 +237,6 @@ final class BitMatrix extends QRMatrix{ return $this; } - /** - * - */ private function copyVersionBit(int $i, int $j, int $versionBits):int{ $bit = $this->mirror @@ -380,9 +377,6 @@ final class BitMatrix extends QRMatrix{ return null; } - /** - * - */ private function uRShift(int $a, int $b):int{ if($b === 0){ @@ -392,9 +386,6 @@ final class BitMatrix extends QRMatrix{ return (($a >> $b) & ~((1 << (8 * PHP_INT_SIZE - 1)) >> ($b - 1))); } - /** - * - */ private function numBitsDiffering(int $a, int $b):int{ // a now has a 1 bit exactly where its bit differs with b's $a ^= $b; diff --git a/src/Decoder/Decoder.php b/src/Decoder/Decoder.php index a6d129d4c..a2f8767b3 100644 --- a/src/Decoder/Decoder.php +++ b/src/Decoder/Decoder.php @@ -27,9 +27,6 @@ use function chr, str_replace; */ final class Decoder{ - /** - * @var \chillerlan\QRCode\QROptions|\chillerlan\Settings\SettingsContainerInterface - */ private SettingsContainerInterface|QROptions $options; private Version|null $version = null; private EccLevel|null $eccLevel = null; @@ -164,9 +161,6 @@ final class Decoder{ ]); } - /** - * - */ private function decodeAlphanumSegment(int $versionNumber, bool $fc1InEffect):string{ $str = AlphaNum::decodeSegment($this->bitBuffer, $versionNumber); diff --git a/src/Decoder/DecoderResult.php b/src/Decoder/DecoderResult.php index 4790f42f2..da2ced8a9 100644 --- a/src/Decoder/DecoderResult.php +++ b/src/Decoder/DecoderResult.php @@ -60,10 +60,7 @@ final class DecoderResult{ } - /** - * @return mixed|null - */ - public function __get(string $property){ + public function __get(string $property):mixed{ if(property_exists($this, $property)){ return $this->{$property}; @@ -72,16 +69,10 @@ final class DecoderResult{ return null; } - /** - * - */ public function __toString():string{ return $this->data; } - /** - * - */ public function hasStructuredAppend():bool{ return $this->structuredAppendParity >= 0 && $this->structuredAppendSequence >= 0; } diff --git a/src/Decoder/ReedSolomonDecoder.php b/src/Decoder/ReedSolomonDecoder.php index e3f61e653..0b5eb5860 100644 --- a/src/Decoder/ReedSolomonDecoder.php +++ b/src/Decoder/ReedSolomonDecoder.php @@ -97,7 +97,7 @@ final class ReedSolomonDecoder{ while($longerBlocksStartAt >= 0){ $numCodewords = count($result[$longerBlocksStartAt][1]); - if($numCodewords == $shorterBlocksTotalCodewords){ + if($numCodewords === $shorterBlocksTotalCodewords){ break; } @@ -193,7 +193,7 @@ final class ReedSolomonDecoder{ [$sigma, $omega] = $this->runEuclideanAlgorithm( GF256::buildMonomial($numEccCodewords, 1), new GenericGFPoly(array_reverse($syndromeCoefficients)), - $numEccCodewords + $numEccCodewords, ); $errorLocations = $this->findErrorLocations($sigma); diff --git a/src/Detector/AlignmentPattern.php b/src/Detector/AlignmentPattern.php index b405ec711..d3a1282cf 100644 --- a/src/Detector/AlignmentPattern.php +++ b/src/Detector/AlignmentPattern.php @@ -27,7 +27,7 @@ final class AlignmentPattern extends ResultPoint{ return new self( (($this->x + $j) / 2.0), (($this->y + $i) / 2.0), - (($this->estimatedModuleSize + $newModuleSize) / 2.0) + (($this->estimatedModuleSize + $newModuleSize) / 2.0), ); } diff --git a/src/Detector/AlignmentPatternFinder.php b/src/Detector/AlignmentPatternFinder.php index 812b823b6..917394845 100644 --- a/src/Detector/AlignmentPatternFinder.php +++ b/src/Detector/AlignmentPatternFinder.php @@ -202,9 +202,6 @@ final class AlignmentPatternFinder{ * figures the location of the center of this black/white/black run. * * @param int[] $stateCount - * @param int $end - * - * @return float */ private function centerFromEnd(array $stateCount, int $end):float{ return (float)(($end - $stateCount[2]) - $stateCount[1] / 2); @@ -215,13 +212,12 @@ final class AlignmentPatternFinder{ * "cross-checks" by scanning down vertically through the center of the possible * alignment pattern to see if the same proportion is detected. * - * @param int $startI row where an alignment pattern was detected - * @param int $centerJ center of the section that appears to cross an alignment pattern - * @param int $maxCount maximum reasonable number of modules that should be - * observed in any reading state, based on the results of the horizontal scan - * @param int $originalStateCountTotal + * $startI row where an alignment pattern was detected + * $centerJ center of the section that appears to cross an alignment pattern + * $maxCount maximum reasonable number of modules that should be + * observed in any reading state, based on the results of the horizontal scan * - * @return float|null vertical center of alignment pattern, or null if not found + * returns vertical center of alignment pattern, or null if not found */ private function crossCheckVertical(int $startI, int $centerJ, int $maxCount, int $originalStateCountTotal):float|null{ $maxI = $this->matrix->getSize(); @@ -257,7 +253,7 @@ final class AlignmentPatternFinder{ $i++; } - if($i == $maxI || $stateCount[1] > $maxCount){ + if($i === $maxI || $stateCount[1] > $maxCount){ return null; } @@ -270,6 +266,7 @@ final class AlignmentPatternFinder{ return null; } + // phpcs:ignore if((5 * abs(($stateCount[0] + $stateCount[1] + $stateCount[2]) - $originalStateCountTotal)) >= (2 * $originalStateCountTotal)){ return null; } diff --git a/src/Detector/Detector.php b/src/Detector/Detector.php index a4a6d34c8..e3188d0e4 100644 --- a/src/Detector/Detector.php +++ b/src/Detector/Detector.php @@ -274,7 +274,7 @@ final class Detector{ float $overallEstModuleSize, int $estAlignmentX, int $estAlignmentY, - float $allowanceFactor + float $allowanceFactor, ):AlignmentPattern|null{ // Look for an alignment pattern (3 modules in size) around where it should be $dimension = $this->matrix->getSize(); @@ -301,15 +301,12 @@ final class Detector{ ); } - /** - * - */ private function createTransform( FinderPattern $nw, FinderPattern $ne, FinderPattern $sw, int $size, - AlignmentPattern|null $ap = null + AlignmentPattern|null $ap = null, ):PerspectiveTransform{ $dimMinusThree = ($size - 3.5); @@ -343,7 +340,7 @@ final class Detector{ $bottomRightX, $bottomRightY, $sw->getX(), - $sw->getY() + $sw->getY(), ); } diff --git a/src/Detector/FinderPattern.php b/src/Detector/FinderPattern.php index 2c0ebd439..bc55b999e 100644 --- a/src/Detector/FinderPattern.php +++ b/src/Detector/FinderPattern.php @@ -24,18 +24,12 @@ final class FinderPattern extends ResultPoint{ private int $count; - /** - * - */ public function __construct(float $posX, float $posY, float $estimatedModuleSize, int|null $count = null){ parent::__construct($posX, $posY, $estimatedModuleSize); $this->count = ($count ?? 1); } - /** - * - */ public function getCount():int{ return $this->count; } @@ -46,14 +40,14 @@ final class FinderPattern extends ResultPoint{ * @return float distance between two points */ public function getDistance(FinderPattern $b):float{ - return self::distance($this->x, $this->y, $b->x, $b->y); + return $this->distance($this->x, $this->y, $b->x, $b->y); } /** * Get square of distance between a and b. */ public function getSquaredDistance(FinderPattern $b):float{ - return self::squaredDistance($this->x, $this->y, $b->x, $b->y); + return $this->squaredDistance($this->x, $this->y, $b->x, $b->y); } /** @@ -68,25 +62,19 @@ final class FinderPattern extends ResultPoint{ ($this->count * $this->x + $j) / $combinedCount, ($this->count * $this->y + $i) / $combinedCount, ($this->count * $this->estimatedModuleSize + $newModuleSize) / $combinedCount, - $combinedCount + $combinedCount, ); } - /** - * - */ - private static function squaredDistance(float $aX, float $aY, float $bX, float $bY):float{ + private function squaredDistance(float $aX, float $aY, float $bX, float $bY):float{ $xDiff = ($aX - $bX); $yDiff = ($aY - $bY); return ($xDiff * $xDiff + $yDiff * $yDiff); } - /** - * - */ - public static function distance(float $aX, float $aY, float $bX, float $bY):float{ - return sqrt(self::squaredDistance($aX, $aY, $bX, $bY)); + public function distance(float $aX, float $aY, float $bX, float $bY):float{ + return sqrt($this->squaredDistance($aX, $aY, $bX, $bY)); } } diff --git a/src/Detector/FinderPatternFinder.php b/src/Detector/FinderPatternFinder.php index 45bbe5407..baed34ada 100644 --- a/src/Detector/FinderPatternFinder.php +++ b/src/Detector/FinderPatternFinder.php @@ -288,11 +288,13 @@ final class FinderPatternFinder{ // Now also count down, right from center $i = 1; + // phpcs:ignore while(($centerI + $i) < $dimension && ($centerJ + $i) < $dimension && $this->matrix->check(($centerJ + $i), ($centerI + $i))){ $stateCount[2]++; $i++; } + // phpcs:ignore while(($centerI + $i) < $dimension && ($centerJ + $i) < $dimension && !$this->matrix->check(($centerJ + $i), ($centerI + $i))){ $stateCount[3]++; $i++; @@ -302,6 +304,7 @@ final class FinderPatternFinder{ return false; } + // phpcs:ignore while(($centerI + $i) < $dimension && ($centerJ + $i) < $dimension && $this->matrix->check(($centerJ + $i), ($centerI + $i))){ $stateCount[4]++; $i++; @@ -319,13 +322,14 @@ final class FinderPatternFinder{ * "cross-checks" by scanning down vertically through the center of the possible * finder pattern to see if the same proportion is detected. * - * @param int $startI row where a finder pattern was detected - * @param int $centerJ center of the section that appears to cross a finder pattern - * @param int $maxCount maximum reasonable number of modules that should be - * observed in any reading state, based on the results of the horizontal scan - * @param int $originalStateCountTotal + * $startI row where a finder pattern was detected + * $centerJ center of the section that appears to cross a finder pattern + * $maxCount maximum reasonable number of modules that should be + * observed in any reading state, based on the results of the horizontal scan + * $originalStateCountTotal + * + * returns vertical center of finder pattern, or null if not found * - * @return float|null vertical center of finder pattern, or null if not found * @noinspection DuplicatedCode */ private function crossCheckVertical(int $startI, int $centerJ, int $maxCount, int $originalStateCountTotal):float|null{ @@ -630,7 +634,7 @@ final class FinderPatternFinder{ usort( $this->possibleCenters, - fn(FinderPattern $a, FinderPattern $b) => ($a->getEstimatedModuleSize() <=> $b->getEstimatedModuleSize()) + fn(FinderPattern $a, FinderPattern $b) => ($a->getEstimatedModuleSize() <=> $b->getEstimatedModuleSize()), ); $distortion = PHP_FLOAT_MAX; diff --git a/src/Detector/GridSampler.php b/src/Detector/GridSampler.php index 8c410ecef..093a112ac 100644 --- a/src/Detector/GridSampler.php +++ b/src/Detector/GridSampler.php @@ -153,15 +153,15 @@ final class GridSampler{ // no need to try/catch as QRMatrix::set() will silently discard out of bounds values # try{ - for($x = 0; $x < $max; $x += 2){ - // Black(-ish) pixel - $bits->set( - intdiv($x, 2), - $y, - $matrix->check((int)$this->points[$x], (int)$this->points[($x + 1)]), - QRMatrix::M_DATA - ); - } + for($x = 0; $x < $max; $x += 2){ + // Black(-ish) pixel + $bits->set( + intdiv($x, 2), + $y, + $matrix->check((int)$this->points[$x], (int)$this->points[($x + 1)]), + QRMatrix::M_DATA, + ); + } # } # catch(\Throwable $aioobe){//ArrayIndexOutOfBoundsException // This feels wrong, but, sometimes if the finder patterns are misidentified, the resulting diff --git a/src/Detector/PerspectiveTransform.php b/src/Detector/PerspectiveTransform.php index ba45e257a..31a83272d 100644 --- a/src/Detector/PerspectiveTransform.php +++ b/src/Detector/PerspectiveTransform.php @@ -32,13 +32,10 @@ final class PerspectiveTransform{ private float $a32; private float $a33; - /** - * - */ private function set( float $a11, float $a21, float $a31, float $a12, float $a22, float $a32, - float $a13, float $a23, float $a33 + float $a13, float $a23, float $a33, ):self{ $this->a11 = $a11; $this->a12 = $a12; @@ -58,19 +55,16 @@ final class PerspectiveTransform{ */ public function quadrilateralToQuadrilateral( float $x0, float $y0, float $x1, float $y1, float $x2, float $y2, float $x3, float $y3, - float $x0p, float $y0p, float $x1p, float $y1p, float $x2p, float $y2p, float $x3p, float $y3p + float $x0p, float $y0p, float $x1p, float $y1p, float $x2p, float $y2p, float $x3p, float $y3p, ):self{ return (new self) ->squareToQuadrilateral($x0p, $y0p, $x1p, $y1p, $x2p, $y2p, $x3p, $y3p) ->times($this->quadrilateralToSquare($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3)); } - /** - * - */ private function quadrilateralToSquare( float $x0, float $y0, float $x1, float $y1, - float $x2, float $y2, float $x3, float $y3 + float $x2, float $y2, float $x3, float $y3, ):self{ // Here, the adjoint serves as the inverse: return $this @@ -78,9 +72,6 @@ final class PerspectiveTransform{ ->buildAdjoint(); } - /** - * - */ private function buildAdjoint():self{ // Adjoint is the transpose of the cofactor matrix: return $this->set( @@ -92,16 +83,13 @@ final class PerspectiveTransform{ ($this->a12 * $this->a31 - $this->a11 * $this->a32), ($this->a12 * $this->a23 - $this->a13 * $this->a22), ($this->a13 * $this->a21 - $this->a11 * $this->a23), - ($this->a11 * $this->a22 - $this->a12 * $this->a21) + ($this->a11 * $this->a22 - $this->a12 * $this->a21), ); } - /** - * - */ private function squareToQuadrilateral( float $x0, float $y0, float $x1, float $y1, - float $x2, float $y2, float $x3, float $y3 + float $x2, float $y2, float $x3, float $y3, ):self{ $dx3 = ($x0 - $x1 + $x2 - $x3); $dy3 = ($y0 - $y1 + $y2 - $y3); @@ -128,13 +116,10 @@ final class PerspectiveTransform{ $y0, $a13, $a23, - 1.0 + 1.0, ); } - /** - * - */ private function times(PerspectiveTransform $other):self{ return $this->set( ($this->a11 * $other->a11 + $this->a21 * $other->a12 + $this->a31 * $other->a13), @@ -145,7 +130,7 @@ final class PerspectiveTransform{ ($this->a12 * $other->a31 + $this->a22 * $other->a32 + $this->a32 * $other->a33), ($this->a13 * $other->a11 + $this->a23 * $other->a12 + $this->a33 * $other->a13), ($this->a13 * $other->a21 + $this->a23 * $other->a22 + $this->a33 * $other->a23), - ($this->a13 * $other->a31 + $this->a23 * $other->a32 + $this->a33 * $other->a33) + ($this->a13 * $other->a31 + $this->a23 * $other->a32 + $this->a33 * $other->a33), ); } diff --git a/src/Detector/ResultPoint.php b/src/Detector/ResultPoint.php index 92997a746..34b64812e 100644 --- a/src/Detector/ResultPoint.php +++ b/src/Detector/ResultPoint.php @@ -25,32 +25,20 @@ abstract class ResultPoint{ protected float $y; protected float $estimatedModuleSize; - /** - * - */ public function __construct(float $x, float $y, float $estimatedModuleSize){ $this->x = $x; $this->y = $y; $this->estimatedModuleSize = $estimatedModuleSize; } - /** - * - */ public function getX():float{ return $this->x; } - /** - * - */ public function getY():float{ return $this->y; } - /** - * - */ public function getEstimatedModuleSize():float{ return $this->estimatedModuleSize; } diff --git a/src/Output/QREps.php b/src/Output/QREps.php index 35a8c62f9..457c0d468 100644 --- a/src/Output/QREps.php +++ b/src/Output/QREps.php @@ -24,9 +24,6 @@ class QREps extends QROutputAbstract{ final public const MIME_TYPE = 'application/postscript'; - /** - * @inheritDoc - */ public static function moduleValueIsValid(mixed $value):bool{ if(!is_array($value) || count($value) < 3){ @@ -49,9 +46,6 @@ class QREps extends QROutputAbstract{ return true; } - /** - * @inheritDoc - */ protected function prepareModuleValue(mixed $value):string{ $values = []; @@ -68,9 +62,6 @@ class QREps extends QROutputAbstract{ return $this->formatColor($values); } - /** - * @inheritDoc - */ protected function getDefaultModuleValue(bool $isDark):string{ return $this->formatColor(($isDark) ? [0.0, 0.0, 0.0] : [1.0, 1.0, 1.0]); } @@ -95,14 +86,11 @@ class QREps extends QROutputAbstract{ // CMYK ? '%f %f %f %f C' // RGB - :'%f %f %f R'; + : '%f %f %f R'; return sprintf($format, ...$values); } - /** - * @inheritDoc - */ public function dump(string|null $file = null):string{ [$width, $height] = $this->getOutputDimensions(); diff --git a/src/Output/QRFpdf.php b/src/Output/QRFpdf.php index 03d9bc1cb..7ccc94fa7 100644 --- a/src/Output/QRFpdf.php +++ b/src/Output/QRFpdf.php @@ -29,10 +29,9 @@ class QRFpdf extends QROutputAbstract{ final public const MIME_TYPE = 'application/pdf'; - protected FPDF $fpdf; - /** @var int[] */ protected array|null $prevColor = null; + protected FPDF $fpdf; /** * QRFpdf constructor. @@ -45,6 +44,7 @@ class QRFpdf extends QROutputAbstract{ // @codeCoverageIgnoreStart throw new QRCodeOutputException( 'The QRFpdf output requires FPDF (https://github.com/Setasign/FPDF)'. + // phpcs:ignore ' as dependency but the class "\\FPDF" could not be found.' ); // @codeCoverageIgnoreEnd @@ -57,15 +57,12 @@ class QRFpdf extends QROutputAbstract{ * Initializes an FPDF instance */ protected function initFPDF():FPDF{ - $fpdf = new FPDF('P', $this->options->fpdfMeasureUnit, $this->getOutputDimensions()); + $fpdf = new FPDF('P', $this->options->fpdfMeasureUnit, $this->getOutputDimensions()); $fpdf->AddPage(); return $fpdf; } - /** - * @inheritDoc - */ public function dump(string|null $file = null, FPDF|null $fpdf = null):string|FPDF{ $this->fpdf = ($fpdf ?? $this->initFPDF()); diff --git a/src/Output/QRGdImage.php b/src/Output/QRGdImage.php index ccd10c78e..d7666e5eb 100644 --- a/src/Output/QRGdImage.php +++ b/src/Output/QRGdImage.php @@ -53,8 +53,6 @@ abstract class QRGdImage extends QROutputAbstract{ protected bool $upscaled = false; /** - * @inheritDoc - * * @throws \chillerlan\QRCode\Output\QRCodeOutputException * @noinspection PhpMissingParentConstructorInspection */ @@ -131,9 +129,6 @@ abstract class QRGdImage extends QROutputAbstract{ return $color; } - /** - * @inheritDoc - */ protected function getDefaultModuleValue(bool $isDark):int{ return $this->prepareModuleValue(($isDark) ? [0, 0, 0] : [255, 255, 255]); } @@ -141,7 +136,7 @@ abstract class QRGdImage extends QROutputAbstract{ /** * @inheritDoc * - * @throws \ErrorException + * @throws \ErrorException|\chillerlan\QRCode\Output\QRCodeOutputException */ public function dump(string|null $file = null):string|GdImage{ @@ -160,7 +155,13 @@ abstract class QRGdImage extends QROutputAbstract{ if($this->upscaled){ // scale down to the expected size - $this->image = imagescale($this->image, ($this->length / 10), ($this->length / 10)); + $scaled = imagescale($this->image, ($this->length / 10), ($this->length / 10)); + + if($scaled === false){ + throw new QRCodeOutputException('imagescale() error'); + } + + $this->image = $scaled; $this->upscaled = false; // Reset scaled and length values after rescaling image to prevent issues with subclasses that use the output from dump() $this->setMatrixDimensions(); @@ -273,7 +274,7 @@ abstract class QRGdImage extends QROutputAbstract{ (($y * $this->scale) + intdiv($this->scale, 2)), (int)($this->circleDiameter * $this->scale), (int)($this->circleDiameter * $this->scale), - $color + $color, ); return; @@ -285,7 +286,7 @@ abstract class QRGdImage extends QROutputAbstract{ ($y * $this->scale), (($x + 1) * $this->scale), (($y + 1) * $this->scale), - $color + $color, ); } @@ -311,6 +312,11 @@ abstract class QRGdImage extends QROutputAbstract{ $this->renderImage(); $imageData = ob_get_contents(); + + if($imageData === false){ + throw new QRCodeOutputException('ob_get_contents() error'); + } + imagedestroy($this->image); } // not going to cover edge cases diff --git a/src/Output/QRGdImageAVIF.php b/src/Output/QRGdImageAVIF.php index 1efa6f1c3..f9e256e97 100644 --- a/src/Output/QRGdImageAVIF.php +++ b/src/Output/QRGdImageAVIF.php @@ -23,9 +23,6 @@ class QRGdImageAVIF extends QRGdImage{ final public const MIME_TYPE = 'image/avif'; - /** - * @inheritDoc - */ protected function renderImage():void{ imageavif($this->image, null, max(-1, min(100, $this->options->quality))); } diff --git a/src/Output/QRGdImageBMP.php b/src/Output/QRGdImageBMP.php index 3a4568b12..0754c7b59 100644 --- a/src/Output/QRGdImageBMP.php +++ b/src/Output/QRGdImageBMP.php @@ -23,9 +23,6 @@ class QRGdImageBMP extends QRGdImage{ final public const MIME_TYPE = 'image/bmp'; - /** - * @inheritDoc - */ protected function renderImage():void{ imagebmp($this->image, null, ($this->options->quality > 0)); } diff --git a/src/Output/QRGdImageGIF.php b/src/Output/QRGdImageGIF.php index 751b381a6..5c9202665 100644 --- a/src/Output/QRGdImageGIF.php +++ b/src/Output/QRGdImageGIF.php @@ -23,9 +23,6 @@ class QRGdImageGIF extends QRGdImage{ final public const MIME_TYPE = 'image/gif'; - /** - * @inheritDoc - */ protected function renderImage():void{ imagegif($this->image); } diff --git a/src/Output/QRGdImageJPEG.php b/src/Output/QRGdImageJPEG.php index 3fb95cc91..cbe40f09e 100644 --- a/src/Output/QRGdImageJPEG.php +++ b/src/Output/QRGdImageJPEG.php @@ -23,16 +23,10 @@ class QRGdImageJPEG extends QRGdImage{ final public const MIME_TYPE = 'image/jpg'; - /** - * @inheritDoc - */ protected function setTransparencyColor():void{ // noop - transparency is not supported } - /** - * @inheritDoc - */ protected function renderImage():void{ imagejpeg($this->image, null, max(-1, min(100, $this->options->quality))); } diff --git a/src/Output/QRGdImagePNG.php b/src/Output/QRGdImagePNG.php index 17b249182..09de6ccbd 100644 --- a/src/Output/QRGdImagePNG.php +++ b/src/Output/QRGdImagePNG.php @@ -23,9 +23,6 @@ class QRGdImagePNG extends QRGdImage{ final public const MIME_TYPE = 'image/png'; - /** - * @inheritDoc - */ protected function renderImage():void{ imagepng($this->image, null, max(-1, min(9, $this->options->quality))); } diff --git a/src/Output/QRGdImageWEBP.php b/src/Output/QRGdImageWEBP.php index 0f2d32dc9..9f63a4f2b 100644 --- a/src/Output/QRGdImageWEBP.php +++ b/src/Output/QRGdImageWEBP.php @@ -23,9 +23,6 @@ class QRGdImageWEBP extends QRGdImage{ final public const MIME_TYPE = 'image/webp'; - /** - * @inheritDoc - */ protected function renderImage():void{ imagewebp($this->image, null, max(-1, min(100, $this->options->quality))); } diff --git a/src/Output/QRImagick.php b/src/Output/QRImagick.php index 387fcdbad..73164cb1d 100644 --- a/src/Output/QRImagick.php +++ b/src/Output/QRImagick.php @@ -94,23 +94,14 @@ class QRImagick extends QROutputAbstract{ return false; } - /** - * @inheritDoc - */ protected function prepareModuleValue(mixed $value):ImagickPixel{ return new ImagickPixel($value); } - /** - * @inheritDoc - */ protected function getDefaultModuleValue(bool $isDark):ImagickPixel{ return $this->prepareModuleValue(($isDark) ? '#000' : '#fff'); } - /** - * @inheritDoc - */ public function dump(string|null $file = null):string|Imagick{ $this->setBgColor(); @@ -131,12 +122,28 @@ class QRImagick extends QROutputAbstract{ $this->saveToFile($imageData, $file); if($this->options->outputBase64){ - $imageData = $this->toBase64DataURI($imageData, (new finfo(FILEINFO_MIME_TYPE))->buffer($imageData)); + + $imageData = $this->toBase64DataURI($imageData, $this->guessMimeType($imageData)); } return $imageData; } + /** + * @todo: move to QROutputAbstract + * + * @throws \chillerlan\QRCode\Output\QRCodeOutputException + */ + protected function guessMimeType(string $imageData):string{ + $mime = (new finfo(FILEINFO_MIME_TYPE))->buffer($imageData); + + if($mime === false){ + throw new QRCodeOutputException('unable to detect mime type'); + } + + return $mime; + } + /** * Sets the background color */ @@ -217,7 +224,7 @@ class QRImagick extends QROutputAbstract{ (($x + 0.5) * $this->scale), (($y + 0.5) * $this->scale), (($x + 0.5 + $this->circleRadius) * $this->scale), - (($y + 0.5) * $this->scale) + (($y + 0.5) * $this->scale), ); return; @@ -227,7 +234,7 @@ class QRImagick extends QROutputAbstract{ ($x * $this->scale), ($y * $this->scale), ((($x + 1) * $this->scale) - 1), - ((($y + 1) * $this->scale) - 1) + ((($y + 1) * $this->scale) - 1), ); } diff --git a/src/Output/QRInterventionImage.php b/src/Output/QRInterventionImage.php index c2b7a31c3..806d270e4 100644 --- a/src/Output/QRInterventionImage.php +++ b/src/Output/QRInterventionImage.php @@ -82,9 +82,6 @@ class QRInterventionImage extends QROutputAbstract{ return $this; } - /** - * @inheritDoc - */ public function dump(string|null $file = null):string|ImageInterface{ [$width, $height] = $this->getOutputDimensions(); @@ -126,7 +123,6 @@ class QRInterventionImage extends QROutputAbstract{ return $imageData; } - /** * draws a single pixel at the given position */ @@ -146,7 +142,7 @@ class QRInterventionImage extends QROutputAbstract{ function(CircleFactory $circle) use ($color):void{ $circle->radius((int)($this->circleRadius * $this->scale)); $circle->background($color); - } + }, ); return; @@ -158,7 +154,7 @@ class QRInterventionImage extends QROutputAbstract{ function(RectangleFactory $rectangle) use ($color):void{ $rectangle->size($this->scale, $this->scale); $rectangle->background($color); - } + }, ); } diff --git a/src/Output/QRMarkup.php b/src/Output/QRMarkup.php index 983f22b09..d793aada3 100644 --- a/src/Output/QRMarkup.php +++ b/src/Output/QRMarkup.php @@ -16,9 +16,6 @@ namespace chillerlan\QRCode\Output; abstract class QRMarkup extends QROutputAbstract{ use CssColorModuleValueTrait; - /** - * @inheritDoc - */ public function dump(string|null $file = null):string{ $saveToFile = $file !== null; $data = $this->createMarkup($saveToFile); diff --git a/src/Output/QRMarkupHTML.php b/src/Output/QRMarkupHTML.php index 8a37d5511..d2416b896 100644 --- a/src/Output/QRMarkupHTML.php +++ b/src/Output/QRMarkupHTML.php @@ -19,9 +19,6 @@ class QRMarkupHTML extends QRMarkup{ final public const MIME_TYPE = 'text/html'; - /** - * @inheritDoc - */ protected function createMarkup(bool $saveToFile):string{ $rows = []; $cssClass = $this->getCssClass(); @@ -41,7 +38,7 @@ class QRMarkupHTML extends QRMarkup{ '%2$s%2$s%2$s'. 'QR Code%2$s%1$s%2$s', $html, - $this->eol + $this->eol, ); } diff --git a/src/Output/QRMarkupSVG.php b/src/Output/QRMarkupSVG.php index 9aa6961cf..bbf9bb575 100644 --- a/src/Output/QRMarkupSVG.php +++ b/src/Output/QRMarkupSVG.php @@ -50,16 +50,10 @@ class QRMarkupSVG extends QRMarkup{ return parent::moduleValueIsValid($value); } - /** - * @inheritDoc - */ protected function getOutputDimensions():array{ return [$this->moduleCount, $this->moduleCount]; } - /** - * @inheritDoc - */ protected function getCssClass(int $M_TYPE = 0):string{ return implode(' ', [ 'qr-'.($this::LAYERNAMES[$M_TYPE] ?? $M_TYPE), @@ -68,9 +62,6 @@ class QRMarkupSVG extends QRMarkup{ ]); } - /** - * @inheritDoc - */ protected function createMarkup(bool $saveToFile):string{ $svg = $this->header(); @@ -110,7 +101,7 @@ class QRMarkupSVG extends QRMarkup{ $this->options->cssClass, $this->getViewBox(), $this->options->svgPreserveAspectRatio, - $this->eol + $this->eol, ); if($this->options->svgAddXmlHeader){ @@ -161,7 +152,7 @@ class QRMarkupSVG extends QRMarkup{ '', $this->getCssClass($M_TYPE), $this->getModuleValue($M_TYPE), - $path + $path, ); } diff --git a/src/Output/QRMarkupXML.php b/src/Output/QRMarkupXML.php index 7fc7922cb..b6fa4d89c 100644 --- a/src/Output/QRMarkupXML.php +++ b/src/Output/QRMarkupXML.php @@ -28,7 +28,6 @@ class QRMarkupXML extends QRMarkup{ /** * @inheritDoc - * * @return int[] */ protected function getOutputDimensions():array{ @@ -37,6 +36,7 @@ class QRMarkupXML extends QRMarkup{ /** * @inheritDoc + * @throws \chillerlan\QRCode\Output\QRCodeOutputException */ protected function createMarkup(bool $saveToFile):string{ /** @noinspection PhpComposerExtensionStubsInspection */ @@ -62,6 +62,10 @@ class QRMarkupXML extends QRMarkup{ $xml = $this->dom->saveXML(); + if($xml === false){ + throw new QRCodeOutputException('XML error'); + } + return $xml; } @@ -129,9 +133,8 @@ class QRMarkupXML extends QRMarkup{ $module = $this->dom->createElement('module'); - $module->setAttribute('x', $x); - $module->setAttribute('dark', ($isDark ? 'true' : 'false')); $module->setAttribute('x', (string)$x); + $module->setAttribute('dark', (($isDark) ? 'true' : 'false')); $module->setAttribute('layer', ($this::LAYERNAMES[$M_TYPE] ?? '')); $module->setAttribute('value', (string)$this->getModuleValue($M_TYPE)); diff --git a/src/Output/QRStringJSON.php b/src/Output/QRStringJSON.php index 2e32aa9c9..2531d8fad 100644 --- a/src/Output/QRStringJSON.php +++ b/src/Output/QRStringJSON.php @@ -12,9 +12,12 @@ namespace chillerlan\QRCode\Output; +use JsonException; use function json_encode; /** + * JSON Output + * * @method string getModuleValue(int $M_TYPE) * * @phpstan-type Module array{x: int, dark: bool, layer: string, value: string} @@ -40,12 +43,12 @@ class QRStringJSON extends QROutputAbstract{ */ public function dump(string|null $file = null):string{ [$width, $height] = $this->getOutputDimensions(); - $version = $this->matrix->getVersion(); - $dimension = $version->getDimension(); + $version = $this->matrix->getVersion(); + $dimension = $version->getDimension(); $json = [ '$schema' => $this::SCHEMA, - 'qrcode' => [ + 'qrcode' => [ 'version' => $version->getVersionNumber(), 'eccLevel' => (string)$this->matrix->getEccLevel(), 'matrix' => [ @@ -67,7 +70,11 @@ class QRStringJSON extends QROutputAbstract{ } } - $data = json_encode($json, $this->options->jsonFlags);; + $data = json_encode($json, $this->options->jsonFlags); + + if($data === false){ + throw new JsonException('error while encoding JSON'); + } $this->saveToFile($data, $file); diff --git a/src/Output/QRStringText.php b/src/Output/QRStringText.php index 01df6423a..1a7f15645 100644 --- a/src/Output/QRStringText.php +++ b/src/Output/QRStringText.php @@ -13,7 +13,7 @@ namespace chillerlan\QRCode\Output; use function array_map, implode, is_string, max, min, sprintf; /** - * + * String/plaintext output (for CLI etc.) */ class QRStringText extends QROutputAbstract{ @@ -37,16 +37,10 @@ class QRStringText extends QROutputAbstract{ return $value; } - /** - * @inheritDoc - */ protected function getDefaultModuleValue(bool $isDark):string{ return ($isDark) ? '██' : '░░'; } - /** - * @inheritDoc - */ public function dump(string|null $file = null):string{ $lines = []; $linestart = $this->options->textLineStart; diff --git a/src/QRCode.php b/src/QRCode.php index da4ea14ba..777dbf052 100755 --- a/src/QRCode.php +++ b/src/QRCode.php @@ -133,7 +133,7 @@ class QRCode{ $logoSpaceWidth, $logoSpaceHeight, $this->options->logoSpaceStartX, - $this->options->logoSpaceStartY + $this->options->logoSpaceStartY, ); } @@ -156,7 +156,7 @@ class QRCode{ throw new QRCodeOutputException('invalid output class'); } - if(!in_array(QROutputInterface::class, class_implements($outputInterface))){ + if(!in_array(QROutputInterface::class, class_implements($outputInterface), true)){ throw new QRCodeOutputException('output class does not implement QROutputInterface'); } diff --git a/src/QROptionsTrait.php b/src/QROptionsTrait.php index aa5128cb6..4695ef286 100644 --- a/src/QROptionsTrait.php +++ b/src/QROptionsTrait.php @@ -19,7 +19,6 @@ use chillerlan\QRCode\Output\QRMarkupSVG; use function constant, in_array, is_string, max, min, sprintf, strtolower, strtoupper, trim; use const JSON_THROW_ON_ERROR, JSON_UNESCAPED_SLASHES, PHP_EOL; - /** * The QRCode plug-in settings & setter functionality * @@ -346,8 +345,6 @@ trait QROptionsTrait{ * * @see \imagecolortransparent() * @see \Imagick::transparentPaintImage() - * - * @var mixed|null */ protected mixed $transparencyColor = null; @@ -463,7 +460,7 @@ trait QROptionsTrait{ * * @see https://www.php.net/manual/json.constants.php */ - protected int $jsonFlags = JSON_THROW_ON_ERROR|JSON_UNESCAPED_SLASHES; + protected int $jsonFlags = (JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES); /* @@ -532,7 +529,7 @@ trait QROptionsTrait{ if(is_string($eccLevel)){ $ecc = strtoupper(trim($eccLevel)); - if(!in_array($ecc, ['L', 'M', 'Q', 'H'])){ + if(!in_array($ecc, ['L', 'M', 'Q', 'H'], true)){ throw new QRCodeException(sprintf('Invalid ECC level: "%s"', $ecc)); } diff --git a/tests/BuildDirTrait.php b/tests/BuildDirTrait.php index 77e30e560..ca91be930 100644 --- a/tests/BuildDirTrait.php +++ b/tests/BuildDirTrait.php @@ -81,9 +81,17 @@ trait BuildDirTrait{ /** * returns the contents of the given build file + * + * @throws \RuntimeException */ protected function getBuildFileContent(string $fileSubPath):string{ - return file_get_contents($this->getBuildFilePath($fileSubPath)); + $content = file_get_contents($this->getBuildFilePath($fileSubPath)); + + if($content === false){ + throw new RuntimeException('file_get_contents() error while reading build file'); + } + + return $content; } } diff --git a/tests/Data/ByteTest.php b/tests/Data/ByteTest.php index 0ec9708d0..0a73b5e38 100644 --- a/tests/Data/ByteTest.php +++ b/tests/Data/ByteTest.php @@ -38,16 +38,10 @@ final class ByteTest extends DataInterfaceTestAbstract{ ]; } - /** - * @inheritDoc - */ public function testInvalidDataException():void{ $this::markTestSkipped('N/A (binary mode)'); } - /** - * @inheritDoc - */ public function testBinaryStringInvalid():void{ $this::markTestSkipped('N/A (binary mode)'); } diff --git a/tests/Data/DataInterfaceTestAbstract.php b/tests/Data/DataInterfaceTestAbstract.php index 4ff7d5867..3b2b82357 100644 --- a/tests/Data/DataInterfaceTestAbstract.php +++ b/tests/Data/DataInterfaceTestAbstract.php @@ -187,7 +187,7 @@ abstract class DataInterfaceTestAbstract extends TestCase{ try{ $this::assertSame($version->getVersionNumber(), $minimumVersionNumber); } - catch(ExpectationFailedException $e){ + catch(ExpectationFailedException){ $this::assertSame(($version->getVersionNumber() + 1), $minimumVersionNumber, 'safety margin'); } diff --git a/tests/Data/HanziTest.php b/tests/Data/HanziTest.php index 9fc77ebc7..267f06388 100644 --- a/tests/Data/HanziTest.php +++ b/tests/Data/HanziTest.php @@ -76,7 +76,7 @@ final class HanziTest extends DataInterfaceTestAbstract{ try{ $this::assertTrue(Hanzi::validateString($chr)); } - catch(Throwable $e){ + catch(Throwable){ /** @noinspection PhpUndefinedConstantInspection - see phpunit.xml.dist */ if(defined('TEST_IS_CI') && TEST_IS_CI === true){ $this::markTestSkipped(); @@ -85,7 +85,7 @@ final class HanziTest extends DataInterfaceTestAbstract{ $this::markTestSkipped(sprintf( 'invalid glyph: %s => %s', bin2hex(mb_convert_encoding($chr, Hanzi::ENCODING, 'UTF-8')), - $chr + $chr, )); } } diff --git a/tests/Data/KanjiTest.php b/tests/Data/KanjiTest.php index 09942df17..886d2a622 100644 --- a/tests/Data/KanjiTest.php +++ b/tests/Data/KanjiTest.php @@ -103,7 +103,7 @@ final class KanjiTest extends DataInterfaceTestAbstract{ try{ $this::assertTrue(Kanji::validateString($chr)); } - catch(Throwable $e){ + catch(Throwable){ /** @noinspection PhpUndefinedConstantInspection - see phpunit.xml.dist */ if(defined('TEST_IS_CI') && TEST_IS_CI === true){ $this::markTestSkipped(); @@ -112,7 +112,7 @@ final class KanjiTest extends DataInterfaceTestAbstract{ $this::markTestSkipped(sprintf( 'invalid glyph: %s => %s', bin2hex(mb_convert_encoding($chr, Kanji::ENCODING, 'UTF-8')), - $chr + $chr, )); } } diff --git a/tests/Data/QRDataTest.php b/tests/Data/QRDataTest.php index b47bc0f3d..8594b3886 100644 --- a/tests/Data/QRDataTest.php +++ b/tests/Data/QRDataTest.php @@ -21,9 +21,6 @@ use chillerlan\QRCode\QROptions; use chillerlan\QRCodeTest\QRMatrixDebugTrait; use PHPUnit\Framework\TestCase; -/** - * - */ final class QRDataTest extends TestCase{ use QRMatrixDebugTrait; diff --git a/tests/Data/QRMatrixTest.php b/tests/Data/QRMatrixTest.php index 53d8f3e22..ff42b0611 100755 --- a/tests/Data/QRMatrixTest.php +++ b/tests/Data/QRMatrixTest.php @@ -33,7 +33,7 @@ final class QRMatrixTest extends TestCase{ protected function setUp():void{ $this->matrix = new QRMatrix( new Version($this::version), - new EccLevel(EccLevel::L) + new EccLevel(EccLevel::L), ); } diff --git a/tests/Output/QREpsTest.php b/tests/Output/QREpsTest.php index 5b546bd4b..56b6dca63 100644 --- a/tests/Output/QREpsTest.php +++ b/tests/Output/QREpsTest.php @@ -31,14 +31,11 @@ class QREpsTest extends QROutputTestAbstract{ protected function getOutputInterface( SettingsContainerInterface|QROptions $options, - QRMatrix $matrix + QRMatrix $matrix, ):QROutputInterface{ return new QREps($options, $matrix); } - /** - * @inheritDoc - */ public function testSetModuleValues():void{ $this->options->moduleValues = [ diff --git a/tests/Output/QRFpdfTest.php b/tests/Output/QRFpdfTest.php index e01fcff8d..0e34cb505 100644 --- a/tests/Output/QRFpdfTest.php +++ b/tests/Output/QRFpdfTest.php @@ -23,9 +23,6 @@ use function class_exists; final class QRFpdfTest extends QROutputTestAbstract{ use RGBArrayModuleValueProviderTrait; - /** - * @inheritDoc - */ protected function setUp():void{ if(!class_exists(FPDF::class)){ @@ -37,14 +34,11 @@ final class QRFpdfTest extends QROutputTestAbstract{ protected function getOutputInterface( SettingsContainerInterface|QROptions $options, - QRMatrix $matrix + QRMatrix $matrix, ):QROutputInterface{ return new QRFpdf($options, $matrix); } - /** - * @inheritDoc - */ public function testSetModuleValues():void{ $this->options->moduleValues = [ diff --git a/tests/Output/QRGdImageAVIFTest.php b/tests/Output/QRGdImageAVIFTest.php index a4568ab9b..568ee6c0f 100644 --- a/tests/Output/QRGdImageAVIFTest.php +++ b/tests/Output/QRGdImageAVIFTest.php @@ -15,14 +15,11 @@ use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Output\{QRGdImageAVIF, QROutputInterface}; use chillerlan\Settings\SettingsContainerInterface; -/** - * - */ final class QRGdImageAVIFTest extends QRGdImageTestAbstract{ protected function getOutputInterface( SettingsContainerInterface|QROptions $options, - QRMatrix $matrix + QRMatrix $matrix, ):QROutputInterface{ return new QRGdImageAVIF($options, $matrix); } diff --git a/tests/Output/QRGdImageBMPTest.php b/tests/Output/QRGdImageBMPTest.php index 4606c2a5a..5e7044578 100644 --- a/tests/Output/QRGdImageBMPTest.php +++ b/tests/Output/QRGdImageBMPTest.php @@ -15,14 +15,11 @@ use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Output\{QRGdImageBMP, QROutputInterface}; use chillerlan\Settings\SettingsContainerInterface; -/** - * - */ final class QRGdImageBMPTest extends QRGdImageTestAbstract{ protected function getOutputInterface( SettingsContainerInterface|QROptions $options, - QRMatrix $matrix + QRMatrix $matrix, ):QROutputInterface{ return new QRGdImageBMP($options, $matrix); } diff --git a/tests/Output/QRGdImageGIFTest.php b/tests/Output/QRGdImageGIFTest.php index 763f2fea2..2dcf96f11 100644 --- a/tests/Output/QRGdImageGIFTest.php +++ b/tests/Output/QRGdImageGIFTest.php @@ -15,14 +15,11 @@ use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Output\{QRGdImageGIF, QROutputInterface}; use chillerlan\Settings\SettingsContainerInterface; -/** - * - */ final class QRGdImageGIFTest extends QRGdImageTestAbstract{ protected function getOutputInterface( SettingsContainerInterface|QROptions $options, - QRMatrix $matrix + QRMatrix $matrix, ):QROutputInterface{ return new QRGdImageGIF($options, $matrix); } diff --git a/tests/Output/QRGdImageJPGTest.php b/tests/Output/QRGdImageJPGTest.php index ff832e877..216a67f02 100644 --- a/tests/Output/QRGdImageJPGTest.php +++ b/tests/Output/QRGdImageJPGTest.php @@ -15,14 +15,11 @@ use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Output\{QRGdImageJPEG, QROutputInterface}; use chillerlan\Settings\SettingsContainerInterface; -/** - * - */ final class QRGdImageJPGTest extends QRGdImageTestAbstract{ protected function getOutputInterface( SettingsContainerInterface|QROptions $options, - QRMatrix $matrix + QRMatrix $matrix, ):QROutputInterface{ return new QRGdImageJPEG($options, $matrix); } diff --git a/tests/Output/QRGdImagePNGTest.php b/tests/Output/QRGdImagePNGTest.php index 2ab0bce2b..6443a5c35 100644 --- a/tests/Output/QRGdImagePNGTest.php +++ b/tests/Output/QRGdImagePNGTest.php @@ -15,14 +15,11 @@ use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Output\{QRGdImagePNG, QROutputInterface}; use chillerlan\Settings\SettingsContainerInterface; -/** - * - */ final class QRGdImagePNGTest extends QRGdImageTestAbstract{ protected function getOutputInterface( SettingsContainerInterface|QROptions $options, - QRMatrix $matrix + QRMatrix $matrix, ):QROutputInterface{ return new QRGdImagePNG($options, $matrix); } diff --git a/tests/Output/QRGdImageTestAbstract.php b/tests/Output/QRGdImageTestAbstract.php index f5fd46ae3..c5a740225 100644 --- a/tests/Output/QRGdImageTestAbstract.php +++ b/tests/Output/QRGdImageTestAbstract.php @@ -22,9 +22,6 @@ use function extension_loaded; abstract class QRGdImageTestAbstract extends QROutputTestAbstract{ use RGBArrayModuleValueProviderTrait; - /** - * @inheritDoc - */ protected function setUp():void{ if(!extension_loaded('gd')){ @@ -34,9 +31,6 @@ abstract class QRGdImageTestAbstract extends QROutputTestAbstract{ parent::setUp(); } - /** - * @inheritDoc - */ public function testSetModuleValues():void{ $this->options->moduleValues = [ diff --git a/tests/Output/QRGdImageWEBPTest.php b/tests/Output/QRGdImageWEBPTest.php index 444046cf7..4d18396fe 100644 --- a/tests/Output/QRGdImageWEBPTest.php +++ b/tests/Output/QRGdImageWEBPTest.php @@ -15,14 +15,11 @@ use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Output\{QRGdImageWEBP, QROutputInterface}; use chillerlan\Settings\SettingsContainerInterface; -/** - * - */ final class QRGdImageWEBPTest extends QRGdImageTestAbstract{ protected function getOutputInterface( SettingsContainerInterface|QROptions $options, - QRMatrix $matrix + QRMatrix $matrix, ):QROutputInterface{ return new QRGdImageWEBP($options, $matrix); } diff --git a/tests/Output/QRImagickTest.php b/tests/Output/QRImagickTest.php index 2d4ca3e44..397cca6cb 100644 --- a/tests/Output/QRImagickTest.php +++ b/tests/Output/QRImagickTest.php @@ -24,9 +24,6 @@ use function extension_loaded; */ final class QRImagickTest extends QROutputTestAbstract{ - /** - * @inheritDoc - */ protected function setUp():void{ if(!extension_loaded('imagick')){ @@ -38,7 +35,7 @@ final class QRImagickTest extends QROutputTestAbstract{ protected function getOutputInterface( SettingsContainerInterface|QROptions $options, - QRMatrix $matrix + QRMatrix $matrix, ):QROutputInterface{ return new QRImagick($options, $matrix); } @@ -69,9 +66,6 @@ final class QRImagickTest extends QROutputTestAbstract{ ]; } - /** - * @inheritDoc - */ public function testSetModuleValues():void{ $this->options->moduleValues = [ diff --git a/tests/Output/QRInterventionImageTest.php b/tests/Output/QRInterventionImageTest.php index 81bd0b018..91e53865f 100644 --- a/tests/Output/QRInterventionImageTest.php +++ b/tests/Output/QRInterventionImageTest.php @@ -24,9 +24,6 @@ use function extension_loaded; class QRInterventionImageTest extends QROutputTestAbstract{ use CssColorModuleValueProviderTrait; - /** - * @inheritDoc - */ protected function setUp():void{ if(!extension_loaded('gd')){ @@ -38,14 +35,11 @@ class QRInterventionImageTest extends QROutputTestAbstract{ protected function getOutputInterface( SettingsContainerInterface|QROptions $options, - QRMatrix $matrix + QRMatrix $matrix, ):QROutputInterface{ return new QRInterventionImage($options, $matrix); } - /** - * @inheritDoc - */ public function testSetModuleValues():void{ $this->options->moduleValues = [ diff --git a/tests/Output/QRMarkupHTMLTest.php b/tests/Output/QRMarkupHTMLTest.php index ca1fe9bcf..da47fa12a 100644 --- a/tests/Output/QRMarkupHTMLTest.php +++ b/tests/Output/QRMarkupHTMLTest.php @@ -15,14 +15,11 @@ use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Output\{QRMarkupHTML, QROutputInterface}; use chillerlan\Settings\SettingsContainerInterface; -/** - * - */ final class QRMarkupHTMLTest extends QRMarkupTestAbstract{ protected function getOutputInterface( SettingsContainerInterface|QROptions $options, - QRMatrix $matrix + QRMatrix $matrix, ):QROutputInterface{ return new QRMarkupHTML($options, $matrix); } diff --git a/tests/Output/QRMarkupSVGTest.php b/tests/Output/QRMarkupSVGTest.php index 7d0b88ad5..74d2d83a8 100644 --- a/tests/Output/QRMarkupSVGTest.php +++ b/tests/Output/QRMarkupSVGTest.php @@ -15,14 +15,11 @@ use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Output\{QRMarkupSVG, QROutputInterface}; use chillerlan\Settings\SettingsContainerInterface; -/** - * - */ final class QRMarkupSVGTest extends QRMarkupTestAbstract{ protected function getOutputInterface( SettingsContainerInterface|QROptions $options, - QRMatrix $matrix + QRMatrix $matrix, ):QROutputInterface{ return new QRMarkupSVG($options, $matrix); } diff --git a/tests/Output/QRMarkupTestAbstract.php b/tests/Output/QRMarkupTestAbstract.php index 1dc23abe2..0d908af99 100644 --- a/tests/Output/QRMarkupTestAbstract.php +++ b/tests/Output/QRMarkupTestAbstract.php @@ -18,9 +18,6 @@ use chillerlan\QRCode\Data\QRMatrix; abstract class QRMarkupTestAbstract extends QROutputTestAbstract{ use CssColorModuleValueProviderTrait; - /** - * @inheritDoc - */ public function testSetModuleValues():void{ $this->options->outputBase64 = false; $this->options->drawLightModules = true; diff --git a/tests/Output/QRMarkupXMLTest.php b/tests/Output/QRMarkupXMLTest.php index 677c0e8af..843fae276 100644 --- a/tests/Output/QRMarkupXMLTest.php +++ b/tests/Output/QRMarkupXMLTest.php @@ -15,9 +15,6 @@ use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Output\{QRMarkupXML, QROutputInterface}; use chillerlan\Settings\SettingsContainerInterface; -/** - * - */ class QRMarkupXMLTest extends QRMarkupTestAbstract{ protected function getOutputInterface( diff --git a/tests/Output/QRStringJSONTest.php b/tests/Output/QRStringJSONTest.php index 36ef4f995..ce28c94f5 100644 --- a/tests/Output/QRStringJSONTest.php +++ b/tests/Output/QRStringJSONTest.php @@ -15,22 +15,16 @@ use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Output\{QROutputInterface, QRStringJSON}; use chillerlan\Settings\SettingsContainerInterface; -/** - * - */ final class QRStringJSONTest extends QROutputTestAbstract{ use CssColorModuleValueProviderTrait; protected function getOutputInterface( SettingsContainerInterface|QROptions $options, - QRMatrix $matrix + QRMatrix $matrix, ):QROutputInterface{ return new QRStringJSON($options, $matrix); } - /** - * @inheritDoc - */ public function testSetModuleValues():void{ $this->options->moduleValues = [ diff --git a/tests/Output/QRStringTextTest.php b/tests/Output/QRStringTextTest.php index ead032c8b..08835ba2c 100644 --- a/tests/Output/QRStringTextTest.php +++ b/tests/Output/QRStringTextTest.php @@ -15,14 +15,11 @@ use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Output\{QROutputInterface, QRStringText}; use chillerlan\Settings\SettingsContainerInterface; -/** - * - */ final class QRStringTextTest extends QROutputTestAbstract{ protected function getOutputInterface( SettingsContainerInterface|QROptions $options, - QRMatrix $matrix + QRMatrix $matrix, ):QROutputInterface{ return new QRStringText($options, $matrix); } @@ -39,9 +36,6 @@ final class QRStringTextTest extends QROutputTestAbstract{ ]; } - /** - * @inheritDoc - */ public function testSetModuleValues():void{ $this->options->moduleValues = [ diff --git a/tests/QRCodeReaderGDTest.php b/tests/QRCodeReaderGDTest.php index fe160d814..3b7039ab1 100644 --- a/tests/QRCodeReaderGDTest.php +++ b/tests/QRCodeReaderGDTest.php @@ -21,7 +21,7 @@ final class QRCodeReaderGDTest extends QRCodeReaderTestAbstract{ protected function getLuminanceSourceFromFile( string $file, - SettingsContainerInterface|QROptions $options + SettingsContainerInterface|QROptions $options, ):LuminanceSourceInterface{ return GDLuminanceSource::fromFile($file, $options); } diff --git a/tests/QRCodeReaderImagickTest.php b/tests/QRCodeReaderImagickTest.php index 5056f3535..ed21cbeea 100644 --- a/tests/QRCodeReaderImagickTest.php +++ b/tests/QRCodeReaderImagickTest.php @@ -36,7 +36,7 @@ final class QRCodeReaderImagickTest extends QRCodeReaderTestAbstract{ protected function getLuminanceSourceFromFile( string $file, - SettingsContainerInterface|QROptions $options + SettingsContainerInterface|QROptions $options, ):LuminanceSourceInterface{ return IMagickLuminanceSource::fromFile($file, $options); } diff --git a/tests/QRCodeReaderTestAbstract.php b/tests/QRCodeReaderTestAbstract.php index a0e23e698..db4541fcf 100644 --- a/tests/QRCodeReaderTestAbstract.php +++ b/tests/QRCodeReaderTestAbstract.php @@ -20,6 +20,7 @@ use chillerlan\Settings\SettingsContainerInterface; use PHPUnit\Framework\Attributes\{DataProvider, Group}; use PHPUnit\Framework\TestCase; use Exception, Generator; +use RuntimeException; use function array_map, defined, realpath, sprintf, str_repeat, substr; /** @@ -83,7 +84,7 @@ abstract class QRCodeReaderTestAbstract extends TestCase{ abstract protected function getLuminanceSourceFromFile( string $file, - SettingsContainerInterface|QROptions $options + SettingsContainerInterface|QROptions $options, ):LuminanceSourceInterface; #[Group('slow')] @@ -95,7 +96,13 @@ abstract class QRCodeReaderTestAbstract extends TestCase{ $this->options->readerIncreaseContrast = true; } - $luminanceSource = $this->getLuminanceSourceFromFile(realpath($this::samplesDir.$img), $this->options); + $file = realpath($this::samplesDir.$img); + + if($file === false){ + throw new RuntimeException(sprintf('invalid file given: "%s" in samples directory "%s"', $img, $this::samplesDir)); + } + + $luminanceSource = $this->getLuminanceSourceFromFile($file, $this->options); $result = (new Decoder)->decode($luminanceSource); $this->debugMatrix($result->getQRMatrix()); @@ -141,7 +148,7 @@ abstract class QRCodeReaderTestAbstract extends TestCase{ yield 'version: '.$version.$eccLevel => [ $version, $eccLevel, - substr($str, 0, (self::getMaxLengthForMode(Mode::BYTE, $version, $eccLevel) ?? '')), + substr($str, 0, self::getMaxLengthForMode(Mode::BYTE, $version, $eccLevel)), ]; } } diff --git a/tests/QRMatrixDebugTrait.php b/tests/QRMatrixDebugTrait.php index 1f4105c13..424c33c6d 100644 --- a/tests/QRMatrixDebugTrait.php +++ b/tests/QRMatrixDebugTrait.php @@ -72,7 +72,7 @@ trait QRMatrixDebugTrait{ $out = (new QRStringText($options, $matrix))->dump(); - printf("\n\n%s\n\n", $out) ; + printf("\n\n%s\n\n", $out); } /** diff --git a/tests/QRMaxLengthTrait.php b/tests/QRMaxLengthTrait.php index 9d8239b2b..59472ef85 100644 --- a/tests/QRMaxLengthTrait.php +++ b/tests/QRMaxLengthTrait.php @@ -25,7 +25,7 @@ trait QRMaxLengthTrait{ * * @var int[][][] */ - protected const MAX_LENGTH =[ + protected const MAX_LENGTH = [ // v => [NUMERIC => [L, M, Q, H ], ALPHANUM => [L, M, Q, H], BINARY => [L, M, Q, H ], KANJI => [L, M, Q, H ]] 1 => [[ 41, 34, 27, 17], [ 25, 20, 16, 10], [ 17, 14, 11, 7], [ 10, 8, 7, 4]], 2 => [[ 77, 63, 48, 34], [ 47, 38, 29, 20], [ 32, 26, 20, 14], [ 20, 16, 12, 8]],