From fc47c7b40f2a72e1c2f7abdbe5e702f3c0601226 Mon Sep 17 00:00:00 2001 From: smiley Date: Mon, 22 Jul 2024 14:29:50 +0200 Subject: [PATCH] :octocat: PHPCS: add Slevomat standard --- composer.json | 6 +- examples/qrcode-interactive.php | 4 +- phpcs.xml.dist | 109 ++++++++++++++++++++++++ src/Data/ECI.php | 2 +- src/Decoder/ReedSolomonDecoder.php | 2 +- src/Detector/AlignmentPatternFinder.php | 3 +- src/Detector/FinderPatternFinder.php | 3 + src/QRCode.php | 2 +- 8 files changed, 124 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 4c6278ba8..39f4dd2cd 100644 --- a/composer.json +++ b/composer.json @@ -50,6 +50,7 @@ "phpunit/phpunit": "^9.6", "phpmd/phpmd": "^2.15", "setasign/fpdf": "^1.8.2", + "slevomat/coding-standard": "^8.15", "squizlabs/php_codesniffer": "^3.10" }, "suggest": { @@ -75,6 +76,9 @@ "config": { "lock": false, "sort-packages": true, - "platform-check": true + "platform-check": true, + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/examples/qrcode-interactive.php b/examples/qrcode-interactive.php index 2127e1a5f..267b41735 100644 --- a/examples/qrcode-interactive.php +++ b/examples/qrcode-interactive.php @@ -48,7 +48,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 ; } @@ -73,7 +73,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/phpcs.xml.dist b/phpcs.xml.dist index d8a7643dc..4b5082041 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -17,6 +17,115 @@ error + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + examples + + + + + + + + + + + + + + + diff --git a/src/Data/ECI.php b/src/Data/ECI.php index 5701be0bd..624fa10f3 100644 --- a/src/Data/ECI.php +++ b/src/Data/ECI.php @@ -108,7 +108,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/Decoder/ReedSolomonDecoder.php b/src/Decoder/ReedSolomonDecoder.php index 2bd539aad..5f104a1c8 100644 --- a/src/Decoder/ReedSolomonDecoder.php +++ b/src/Decoder/ReedSolomonDecoder.php @@ -94,7 +94,7 @@ final class ReedSolomonDecoder{ while($longerBlocksStartAt >= 0){ $numCodewords = count($result[$longerBlocksStartAt][1]); - if($numCodewords == $shorterBlocksTotalCodewords){ + if($numCodewords === $shorterBlocksTotalCodewords){ break; } diff --git a/src/Detector/AlignmentPatternFinder.php b/src/Detector/AlignmentPatternFinder.php index ca62c6f36..d9edc50bb 100644 --- a/src/Detector/AlignmentPatternFinder.php +++ b/src/Detector/AlignmentPatternFinder.php @@ -256,7 +256,7 @@ final class AlignmentPatternFinder{ $i++; } - if($i == $maxI || $stateCount[1] > $maxCount){ + if($i === $maxI || $stateCount[1] > $maxCount){ return null; } @@ -269,6 +269,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/FinderPatternFinder.php b/src/Detector/FinderPatternFinder.php index 755d08c27..61628d063 100644 --- a/src/Detector/FinderPatternFinder.php +++ b/src/Detector/FinderPatternFinder.php @@ -290,11 +290,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++; @@ -304,6 +306,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++; diff --git a/src/QRCode.php b/src/QRCode.php index b0b09140c..235cb06d6 100755 --- a/src/QRCode.php +++ b/src/QRCode.php @@ -303,7 +303,7 @@ class QRCode{ throw new QRCodeOutputException('invalid output module'); } - if(!in_array(QROutputInterface::class, class_implements($outputInterface))){ + if(!in_array(QROutputInterface::class, class_implements($outputInterface), true)){ throw new QRCodeOutputException('output module does not implement QROutputInterface'); }