diff --git a/composer.json b/composer.json
index 13b47839c..4c6278ba8 100644
--- a/composer.json
+++ b/composer.json
@@ -68,8 +68,9 @@
}
},
"scripts": {
- "phpunit": "@php vendor/bin/phpunit",
- "phan": "@php vendor/bin/phan"
+ "phan": "@php vendor/bin/phan",
+ "phpcs": "@php vendor/bin/phpcs",
+ "phpunit": "@php vendor/bin/phpunit"
},
"config": {
"lock": false,
diff --git a/examples/eps.php b/examples/eps.php
index 3a29dc2fb..47eab963e 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 465b284da..0dc97a1fd 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\QROutputInterface;
-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/imageWithRoundedShapes.php b/examples/imageWithRoundedShapes.php
index 687ca7d0d..b3a5fed2d 100644
--- a/examples/imageWithRoundedShapes.php
+++ b/examples/imageWithRoundedShapes.php
@@ -21,7 +21,7 @@ use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;
use chillerlan\Settings\SettingsContainerInterface;
-require_once __DIR__ . '/../vendor/autoload.php';
+require_once __DIR__.'/../vendor/autoload.php';
// --------------------
// Class definition
diff --git a/examples/imagickWithLogo.php b/examples/imagickWithLogo.php
index c4c506d8e..38f4fee1f 100644
--- a/examples/imagickWithLogo.php
+++ b/examples/imagickWithLogo.php
@@ -75,6 +75,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/svg.php b/examples/svg.php
index b0f221d8e..1ce3ec8ca 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/svgMeltedModules.php b/examples/svgMeltedModules.php
index 3cc0ea139..e281b2fd3 100644
--- a/examples/svgMeltedModules.php
+++ b/examples/svgMeltedModules.php
@@ -286,7 +286,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 4e89746e8..9ea3c33d5 100644
--- a/examples/svgRandomColoredDots.php
+++ b/examples/svgRandomColoredDots.php
@@ -155,7 +155,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 1ca58d7c6..68b75f6f4 100644
--- a/examples/svgRoundQuietzone.php
+++ b/examples/svgRoundQuietzone.php
@@ -349,7 +349,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 87a041413..833b59b8b 100644
--- a/examples/svgWithLogo.php
+++ b/examples/svgWithLogo.php
@@ -143,7 +143,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 d639257ba..133cd7da6 100644
--- a/examples/svgWithLogoAndCustomShapes.php
+++ b/examples/svgWithLogoAndCustomShapes.php
@@ -196,7 +196,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/phpcs.xml.dist b/phpcs.xml.dist
index 315dd3aa3..d8a7643dc 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -4,40 +4,117 @@
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
php-qrcode rules for phpcs
+
examples
src
tests
+
error
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ examples
+
+ examples
+ benchmark
+
+
+
+
+
@@ -46,10 +123,17 @@
-
+
+ examples
+
+
+
+
+
+
@@ -65,127 +149,62 @@
-
+
-
+
-
+
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
- error
-
-
-
- error
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
- examples
+
+
+
+
-
- examples
+
+
+
+
-
- examples
-
-
-
- examples
-
-
-
- examples
+
+
+
+
diff --git a/src/Common/LuminanceSourceAbstract.php b/src/Common/LuminanceSourceAbstract.php
index 78e83366f..e4373b87d 100644
--- a/src/Common/LuminanceSourceAbstract.php
+++ b/src/Common/LuminanceSourceAbstract.php
@@ -57,7 +57,10 @@ abstract class LuminanceSourceAbstract implements LuminanceSourceInterface{
return $this->height;
}
- /** @inheritDoc */
+ /**
+ * @inheritDoc
+ * @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException
+ */
public function getRow(int $y):array{
if($y < 0 || $y >= $this->getHeight()){
diff --git a/src/Data/AlphaNum.php b/src/Data/AlphaNum.php
index 77242d728..a62cb5474 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,
diff --git a/src/Data/ECI.php b/src/Data/ECI.php
index 3029e8373..5701be0bd 100644
--- a/src/Data/ECI.php
+++ b/src/Data/ECI.php
@@ -34,6 +34,7 @@ final class ECI extends QRDataModeAbstract{
/**
* @inheritDoc
+ * @throws \chillerlan\QRCode\Data\QRCodeDataException
* @noinspection PhpMissingParentConstructorInspection
*/
public function __construct(int $encoding){
diff --git a/src/Data/Hanzi.php b/src/Data/Hanzi.php
index 4476ad9d2..878d8952e 100644
--- a/src/Data/Hanzi.php
+++ b/src/Data/Hanzi.php
@@ -64,6 +64,7 @@ final class Hanzi extends QRDataModeAbstract{
/**
* @inheritDoc
+ * @throws \chillerlan\QRCode\Data\QRCodeDataException
*/
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 e42f96dc3..3a4c94c2e 100644
--- a/src/Data/Kanji.php
+++ b/src/Data/Kanji.php
@@ -57,6 +57,7 @@ final class Kanji extends QRDataModeAbstract{
/**
* @inheritDoc
+ * @throws \chillerlan\QRCode\Data\QRCodeDataException
*/
public static function convertEncoding(string $string):string{
mb_detect_order([mb_internal_encoding(), 'UTF-8', 'SJIS', 'SJIS-2004']);
diff --git a/src/Data/QRData.php b/src/Data/QRData.php
index 1d03a9d6b..9d610b357 100644
--- a/src/Data/QRData.php
+++ b/src/Data/QRData.php
@@ -207,7 +207,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);
diff --git a/src/Detector/GridSampler.php b/src/Detector/GridSampler.php
index 0d915e3e0..f70bb0eca 100644
--- a/src/Detector/GridSampler.php
+++ b/src/Detector/GridSampler.php
@@ -152,15 +152,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/Output/QREps.php b/src/Output/QREps.php
index 8dba009aa..76dd50b37 100644
--- a/src/Output/QREps.php
+++ b/src/Output/QREps.php
@@ -95,7 +95,7 @@ class QREps extends QROutputAbstract{
// CMYK
? '%f %f %f %f C'
// RGB
- :'%f %f %f R';
+ : '%f %f %f R';
return sprintf($format, ...$values);
}
diff --git a/src/Output/QRFpdf.php b/src/Output/QRFpdf.php
index 53ed811ac..8f2482cba 100644
--- a/src/Output/QRFpdf.php
+++ b/src/Output/QRFpdf.php
@@ -110,7 +110,7 @@ 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;
diff --git a/src/Output/QRStringJSON.php b/src/Output/QRStringJSON.php
index 1a7447c46..87ed2d7ff 100644
--- a/src/Output/QRStringJSON.php
+++ b/src/Output/QRStringJSON.php
@@ -27,7 +27,7 @@ class QRStringJSON extends QROutputAbstract{
*/
public function dump(?string $file = null):string{
$matrix = $this->matrix->getMatrix($this->options->jsonAsBooleans);
- $data = json_encode($matrix, $this->options->jsonFlags);;
+ $data = json_encode($matrix, $this->options->jsonFlags);
$this->saveToFile($data, $file);
diff --git a/src/QRCode.php b/src/QRCode.php
index 9b9f5400f..b0b09140c 100755
--- a/src/QRCode.php
+++ b/src/QRCode.php
@@ -462,8 +462,6 @@ class QRCode{
/**
* Reads a QR Code from a given file
- *
- * @noinspection PhpUndefinedMethodInspection
*/
public function readFromFile(string $path):DecoderResult{
return $this->readFromSource($this->luminanceSourceFQN::fromFile($path, $this->options));
@@ -471,8 +469,6 @@ class QRCode{
/**
* Reads a QR Code from the given data blob
- *
- * @noinspection PhpUndefinedMethodInspection
*/
public function readFromBlob(string $blob):DecoderResult{
return $this->readFromSource($this->luminanceSourceFQN::fromBlob($blob, $this->options));
diff --git a/tests/Performance/maskpattern.php b/tests/Performance/maskpattern.php
index 55295b79a..b6c3e74df 100644
--- a/tests/Performance/maskpattern.php
+++ b/tests/Performance/maskpattern.php
@@ -42,7 +42,6 @@ $generator = new class () {
];
}
}
-
};
$test = new PerformanceTest(100);
diff --git a/tests/Performance/output.php b/tests/Performance/output.php
index 4d96b5177..125faa34d 100644
--- a/tests/Performance/output.php
+++ b/tests/Performance/output.php
@@ -51,7 +51,6 @@ $generator = new class () {
}
}
-
};
$test = new PerformanceTest(100);
diff --git a/tests/Performance/qrcode.php b/tests/Performance/qrcode.php
index c796f80ac..1c4fb1e1d 100644
--- a/tests/Performance/qrcode.php
+++ b/tests/Performance/qrcode.php
@@ -61,7 +61,6 @@ $generator = new class () {
}
}
-
};
$test = new PerformanceTest(100);
diff --git a/tests/Performance/qrdata.php b/tests/Performance/qrdata.php
index 615baa8ca..2f26966b0 100644
--- a/tests/Performance/qrdata.php
+++ b/tests/Performance/qrdata.php
@@ -60,7 +60,6 @@ $generator = new class () {
}
}
-
};
$test = new PerformanceTest(100);
@@ -68,12 +67,14 @@ $json = [];
foreach($generator->dataProvider() as $key => [$version, $eccLevel, $dataModeInterface, $dataModeName, $data]){
// invovcation tests the performance of QRData::writeBitBuffer()
+ // phpcs:ignore
$test->run(fn() => new QRData(new QROptions(['version' => $version, 'eccLevel' => $eccLevel->getLevel()]), [new $dataModeInterface($data)]));
printf('%s encode: % 6.3fms', $key, $test->getResult());
$json[$dataModeName][(string)$eccLevel]['encode'][$version] = $test->getResult();
// writeMatrix includes QRMatrix::writeCodewords() and the ReedSolomonEncoder
+ // phpcs:ignore
$qrdata = new QRData(new QROptions(['version' => $version, 'eccLevel' => $eccLevel->getLevel()]), [new $dataModeInterface($data)]);
$test->run(fn() => $qrdata->writeMatrix());
diff --git a/tests/QRMaxLengthTrait.php b/tests/QRMaxLengthTrait.php
index 7fe07ab5a..e52e530d8 100644
--- a/tests/QRMaxLengthTrait.php
+++ b/tests/QRMaxLengthTrait.php
@@ -25,7 +25,7 @@ trait QRMaxLengthTrait{
*
* @var int[][][]
*/
- private static array $MAX_LENGTH =[
+ private static array $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]],