فهرست منبع

:lipstick: code style fixes

smiley 2 سال پیش
والد
کامیت
6b2a529160
74فایلهای تغییر یافته به همراه845 افزوده شده و 779 حذف شده
  1. 2 2
      examples/custom_output.php
  2. 17 20
      examples/eps.php
  3. 15 15
      examples/fpdf.php
  4. 16 19
      examples/html.php
  5. 22 18
      examples/image.php
  6. 6 6
      examples/imageWithLogo.php
  7. 5 8
      examples/imageWithText.php
  8. 21 17
      examples/imagick.php
  9. 8 4
      examples/imagickWithLogo.php
  10. 20 20
      examples/qrcode-interactive.php
  11. 2 2
      examples/svg.php
  12. 20 20
      examples/svgMeltedModules.php
  13. 7 7
      examples/svgRandomColoredDots.php
  14. 20 20
      examples/svgRoundQuietzone.php
  15. 4 4
      examples/svgWithLogo.php
  16. 5 5
      examples/svgWithLogoAndCustomShapes.php
  17. 20 20
      examples/text.php
  18. 10 10
      src/Common/BitBuffer.php
  19. 2 2
      src/Common/GF256.php
  20. 18 18
      src/Common/GenericGFPoly.php
  21. 34 34
      src/Common/MaskPattern.php
  22. 10 10
      src/Common/ReedSolomonDecoder.php
  23. 8 8
      src/Common/ReedSolomonEncoder.php
  24. 2 2
      src/Common/Version.php
  25. 2 2
      src/Data/Byte.php
  26. 19 13
      src/Data/Hanzi.php
  27. 13 13
      src/Data/Kanji.php
  28. 4 4
      src/Data/Number.php
  29. 6 1
      src/Data/QRCodeDataException.php
  30. 4 4
      src/Data/QRData.php
  31. 43 40
      src/Data/QRMatrix.php
  32. 32 32
      src/Decoder/Binarizer.php
  33. 16 16
      src/Decoder/BitMatrix.php
  34. 69 56
      src/Decoder/Decoder.php
  35. 1 1
      src/Decoder/IMagickLuminanceSource.php
  36. 4 4
      src/Decoder/LuminanceSourceAbstract.php
  37. 6 1
      src/Decoder/QRCodeDecoderException.php
  38. 3 3
      src/Detector/AlignmentPattern.php
  39. 10 11
      src/Detector/AlignmentPatternFinder.php
  40. 36 36
      src/Detector/Detector.php
  41. 5 5
      src/Detector/FinderPattern.php
  42. 33 30
      src/Detector/FinderPatternFinder.php
  43. 18 13
      src/Detector/GridSampler.php
  44. 45 41
      src/Detector/PerspectiveTransform.php
  45. 6 1
      src/Detector/QRCodeDetectorException.php
  46. 6 1
      src/Output/QRCodeOutputException.php
  47. 6 6
      src/Output/QREps.php
  48. 2 2
      src/Output/QRFpdf.php
  49. 7 7
      src/Output/QRGdImage.php
  50. 15 11
      src/Output/QRImagick.php
  51. 1 1
      src/Output/QRMarkup.php
  52. 5 5
      src/Output/QRMarkupSVG.php
  53. 2 2
      src/Output/QROutputAbstract.php
  54. 33 33
      src/Output/QROutputInterface.php
  55. 1 1
      src/Output/QRString.php
  56. 3 3
      src/QRCode.php
  57. 3 1
      src/QRCodeException.php
  58. 2 2
      src/QROptionsTrait.php
  59. 2 2
      tests/Common/EccLevelTest.php
  60. 4 2
      tests/Common/MaskPatternTest.php
  61. 6 6
      tests/Common/ModeTest.php
  62. 2 2
      tests/Common/VersionTest.php
  63. 1 5
      tests/Data/DataInterfaceTestAbstract.php
  64. 1 1
      tests/Data/QRDataTest.php
  65. 58 53
      tests/Data/QRMatrixTest.php
  66. 2 2
      tests/Output/QRFpdfTest.php
  67. 2 2
      tests/Output/QRGdImageTestAbstract.php
  68. 2 2
      tests/Output/QRImagickTest.php
  69. 2 2
      tests/Output/QRMarkupTestAbstract.php
  70. 1 0
      tests/Output/QRStringJSONTest.php
  71. 2 2
      tests/Output/QRStringTEXTTest.php
  72. 1 1
      tests/QRCodeReaderTestAbstract.php
  73. 2 2
      tests/QRMaxLengthTrait.php
  74. 2 2
      tests/QROptionsTest.php

+ 2 - 2
examples/custom_output.php

@@ -72,8 +72,8 @@ $data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s';
 
 // invoke the QROutputInterface manually
 $options = new QROptions([
-	'version'      => 5,
-	'eccLevel'     => EccLevel::L,
+	'version'  => 5,
+	'eccLevel' => EccLevel::L,
 ]);
 
 $qrcode = new QRCode($options);

+ 17 - 20
examples/eps.php

@@ -23,32 +23,32 @@ $options = new QROptions([
 	'cachefile'        => __DIR__.'/test.eps', // save to file
 	'moduleValues'     => [
 		// finder
-		QRMatrix::M_FINDER | QRMatrix::IS_DARK     => [0, 63, 255], // dark (true)
-		QRMatrix::M_FINDER                         => [233, 233, 233], // light (false)
-		QRMatrix::M_FINDER_DOT | QRMatrix::IS_DARK => [0, 63, 255], // finder dot, dark (true)
+		(QRMatrix::M_FINDER | QRMatrix::IS_DARK)     => [0, 63, 255], // dark (true)
+		QRMatrix::M_FINDER                           => [233, 233, 233], // light (false)
+		(QRMatrix::M_FINDER_DOT | QRMatrix::IS_DARK) => [0, 63, 255], // finder dot, dark (true)
 		// alignment
-		QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK  => [255, 0, 255],
-		QRMatrix::M_ALIGNMENT                      => [233, 233, 233],
+		(QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK)  => [255, 0, 255],
+		QRMatrix::M_ALIGNMENT                        => [233, 233, 233],
 		// timing
-		QRMatrix::M_TIMING | QRMatrix::IS_DARK     => [255, 0, 0],
-		QRMatrix::M_TIMING                         => [233, 233, 233],
+		(QRMatrix::M_TIMING | QRMatrix::IS_DARK)     => [255, 0, 0],
+		QRMatrix::M_TIMING                           => [233, 233, 233],
 		// format
-		QRMatrix::M_FORMAT | QRMatrix::IS_DARK     => [67, 159, 84],
-		QRMatrix::M_FORMAT                         => [233, 233, 233],
+		(QRMatrix::M_FORMAT | QRMatrix::IS_DARK)     => [67, 159, 84],
+		QRMatrix::M_FORMAT                           => [233, 233, 233],
 		// version
-		QRMatrix::M_VERSION | QRMatrix::IS_DARK    => [62, 174, 190],
-		QRMatrix::M_VERSION                        => [233, 233, 233],
+		(QRMatrix::M_VERSION | QRMatrix::IS_DARK)    => [62, 174, 190],
+		QRMatrix::M_VERSION                          => [233, 233, 233],
 		// data
-		QRMatrix::M_DATA | QRMatrix::IS_DARK       => [0, 0, 0],
-		QRMatrix::M_DATA                           => [233, 233, 233],
+		(QRMatrix::M_DATA | QRMatrix::IS_DARK)       => [0, 0, 0],
+		QRMatrix::M_DATA                             => [233, 233, 233],
 		// darkmodule
-		QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK => [0, 0, 0],
+		(QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK) => [0, 0, 0],
 		// separator
-		QRMatrix::M_SEPARATOR                      => [233, 233, 233],
+		QRMatrix::M_SEPARATOR                        => [233, 233, 233],
 		// quietzone
-		QRMatrix::M_QUIETZONE                      => [233, 233, 233],
+		QRMatrix::M_QUIETZONE                        => [233, 233, 233],
 		// logo (requires a call to QRMatrix::setLogoSpace()), see QRImageWithLogo
-		QRMatrix::M_LOGO                           => [233, 233, 233],
+		QRMatrix::M_LOGO                             => [233, 233, 233],
 	],
 ]);
 
@@ -62,6 +62,3 @@ if(php_sapi_name() !== 'cli'){
 echo (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
 
 exit;
-
-
-

+ 15 - 15
examples/fpdf.php

@@ -22,29 +22,29 @@ $options = new QROptions([
     'imageBase64'      => false,
     'moduleValues'     => [
         // finder
-        QRMatrix::M_FINDER | QRMatrix::IS_DARK     => [0, 63, 255], // dark (true)
-        QRMatrix::M_FINDER                         => [255, 255, 255], // light (false), white is the transparency color and is enabled by default
+        (QRMatrix::M_FINDER | QRMatrix::IS_DARK)     => [0, 63, 255], // dark (true)
+        QRMatrix::M_FINDER                           => [255, 255, 255], // light (false), white is the transparency color and is enabled by default
         // alignment
-        QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK  => [255, 0, 255],
-        QRMatrix::M_ALIGNMENT                      => [255, 255, 255],
+        (QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK)  => [255, 0, 255],
+        QRMatrix::M_ALIGNMENT                        => [255, 255, 255],
         // timing
-        QRMatrix::M_TIMING | QRMatrix::IS_DARK     => [255, 0, 0],
-        QRMatrix::M_TIMING                         => [255, 255, 255],
+        (QRMatrix::M_TIMING | QRMatrix::IS_DARK)     => [255, 0, 0],
+        QRMatrix::M_TIMING                           => [255, 255, 255],
         // format
-        QRMatrix::M_FORMAT | QRMatrix::IS_DARK     => [67, 191, 84],
-        QRMatrix::M_FORMAT                         => [255, 255, 255],
+        (QRMatrix::M_FORMAT | QRMatrix::IS_DARK)     => [67, 191, 84],
+        QRMatrix::M_FORMAT                           => [255, 255, 255],
         // version
-        QRMatrix::M_VERSION | QRMatrix::IS_DARK    => [62, 174, 190],
-        QRMatrix::M_VERSION                        => [255, 255, 255],
+        (QRMatrix::M_VERSION | QRMatrix::IS_DARK)    => [62, 174, 190],
+        QRMatrix::M_VERSION                          => [255, 255, 255],
         // data
-        QRMatrix::M_DATA | QRMatrix::IS_DARK       => [0, 0, 0],
-        QRMatrix::M_DATA                           => [255, 255, 255],
+        (QRMatrix::M_DATA | QRMatrix::IS_DARK)       => [0, 0, 0],
+        QRMatrix::M_DATA                             => [255, 255, 255],
         // darkmodule
-        QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK => [0, 0, 0],
+        (QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK) => [0, 0, 0],
         // separator
-        QRMatrix::M_SEPARATOR                      => [255, 255, 255],
+        QRMatrix::M_SEPARATOR                        => [255, 255, 255],
         // quietzone
-        QRMatrix::M_QUIETZONE                      => [255, 255, 255],
+        QRMatrix::M_QUIETZONE                        => [255, 255, 255],
     ],
 ]);
 

+ 16 - 19
examples/html.php

@@ -22,30 +22,30 @@ header('Content-Type: text/html; charset=utf-8');
 		'cssClass'     => 'qrcode',
 		'moduleValues' => [
 			// finder
-			QRMatrix::M_FINDER | QRMatrix::IS_DARK     => '#A71111', // dark (true)
-			QRMatrix::M_FINDER                         => '#FFBFBF', // light (false)
-			QRMatrix::M_FINDER_DOT | QRMatrix::IS_DARK => '#A71111', // finder dot, dark (true)
+			(QRMatrix::M_FINDER | QRMatrix::IS_DARK)     => '#A71111', // dark (true)
+			QRMatrix::M_FINDER                           => '#FFBFBF', // light (false)
+			(QRMatrix::M_FINDER_DOT | QRMatrix::IS_DARK) => '#A71111', // finder dot, dark (true)
 			// alignment
-			QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK  => '#A70364',
-			QRMatrix::M_ALIGNMENT                      => '#FFC9C9',
+			(QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK)  => '#A70364',
+			QRMatrix::M_ALIGNMENT                        => '#FFC9C9',
 			// timing
-			QRMatrix::M_TIMING | QRMatrix::IS_DARK     => '#98005D',
-			QRMatrix::M_TIMING                         => '#FFB8E9',
+			(QRMatrix::M_TIMING | QRMatrix::IS_DARK)     => '#98005D',
+			QRMatrix::M_TIMING                           => '#FFB8E9',
 			// format
-			QRMatrix::M_FORMAT | QRMatrix::IS_DARK     => '#003804',
-			QRMatrix::M_FORMAT                         => '#00FB12',
+			(QRMatrix::M_FORMAT | QRMatrix::IS_DARK)     => '#003804',
+			QRMatrix::M_FORMAT                           => '#00FB12',
 			// version
-			QRMatrix::M_VERSION | QRMatrix::IS_DARK    => '#650098',
-			QRMatrix::M_VERSION                        => '#E0B8FF',
+			(QRMatrix::M_VERSION | QRMatrix::IS_DARK)    => '#650098',
+			QRMatrix::M_VERSION                          => '#E0B8FF',
 			// data
-			QRMatrix::M_DATA | QRMatrix::IS_DARK       => '#4A6000',
-			QRMatrix::M_DATA                           => '#ECF9BE',
+			(QRMatrix::M_DATA | QRMatrix::IS_DARK)       => '#4A6000',
+			QRMatrix::M_DATA                             => '#ECF9BE',
 			// darkmodule
-			QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK => '#080063',
+			(QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK) => '#080063',
 			// separator
-			QRMatrix::M_SEPARATOR                      => '#AFBFBF',
+			QRMatrix::M_SEPARATOR                        => '#AFBFBF',
 			// quietzone
-			QRMatrix::M_QUIETZONE                      => '#DDDDDD',
+			QRMatrix::M_QUIETZONE                        => '#DDDDDD',
 		],
 	]);
 
@@ -82,6 +82,3 @@ echo (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ
 ?>
 </body>
 </html>
-
-
-

+ 22 - 18
examples/image.php

@@ -23,35 +23,39 @@ $options = new QROptions([
 	'imageTransparent'    => false,
 	'drawCircularModules' => true,
 	'circleRadius'        => 0.4,
-	'keepAsSquare'        => [QRMatrix::M_FINDER|QRMatrix::IS_DARK, QRMatrix::M_FINDER_DOT, QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK],
+	'keepAsSquare'        => [
+		(QRMatrix::M_FINDER|QRMatrix::IS_DARK),
+		QRMatrix::M_FINDER_DOT,
+		(QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK),
+	],
 	'moduleValues'        => [
 		// finder
-		QRMatrix::M_FINDER | QRMatrix::IS_DARK     => [0, 63, 255], // dark (true)
-		QRMatrix::M_FINDER                         => [233, 233, 233], // light (false), white is the transparency color and is enabled by default
-		QRMatrix::M_FINDER_DOT | QRMatrix::IS_DARK => [0, 63, 255], // finder dot, dark (true)
+		(QRMatrix::M_FINDER | QRMatrix::IS_DARK)     => [0, 63, 255], // dark (true)
+		QRMatrix::M_FINDER                           => [233, 233, 233], // light (false), white is the transparency color and is enabled by default
+		(QRMatrix::M_FINDER_DOT | QRMatrix::IS_DARK) => [0, 63, 255], // finder dot, dark (true)
 		// alignment
-		QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK  => [255, 0, 255],
-		QRMatrix::M_ALIGNMENT                      => [233, 233, 233],
+		(QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK)  => [255, 0, 255],
+		QRMatrix::M_ALIGNMENT                        => [233, 233, 233],
 		// timing
-		QRMatrix::M_TIMING | QRMatrix::IS_DARK     => [255, 0, 0],
-		QRMatrix::M_TIMING                         => [233, 233, 233],
+		(QRMatrix::M_TIMING | QRMatrix::IS_DARK)     => [255, 0, 0],
+		QRMatrix::M_TIMING                           => [233, 233, 233],
 		// format
-		QRMatrix::M_FORMAT | QRMatrix::IS_DARK     => [67, 159, 84],
-		QRMatrix::M_FORMAT                         => [233, 233, 233],
+		(QRMatrix::M_FORMAT | QRMatrix::IS_DARK)     => [67, 159, 84],
+		QRMatrix::M_FORMAT                           => [233, 233, 233],
 		// version
-		QRMatrix::M_VERSION | QRMatrix::IS_DARK    => [62, 174, 190],
-		QRMatrix::M_VERSION                        => [233, 233, 233],
+		(QRMatrix::M_VERSION | QRMatrix::IS_DARK)    => [62, 174, 190],
+		QRMatrix::M_VERSION                          => [233, 233, 233],
 		// data
-		QRMatrix::M_DATA | QRMatrix::IS_DARK       => [0, 0, 0],
-		QRMatrix::M_DATA                           => [233, 233, 233],
+		(QRMatrix::M_DATA | QRMatrix::IS_DARK)       => [0, 0, 0],
+		QRMatrix::M_DATA                             => [233, 233, 233],
 		// darkmodule
-		QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK => [0, 0, 0],
+		(QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK) => [0, 0, 0],
 		// separator
-		QRMatrix::M_SEPARATOR                      => [233, 233, 233],
+		QRMatrix::M_SEPARATOR                        => [233, 233, 233],
 		// quietzone
-		QRMatrix::M_QUIETZONE                      => [233, 233, 233],
+		QRMatrix::M_QUIETZONE                        => [233, 233, 233],
 		// logo (requires a call to QRMatrix::setLogoSpace()), see QRImageWithLogo
-		QRMatrix::M_LOGO                           => [233, 233, 233],
+		QRMatrix::M_LOGO                             => [233, 233, 233],
 	],
 ]);
 

+ 6 - 6
examples/imageWithLogo.php

@@ -32,8 +32,8 @@ class QRImageWithLogo extends QRGdImage{
 		// set returnResource to true to skip further processing for now
 		$this->options->returnResource = true;
 
-		// of course you could accept other formats too (such as resource or Imagick)
-		// i'm not checking for the file type either for simplicity reasons (assuming PNG)
+		// of course, you could accept other formats too (such as resource or Imagick)
+		// I'm not checking for the file type either for simplicity reasons (assuming PNG)
 		if(!is_file($logo) || !is_readable($logo)){
 			throw new QRCodeOutputException('invalid logo');
 		}
@@ -48,14 +48,14 @@ class QRImageWithLogo extends QRGdImage{
 		$h = imagesy($im);
 
 		// set new logo size, leave a border of 1 module (no proportional resize/centering)
-		$lw = ($this->options->logoSpaceWidth - 2) * $this->options->scale;
-		$lh = ($this->options->logoSpaceHeight - 2) * $this->options->scale;
+		$lw = (($this->options->logoSpaceWidth - 2) * $this->options->scale);
+		$lh = (($this->options->logoSpaceHeight - 2) * $this->options->scale);
 
 		// get the qrcode size
-		$ql = $this->matrix->size() * $this->options->scale;
+		$ql = ($this->matrix->size() * $this->options->scale);
 
 		// scale the logo and copy it over. done!
-		imagecopyresampled($this->image, $im, ($ql - $lw) / 2, ($ql - $lh) / 2, 0, 0, $lw, $lh, $w, $h);
+		imagecopyresampled($this->image, $im, (($ql - $lw) / 2), (($ql - $lh) / 2), 0, 0, $lw, $lh, $w, $h);
 
 		$imageData = $this->dumpImage();
 

+ 5 - 8
examples/imageWithText.php

@@ -48,9 +48,6 @@ class QRImageWithText extends QRGdImage{
 		return $imageData;
 	}
 
-	/**
-	 * @inheritDoc
-	 */
 	protected function addText(string $text):void{
 		// save the qrcode image
 		$qrcode = $this->image;
@@ -61,7 +58,7 @@ class QRImageWithText extends QRGdImage{
 		$textColor = [50, 50, 50];
 
 		$bgWidth  = $this->length;
-		$bgHeight = $bgWidth + 20; // 20px extra space
+		$bgHeight = ($bgWidth + 20); // 20px extra space
 
 		// create a new image with additional space
 		$this->image = imagecreatetruecolor($bgWidth, $bgHeight);
@@ -97,10 +94,10 @@ class QRImageWithText extends QRGdImage{
  */
 
 $options = new QROptions([
-	'version'      => 7,
-	'outputType'   => QROutputInterface::GDIMAGE_PNG,
-	'scale'        => 3,
-	'imageBase64'  => false,
+	'version'     => 7,
+	'outputType'  => QROutputInterface::GDIMAGE_PNG,
+	'scale'       => 3,
+	'imageBase64' => false,
 ]);
 
 $qrcode = new QRCode($options);

+ 21 - 17
examples/imagick.php

@@ -23,33 +23,37 @@ $options = new QROptions([
 	'drawLightModules'    => true,
 	'drawCircularModules' => true,
 	'circleRadius'        => 0.4,
-	'keepAsSquare'        => [QRMatrix::M_FINDER|QRMatrix::IS_DARK, QRMatrix::M_FINDER_DOT, QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK],
+	'keepAsSquare'        => [
+		(QRMatrix::M_FINDER|QRMatrix::IS_DARK),
+		QRMatrix::M_FINDER_DOT,
+		(QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK),
+	],
 	'moduleValues'        => [
 		// finder
-		QRMatrix::M_FINDER | QRMatrix::IS_DARK     => '#A71111', // dark (true)
-		QRMatrix::M_FINDER                         => '#FFBFBF', // light (false)
-		QRMatrix::M_FINDER_DOT | QRMatrix::IS_DARK => '#A71111', // finder dot, dark (true)
+		(QRMatrix::M_FINDER | QRMatrix::IS_DARK)     => '#A71111', // dark (true)
+		QRMatrix::M_FINDER                           => '#FFBFBF', // light (false)
+		(QRMatrix::M_FINDER_DOT | QRMatrix::IS_DARK) => '#A71111', // finder dot, dark (true)
 		// alignment
-		QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK  => '#A70364',
-		QRMatrix::M_ALIGNMENT                      => '#FFC9C9',
+		(QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK)  => '#A70364',
+		QRMatrix::M_ALIGNMENT                        => '#FFC9C9',
 		// timing
-		QRMatrix::M_TIMING | QRMatrix::IS_DARK     => '#98005D',
-		QRMatrix::M_TIMING                         => '#FFB8E9',
+		(QRMatrix::M_TIMING | QRMatrix::IS_DARK)     => '#98005D',
+		QRMatrix::M_TIMING                           => '#FFB8E9',
 		// format
-		QRMatrix::M_FORMAT | QRMatrix::IS_DARK     => '#003804',
-		QRMatrix::M_FORMAT                         => '#CCFB12',
+		(QRMatrix::M_FORMAT | QRMatrix::IS_DARK)     => '#003804',
+		QRMatrix::M_FORMAT                           => '#CCFB12',
 		// version
-		QRMatrix::M_VERSION | QRMatrix::IS_DARK    => '#650098',
-		QRMatrix::M_VERSION                        => '#E0B8FF',
+		(QRMatrix::M_VERSION | QRMatrix::IS_DARK)    => '#650098',
+		QRMatrix::M_VERSION                          => '#E0B8FF',
 		// data
-		QRMatrix::M_DATA | QRMatrix::IS_DARK       => '#4A6000',
-		QRMatrix::M_DATA                           => '#ECF9BE',
+		(QRMatrix::M_DATA | QRMatrix::IS_DARK)       => '#4A6000',
+		QRMatrix::M_DATA                             => '#ECF9BE',
 		// darkmodule
-		QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK => '#080063',
+		(QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK) => '#080063',
 		// separator
-		QRMatrix::M_SEPARATOR                      => '#DDDDDD',
+		QRMatrix::M_SEPARATOR                        => '#DDDDDD',
 		// quietzone
-		QRMatrix::M_QUIETZONE                      => '#DDDDDD',
+		QRMatrix::M_QUIETZONE                        => '#DDDDDD',
 	],
 ]);
 

+ 8 - 4
examples/imagickWithLogo.php

@@ -35,10 +35,10 @@ class QRImagickWithLogo extends QRImagick{
 		parent::dump($file);
 
 		// set new logo size, leave a border of 1 module (no proportional resize/centering)
-		$size = ($this->options->logoSpaceWidth - 2) * $this->options->scale;
+		$size = (($this->options->logoSpaceWidth - 2) * $this->options->scale);
 
 		// logo position: the top left corner of the logo space
-		$pos  = ($this->moduleCount * $this->options->scale - $size) / 2;
+		$pos  = (($this->moduleCount * $this->options->scale - $size) / 2);
 
 		// invoke logo instance
 		$imLogo = new Imagick($this->options->pngLogo);
@@ -72,7 +72,7 @@ class ImagickWithLogoOptions extends QROptions{
 	/**
 	 * check logo
 	 *
-	 * of course we could accept other formats too.
+	 * of course, we could accept other formats too.
 	 * we're not checking for the file type either for simplicity reasons (assuming PNG)
 	 */
 	protected function set_pngLogo(string $pngLogo):void{
@@ -109,7 +109,11 @@ $options = new ImagickWithLogoOptions([
 	'drawLightModules'    => false,
 	'drawCircularModules' => true,
 	'circleRadius'        => 0.4,
-	'keepAsSquare'        => [QRMatrix::M_FINDER|QRMatrix::IS_DARK, QRMatrix::M_FINDER_DOT, QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK],
+	'keepAsSquare'        => [
+		(QRMatrix::M_FINDER|QRMatrix::IS_DARK),
+		QRMatrix::M_FINDER_DOT,
+		(QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK),
+	],
 ]);
 
 

+ 20 - 20
examples/qrcode-interactive.php

@@ -18,32 +18,32 @@ try{
 
 	$moduleValues = [
 		// finder
-		QRMatrix::M_FINDER | QRMatrix::IS_DARK     => $_POST['m_finder_dark'],
-		QRMatrix::M_FINDER                         => $_POST['m_finder_light'],
-		QRMatrix::M_FINDER_DOT | QRMatrix::IS_DARK => $_POST['m_finder_dot_dark'],
+		(QRMatrix::M_FINDER | QRMatrix::IS_DARK)     => $_POST['m_finder_dark'],
+		QRMatrix::M_FINDER                           => $_POST['m_finder_light'],
+		(QRMatrix::M_FINDER_DOT | QRMatrix::IS_DARK) => $_POST['m_finder_dot_dark'],
 		// alignment
-		QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK  => $_POST['m_alignment_dark'],
-		QRMatrix::M_ALIGNMENT                      => $_POST['m_alignment_light'],
+		(QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK)  => $_POST['m_alignment_dark'],
+		QRMatrix::M_ALIGNMENT                        => $_POST['m_alignment_light'],
 		// timing
-		QRMatrix::M_TIMING | QRMatrix::IS_DARK     => $_POST['m_timing_dark'],
-		QRMatrix::M_TIMING                         => $_POST['m_timing_light'],
+		(QRMatrix::M_TIMING | QRMatrix::IS_DARK)     => $_POST['m_timing_dark'],
+		QRMatrix::M_TIMING                           => $_POST['m_timing_light'],
 		// format
-		QRMatrix::M_FORMAT | QRMatrix::IS_DARK     => $_POST['m_format_dark'],
-		QRMatrix::M_FORMAT                         => $_POST['m_format_light'],
+		(QRMatrix::M_FORMAT | QRMatrix::IS_DARK)     => $_POST['m_format_dark'],
+		QRMatrix::M_FORMAT                           => $_POST['m_format_light'],
 		// version
-		QRMatrix::M_VERSION | QRMatrix::IS_DARK    => $_POST['m_version_dark'],
-		QRMatrix::M_VERSION                        => $_POST['m_version_light'],
+		(QRMatrix::M_VERSION | QRMatrix::IS_DARK)    => $_POST['m_version_dark'],
+		QRMatrix::M_VERSION                          => $_POST['m_version_light'],
 		// data
-		QRMatrix::M_DATA | QRMatrix::IS_DARK       => $_POST['m_data_dark'],
-		QRMatrix::M_DATA                           => $_POST['m_data_light'],
+		(QRMatrix::M_DATA | QRMatrix::IS_DARK)       => $_POST['m_data_dark'],
+		QRMatrix::M_DATA                             => $_POST['m_data_light'],
 		// darkmodule
-		QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK => $_POST['m_darkmodule_dark'],
+		(QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK) => $_POST['m_darkmodule_dark'],
 		// separator
-		QRMatrix::M_SEPARATOR                      => $_POST['m_separator_light'],
+		QRMatrix::M_SEPARATOR                        => $_POST['m_separator_light'],
 		// quietzone
-		QRMatrix::M_QUIETZONE                      => $_POST['m_quietzone_light'],
+		QRMatrix::M_QUIETZONE                        => $_POST['m_quietzone_light'],
 		// logo
-		QRMatrix::M_LOGO                           => $_POST['m_logo_light'],
+		QRMatrix::M_LOGO                             => $_POST['m_logo_light'],
 	];
 
 	$moduleValues = array_map(function($v){
@@ -83,12 +83,12 @@ try{
 		$qrcode = '<pre style="font-size: 75%; overflow-x: auto;">'.$qrcode.'</pre>';
 	}
 
-	send_response(['qrcode' => $qrcode]);
+	sendResponse(['qrcode' => $qrcode]);
 }
 // Pokémon exception handler
 catch(Throwable $e){
 	header('HTTP/1.1 500 Internal Server Error');
-	send_response(['error' => $e->getMessage()]);
+	sendResponse(['error' => $e->getMessage()]);
 }
 
 exit;
@@ -96,7 +96,7 @@ exit;
 /**
  * @param array $response
  */
-function send_response(array $response){
+function sendResponse(array $response){
 	header('Content-type: application/json;charset=utf-8;');
 	echo json_encode($response);
 	exit;

+ 2 - 2
examples/svg.php

@@ -34,9 +34,9 @@ $options = new QROptions([
 	'connectPaths'        => true,
 	// keep modules of these types as square
 	'keepAsSquare'        => [
-		QRMatrix::M_FINDER|QRMatrix::IS_DARK,
+		(QRMatrix::M_FINDER|QRMatrix::IS_DARK),
 		QRMatrix::M_FINDER_DOT,
-		QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK,
+		(QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK),
 	],
 	// https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient
 	'svgDefs'             => '

+ 20 - 20
examples/svgMeltedModules.php

@@ -85,7 +85,7 @@ class MeltedSVGQRCodeOutput extends QRMarkupSVG{
 
 		$r = $this->options->meltRadius;
 
-		return sprintf($template, $x, $y, $r, 1 - $r, 1 - 2 * $r);
+		return sprintf($template, $x, $y, $r, (1 - $r), (1 - 2 * $r));
 	}
 
 	/**
@@ -244,26 +244,26 @@ class MeltedOutputOptions extends QROptions{
  */
 
 $options = new MeltedOutputOptions([
-	'melt'            => true,
-	'inverseMelt'     => true,
-	'meltRadius'      => 0.4,
-
-	'version'         => 7,
-	'eccLevel'        => EccLevel::H,
-	'addQuietzone'    => true,
-	'addLogoSpace'    => true,
-	'logoSpaceWidth'  => 13,
-	'logoSpaceHeight' => 13,
-	'connectPaths'    => true,
-	'imageBase64'     => false,
-
-	'outputType'      => QROutputInterface::CUSTOM,
-	'outputInterface' => MeltedSVGQRCodeOutput::class,
-	'excludeFromConnect'        => [
-		QRMatrix::M_FINDER|QRMatrix::IS_DARK,
-		QRMatrix::M_FINDER_DOT|QRMatrix::IS_DARK,
+	'melt'               => true,
+	'inverseMelt'        => true,
+	'meltRadius'         => 0.4,
+
+	'version'            => 7,
+	'eccLevel'           => EccLevel::H,
+	'addQuietzone'       => true,
+	'addLogoSpace'       => true,
+	'logoSpaceWidth'     => 13,
+	'logoSpaceHeight'    => 13,
+	'connectPaths'       => true,
+	'imageBase64'        => false,
+
+	'outputType'         => QROutputInterface::CUSTOM,
+	'outputInterface'    => MeltedSVGQRCodeOutput::class,
+	'excludeFromConnect' => [
+		(QRMatrix::M_FINDER|QRMatrix::IS_DARK),
+		(QRMatrix::M_FINDER_DOT|QRMatrix::IS_DARK),
 	],
-	'svgDefs'             => '
+	'svgDefs'            => '
 	<linearGradient id="rainbow" x1="100%" y2="100%">
 		<stop stop-color="#e2453c" offset="2.5%"/>
 		<stop stop-color="#e07e39" offset="21.5%"/>

+ 7 - 7
examples/svgRandomColoredDots.php

@@ -58,7 +58,7 @@ class RandomDotsSVGOutput extends QRMarkupSVG{
 
 				// randomly assign another $M_TYPE_LAYER for the given types
 				// note that the layer id has to be an integer value,
-				// ideally outside of the several bitmask values
+				// ideally outside the several bitmask values
 				if($M_TYPE_LAYER === (QRMatrix::M_DATA | QRMatrix::IS_DARK)){
 					$M_TYPE_LAYER = array_rand($this->options->dotColors);
 				}
@@ -134,17 +134,17 @@ $options = new RandomDotsOptions([
 
 	'connectPaths'        => true,
 	'excludeFromConnect'  => [
-		QRMatrix::M_FINDER|QRMatrix::IS_DARK,
-		QRMatrix::M_FINDER_DOT|QRMatrix::IS_DARK,
-		QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK,
+		(QRMatrix::M_FINDER|QRMatrix::IS_DARK),
+		(QRMatrix::M_FINDER_DOT|QRMatrix::IS_DARK),
+		(QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK),
 	],
 
 	'drawCircularModules' => true,
 	'circleRadius'        => 0.4,
 	'keepAsSquare'        => [
-		QRMatrix::M_FINDER|QRMatrix::IS_DARK,
-		QRMatrix::M_FINDER_DOT|QRMatrix::IS_DARK,
-		QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK,
+		(QRMatrix::M_FINDER|QRMatrix::IS_DARK),
+		(QRMatrix::M_FINDER_DOT|QRMatrix::IS_DARK),
+		(QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK),
 	],
 
 ]);

+ 20 - 20
examples/svgRoundQuietzone.php

@@ -32,16 +32,16 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
 	 */
 	protected function createMarkup(bool $saveToFile):string{
 		// some Pythagorean magick
-		$diameter      = sqrt(2 * pow($this->moduleCount + $this->options->additionalModules, 2));
+		$diameter      = sqrt(2 * pow(($this->moduleCount + $this->options->additionalModules), 2));
 		// calculate the quiet zone size, add 1 to it as the outer circle stroke may go outside of it
-		$quietzoneSize = (int)ceil(($diameter - $this->moduleCount) / 2) + 1;
+		$quietzoneSize = ((int)ceil(($diameter - $this->moduleCount) / 2) + 1);
 		// add the quiet zone to fill the circle
 		$this->matrix->setQuietZone($quietzoneSize);
 		// update the matrix dimensions to avoid errors in subsequent calculations
 		// the moduleCount is now QR Code matrix + 2x quiet zone
 		$this->setMatrixDimensions();
 		// color the quiet zone
-		$this->colorQuietzone($quietzoneSize, $diameter / 2);
+		$this->colorQuietzone($quietzoneSize, ($diameter / 2));
 
 		// calculate the logo space
 		$logoSpaceSize = (int)ceil($this->moduleCount * $this->options->svgLogoScale);
@@ -82,10 +82,10 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
 	 * Sets random modules of the quiet zone to dark
 	 */
 	protected function colorQuietzone(int $quietzoneSize, float $radius):void{
-		$l1 = $quietzoneSize - 1;
-		$l2 = $this->moduleCount - $quietzoneSize;
+		$l1 = ($quietzoneSize - 1);
+		$l2 = ($this->moduleCount - $quietzoneSize);
 		// substract 1/2 stroke width and module radius from the circle radius to not cut off modules
-		$r  = $radius - $this->options->circleRadius * 2;
+		$r  = ($radius - $this->options->circleRadius * 2);
 
 		foreach($this->matrix->matrix() as $y => $row){
 			foreach($row as $x => $value){
@@ -107,7 +107,7 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
 
 				// we need to add 0.5 units to the check values since we're calculating the element centers
 				// ($x/$y is the element's assumed top left corner)
-				if($this->checkIfInsideCircle($x + 0.5, $y + 0.5, $r)){
+				if($this->checkIfInsideCircle(($x + 0.5), ($y + 0.5), $r)){
 					$this->matrix->set($x, $y, (bool)rand(0, 1), QRMatrix::M_QUIETZONE);
 				}
 			}
@@ -122,7 +122,7 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
 		$dx = abs($x - $this->moduleCount / 2);
 		$dy = abs($y - $this->moduleCount / 2);
 
-		if($dx + $dy <= $radius){
+		if(($dx + $dy) <= $radius){
 			return true;
 		}
 
@@ -130,7 +130,7 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
 			return false;
 		}
 
-		if(pow($dx, 2) + pow($dy, 2) <= pow($radius, 2)){
+		if((pow($dx, 2) + pow($dy, 2)) <= pow($radius, 2)){
 			return true;
 		}
 
@@ -143,9 +143,9 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
 	protected function addCircle(float $radius):string{
 		return sprintf(
 			'%4$s<circle id="circle" cx="%1$s" cy="%1$s" r="%2$s" stroke-width="%3$s"/>',
-			$this->moduleCount / 2,
+			($this->moduleCount / 2),
 			round($radius, 5),
-			$this->options->circleRadius * 2,
+			($this->options->circleRadius * 2),
 			$this->options->eol
 		);
 	}
@@ -160,7 +160,7 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
 		// @todo: customize the <g> element to your liking (css class, style...)
 		return sprintf(
 			'%5$s<g transform="translate(%1$s %1$s) scale(%2$s)" class="%3$s">%5$s	%4$s%5$s</g>',
-			($this->moduleCount - ($this->moduleCount * $this->options->svgLogoScale)) / 2,
+			(($this->moduleCount - ($this->moduleCount * $this->options->svgLogoScale)) / 2),
 			$this->options->svgLogoScale,
 			$this->options->svgLogoCssClass,
 			file_get_contents($this->options->svgLogo),
@@ -227,7 +227,7 @@ class RoundQuietzoneOptions extends QROptions{
 	 *
 	 * - a value of -1 would go through the center of the outer corner modules of the finder patterns
 	 * - a value of 0 would go through the corner of the outer modules of the finder patterns
-	 * - a value of 3 would go through the center of the module outside next to the finder patterns, in a 45 degree angle
+	 * - a value of 3 would go through the center of the module outside next to the finder patterns, in a 45-degree angle
 	 */
 	protected int $additionalModules = 0;
 
@@ -331,17 +331,17 @@ $options = new RoundQuietzoneOptions([
 	'svgDefs'             => $svgDefs,
 //	'connectPaths'        => true, // this has been set to "always on" internally
 	'excludeFromConnect'  => [
-		QRMatrix::M_FINDER|QRMatrix::IS_DARK,
-		QRMatrix::M_FINDER_DOT|QRMatrix::IS_DARK,
-		QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK,
-		QRMatrix::M_QUIETZONE|QRMatrix::IS_DARK
+		(QRMatrix::M_FINDER|QRMatrix::IS_DARK),
+		(QRMatrix::M_FINDER_DOT|QRMatrix::IS_DARK),
+		(QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK),
+		(QRMatrix::M_QUIETZONE|QRMatrix::IS_DARK),
 	],
 	'drawCircularModules' => true,
 	'circleRadius'        => 0.4,
 	'keepAsSquare'        => [
-		QRMatrix::M_FINDER|QRMatrix::IS_DARK,
-		QRMatrix::M_FINDER_DOT|QRMatrix::IS_DARK,
-		QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK,
+		(QRMatrix::M_FINDER|QRMatrix::IS_DARK),
+		(QRMatrix::M_FINDER_DOT|QRMatrix::IS_DARK),
+		(QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK),
 	],
 ]);
 

+ 4 - 4
examples/svgWithLogo.php

@@ -57,7 +57,7 @@ class QRSvgWithLogo extends QRMarkupSVG{
 		// @todo: customize the <g> element to your liking (css class, style...)
 		return sprintf(
 			'%5$s<g transform="translate(%1$s %1$s) scale(%2$s)" class="%3$s">%5$s	%4$s%5$s</g>',
-			($this->moduleCount - ($this->moduleCount * $this->options->svgLogoScale)) / 2,
+			(($this->moduleCount - ($this->moduleCount * $this->options->svgLogoScale)) / 2),
 			$this->options->svgLogoScale,
 			$this->options->svgLogoCssClass,
 			file_get_contents($this->options->svgLogo),
@@ -122,12 +122,12 @@ $options = new SVGWithLogoOptions([
 	'drawCircularModules' => true,
 	'circleRadius'        => 0.45,
 	// connect paths
-	'connectPaths'     => true,
+	'connectPaths'        => true,
 	// keep modules of thhese types as square
 	'keepAsSquare'        => [
-		QRMatrix::M_FINDER|QRMatrix::IS_DARK,
+		(QRMatrix::M_FINDER|QRMatrix::IS_DARK),
 		QRMatrix::M_FINDER_DOT,
-		QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK,
+		(QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK),
 	],
 	// https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient
 	'svgDefs'             => '

+ 5 - 5
examples/svgWithLogoAndCustomShapes.php

@@ -81,11 +81,11 @@ class QRSvgWithLogoAndCustomShapes extends QRMarkupSVG{
 
 		$qz  = $this->options->addQuietzone ? $this->options->quietzoneSize : 0;
 		// the positions for the finder patterns (top left corner)
-		// $this->moduleCount includes 2* the quiet zone size already so we need to take this into account
+		// $this->moduleCount includes 2* the quiet zone size already, so we need to take this into account
 		$pos = [
-			[0 + $qz, 0 + $qz],
-			[0 + $qz, $this->moduleCount - $qz - 7],
-			[$this->moduleCount - $qz - 7, 0 + $qz],
+			[(0 + $qz), (0 + $qz)],
+			[(0 + $qz), ($this->moduleCount - $qz - 7)],
+			[($this->moduleCount - $qz - 7), (0 + $qz)],
 		];
 
 		// the custom path for one finder pattern - the first move (M) is parametrized, the rest are relative coordinates
@@ -111,7 +111,7 @@ class QRSvgWithLogoAndCustomShapes extends QRMarkupSVG{
 		// @todo: customize the <g> element to your liking (css class, style...)
 		return sprintf(
 			'%5$s<g transform="translate(%1$s %1$s) scale(%2$s)" class="%3$s">%5$s	%4$s%5$s</g>',
-			($this->moduleCount - ($this->moduleCount * $this->options->svgLogoScale)) / 2,
+			(($this->moduleCount - ($this->moduleCount * $this->options->svgLogoScale)) / 2),
 			$this->options->svgLogoScale,
 			$this->options->svgLogoCssClass,
 			file_get_contents($this->options->svgLogo),

+ 20 - 20
examples/text.php

@@ -23,37 +23,37 @@ $options = new QROptions([
 	'eol'          => Color::colorize('reset', "\x00\n"),
 	'moduleValues' => [
 		// finder
-		QRMatrix::M_FINDER | QRMatrix::IS_DARK     => Color::colorize('fg-black', '🔴'), // dark (true)
-		QRMatrix::M_FINDER                         => Color::colorize('fg-black', '⭕'), // light (false)
-		QRMatrix::M_FINDER_DOT | QRMatrix::IS_DARK => Color::colorize('fg-black', '🔴'), // finder dot, dark (true)
+		(QRMatrix::M_FINDER | QRMatrix::IS_DARK)     => Color::colorize('fg-black', '🔴'), // dark (true)
+		QRMatrix::M_FINDER                           => Color::colorize('fg-black', '⭕'), // light (false)
+		(QRMatrix::M_FINDER_DOT | QRMatrix::IS_DARK) => Color::colorize('fg-black', '🔴'), // finder dot, dark (true)
 		// alignment
-		QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK  => Color::colorize('fg-blue', '🔴'),
-		QRMatrix::M_ALIGNMENT                      => Color::colorize('fg-blue', '⭕'),
+		(QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK)  => Color::colorize('fg-blue', '🔴'),
+		QRMatrix::M_ALIGNMENT                        => Color::colorize('fg-blue', '⭕'),
 		// timing
-		QRMatrix::M_TIMING | QRMatrix::IS_DARK     => Color::colorize('fg-red', '🔴'),
-		QRMatrix::M_TIMING                         => Color::colorize('fg-red', '⭕'),
+		(QRMatrix::M_TIMING | QRMatrix::IS_DARK)     => Color::colorize('fg-red', '🔴'),
+		QRMatrix::M_TIMING                           => Color::colorize('fg-red', '⭕'),
 		// format
-		QRMatrix::M_FORMAT | QRMatrix::IS_DARK     => Color::colorize('fg-magenta', '🔴'),
-		QRMatrix::M_FORMAT                         => Color::colorize('fg-magenta', '⭕'),
+		(QRMatrix::M_FORMAT | QRMatrix::IS_DARK)     => Color::colorize('fg-magenta', '🔴'),
+		QRMatrix::M_FORMAT                           => Color::colorize('fg-magenta', '⭕'),
 		// version
-		QRMatrix::M_VERSION | QRMatrix::IS_DARK    => Color::colorize('fg-green', '🔴'),
-		QRMatrix::M_VERSION                        => Color::colorize('fg-green', '⭕'),
+		(QRMatrix::M_VERSION | QRMatrix::IS_DARK)    => Color::colorize('fg-green', '🔴'),
+		QRMatrix::M_VERSION                          => Color::colorize('fg-green', '⭕'),
 		// data
-		QRMatrix::M_DATA | QRMatrix::IS_DARK       => Color::colorize('fg-white', '🔴'),
-		QRMatrix::M_DATA                           => Color::colorize('fg-white', '⭕'),
+		(QRMatrix::M_DATA | QRMatrix::IS_DARK)       => Color::colorize('fg-white', '🔴'),
+		QRMatrix::M_DATA                             => Color::colorize('fg-white', '⭕'),
 		// darkmodule
-		QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK => Color::colorize('fg-black', '🔴'),
+		(QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK) => Color::colorize('fg-black', '🔴'),
 		// separator
-		QRMatrix::M_SEPARATOR                      => Color::colorize('fg-cyan', '⭕'),
+		QRMatrix::M_SEPARATOR                        => Color::colorize('fg-cyan', '⭕'),
 		// quietzone
-		QRMatrix::M_QUIETZONE                      => Color::colorize('fg-cyan', '⭕'),
+		QRMatrix::M_QUIETZONE                        => Color::colorize('fg-cyan', '⭕'),
 		// logo space
-		QRMatrix::M_LOGO                           => Color::colorize('fg-yellow', '⭕'),
+		QRMatrix::M_LOGO                             => Color::colorize('fg-yellow', '⭕'),
 		// empty
-		QRMatrix::M_NULL                           => Color::colorize('fg-black', '⭕'),
+		QRMatrix::M_NULL                             => Color::colorize('fg-black', '⭕'),
 		// data
-		QRMatrix::M_TEST | QRMatrix::IS_DARK       => Color::colorize('fg-white', '🔴'),
-		QRMatrix::M_TEST                           => Color::colorize('fg-black', '⭕'),
+		(QRMatrix::M_TEST | QRMatrix::IS_DARK)       => Color::colorize('fg-white', '🔴'),
+		QRMatrix::M_TEST                             => Color::colorize('fg-black', '⭕'),
 	],
 ]);
 

+ 10 - 10
src/Common/BitBuffer.php

@@ -46,7 +46,7 @@ final class BitBuffer{
 	 * @param int[]|null $bytes
 	 */
 	public function __construct(array $bytes = null){
-		$this->buffer = $bytes ?? [];
+		$this->buffer = ($bytes ?? []);
 		$this->length = count($this->buffer);
 	}
 
@@ -99,7 +99,7 @@ final class BitBuffer{
 	 * @return int number of bits that can be read successfully
 	 */
 	public function available():int{
-		return 8 * ($this->length - $this->bytesRead) - $this->bitsRead;
+		return ((8 * ($this->length - $this->bytesRead)) - $this->bitsRead);
 	}
 
 	/**
@@ -120,11 +120,11 @@ final class BitBuffer{
 
 		// First, read remainder from current byte
 		if($this->bitsRead > 0){
-			$bitsLeft       = 8 - $this->bitsRead;
+			$bitsLeft       = (8 - $this->bitsRead);
 			$toRead         = min($numBits, $bitsLeft);
-			$bitsToNotRead  = $bitsLeft - $toRead;
-			$mask           = (0xff >> (8 - $toRead)) << $bitsToNotRead;
-			$result         = ($this->buffer[$this->bytesRead] & $mask) >> $bitsToNotRead;
+			$bitsToNotRead  = ($bitsLeft - $toRead);
+			$mask           = ((0xff >> (8 - $toRead)) << $bitsToNotRead);
+			$result         = (($this->buffer[$this->bytesRead] & $mask) >> $bitsToNotRead);
 			$numBits        -= $toRead;
 			$this->bitsRead += $toRead;
 
@@ -138,16 +138,16 @@ final class BitBuffer{
 		if($numBits > 0){
 
 			while($numBits >= 8){
-				$result = ($result << 8) | ($this->buffer[$this->bytesRead] & 0xff);
+				$result = (($result << 8) | ($this->buffer[$this->bytesRead] & 0xff));
 				$this->bytesRead++;
 				$numBits -= 8;
 			}
 
 			// Finally read a partial byte
 			if($numBits > 0){
-				$bitsToNotRead  = 8 - $numBits;
-				$mask           = (0xff >> $bitsToNotRead) << $bitsToNotRead;
-				$result         = ($result << $numBits) | (($this->buffer[$this->bytesRead] & $mask) >> $bitsToNotRead);
+				$bitsToNotRead  = (8 - $numBits);
+				$mask           = ((0xff >> $bitsToNotRead) << $bitsToNotRead);
+				$result         = (($result << $numBits) | (($this->buffer[$this->bytesRead] & $mask) >> $bitsToNotRead));
 				$this->bitsRead += $numBits;
 			}
 		}

+ 2 - 2
src/Common/GF256.php

@@ -79,7 +79,7 @@ final class GF256{
 	 * @return int sum/difference of a and b
 	 */
 	public static function addOrSubtract(int $a, int $b):int{
-		return $a ^ $b;
+		return ($a ^ $b);
 	}
 
 	/**
@@ -92,7 +92,7 @@ final class GF256{
 			throw new QRCodeException('degree < 0');
 		}
 
-		$coefficients    = array_fill(0, $degree + 1, 0);
+		$coefficients    = array_fill(0, ($degree + 1), 0);
 		$coefficients[0] = $coefficient;
 
 		return new GenericGFPoly($coefficients);

+ 18 - 18
src/Common/GenericGFPoly.php

@@ -56,23 +56,23 @@ final class GenericGFPoly{
 			$firstNonZero++;
 		}
 
-		if($firstNonZero === $coefficientsLength){
-			$this->coefficients = [0];
-		}
-		else{
-			$this->coefficients = array_fill(0, $coefficientsLength - $firstNonZero + $degree, 0);
+		$this->coefficients = [0];
+
+		if($firstNonZero !== $coefficientsLength){
+			$this->coefficients = array_fill(0, ($coefficientsLength - $firstNonZero + $degree), 0);
 
-			for($i = 0; $i < $coefficientsLength - $firstNonZero; $i++){
-				$this->coefficients[$i] = $coefficients[$i + $firstNonZero];
+			for($i = 0; $i < ($coefficientsLength - $firstNonZero); $i++){
+				$this->coefficients[$i] = $coefficients[($i + $firstNonZero)];
 			}
 		}
+
 	}
 
 	/**
 	 * @return int $coefficient of x^degree term in this polynomial
 	 */
 	public function getCoefficient(int $degree):int{
-		return $this->coefficients[count($this->coefficients) - 1 - $degree];
+		return $this->coefficients[(count($this->coefficients) - 1 - $degree)];
 	}
 
 	/**
@@ -86,7 +86,7 @@ final class GenericGFPoly{
 	 * @return int $degree of this polynomial
 	 */
 	public function getDegree():int{
-		return count($this->coefficients) - 1;
+		return (count($this->coefficients) - 1);
 	}
 
 	/**
@@ -110,7 +110,7 @@ final class GenericGFPoly{
 
 		foreach($this->coefficients as $c){
 			// if $a === 1 just the sum of the coefficients
-			$result = GF256::addOrSubtract(($a === 1 ? $result : GF256::multiply($a, $result)), $c);
+			$result = GF256::addOrSubtract((($a === 1) ? $result : GF256::multiply($a, $result)), $c);
 		}
 
 		return $result;
@@ -125,11 +125,11 @@ final class GenericGFPoly{
 			return new self([0]);
 		}
 
-		$product = array_fill(0, count($this->coefficients) + count($other->coefficients) - 1, 0);
+		$product = array_fill(0, (count($this->coefficients) + count($other->coefficients) - 1), 0);
 
 		foreach($this->coefficients as $i => $aCoeff){
 			foreach($other->coefficients as $j => $bCoeff){
-				$product[$i + $j] ^= GF256::multiply($aCoeff, $bCoeff);
+				$product[($i + $j)] ^= GF256::multiply($aCoeff, $bCoeff);
 			}
 		}
 
@@ -154,7 +154,7 @@ final class GenericGFPoly{
 
 		while($remainder->getDegree() >= $other->getDegree() && !$remainder->isZero()){
 			$scale     = GF256::multiply($remainder->getCoefficient($remainder->getDegree()), $inverseDenominatorLeadingTerm);
-			$diff      = $remainder->getDegree() - $other->getDegree();
+			$diff      = ($remainder->getDegree() - $other->getDegree());
 			$quotient  = $quotient->addOrSubtract(GF256::buildMonomial($diff, $scale));
 			$remainder = $remainder->addOrSubtract($other->multiplyByMonomial($diff, $scale));
 		}
@@ -198,7 +198,7 @@ final class GenericGFPoly{
 			return new self([0]);
 		}
 
-		$product = array_fill(0, count($this->coefficients) + $degree, 0);
+		$product = array_fill(0, (count($this->coefficients) + $degree), 0);
 
 		foreach($this->coefficients as $i => $c){
 			$product[$i] = GF256::multiply($c, $coefficient);
@@ -212,11 +212,11 @@ final class GenericGFPoly{
 	 */
 	public function mod(GenericGFPoly $other):self{
 
-		if(count($this->coefficients) - count($other->coefficients) < 0){
+		if((count($this->coefficients) - count($other->coefficients)) < 0){
 			return $this;
 		}
 
-		$ratio = GF256::log($this->coefficients[0]) - GF256::log($other->coefficients[0]);
+		$ratio = (GF256::log($this->coefficients[0]) - GF256::log($other->coefficients[0]));
 
 		foreach($other->coefficients as $i => $c){
 			$this->coefficients[$i] ^= GF256::exp(GF256::log($c) + $ratio);
@@ -248,14 +248,14 @@ final class GenericGFPoly{
 		}
 
 		$sumDiff    = array_fill(0, count($largerCoefficients), 0);
-		$lengthDiff = count($largerCoefficients) - count($smallerCoefficients);
+		$lengthDiff = (count($largerCoefficients) - count($smallerCoefficients));
 		// Copy high-order terms only found in higher-degree polynomial's coefficients
 		array_splice($sumDiff, 0, $lengthDiff, array_slice($largerCoefficients, 0, $lengthDiff));
 
 		$countLargerCoefficients = count($largerCoefficients);
 
 		for($i = $lengthDiff; $i < $countLargerCoefficients; $i++){
-			$sumDiff[$i] = GF256::addOrSubtract($smallerCoefficients[$i - $lengthDiff], $largerCoefficients[$i]);
+			$sumDiff[$i] = GF256::addOrSubtract($smallerCoefficients[($i - $lengthDiff)], $largerCoefficients[$i]);
 		}
 
 		return new self($sumDiff);

+ 34 - 34
src/Common/MaskPattern.php

@@ -103,7 +103,7 @@ final class MaskPattern{
 			self::PATTERN_010 => fn(int $x, int $y):bool => ($x % 3) === 0,
 			self::PATTERN_011 => fn(int $x, int $y):bool => (($x + $y) % 3) === 0,
 			self::PATTERN_100 => fn(int $x, int $y):bool => (((int)($y / 2) + (int)($x / 3)) % 2) === 0,
-			self::PATTERN_101 => fn(int $x, int $y):bool => ($x * $y) % 6 === 0, // ((($x * $y) % 2) + (($x * $y) % 3)) === 0,
+			self::PATTERN_101 => fn(int $x, int $y):bool => (($x * $y) % 6) === 0, // ((($x * $y) % 2) + (($x * $y) % 3)) === 0,
 			self::PATTERN_110 => fn(int $x, int $y):bool => (($x * $y) % 6) < 3, // (((($x * $y) % 2) + (($x * $y) % 3)) % 2) === 0,
 			self::PATTERN_111 => fn(int $x, int $y):bool => (($x + $y + (($x * $y) % 3)) % 2) === 0, // (((($x * $y) % 3) + (($x + $y) % 2)) % 2) === 0,
 		][$this->maskPattern];
@@ -134,7 +134,7 @@ final class MaskPattern{
 	 * give penalty to them. Example: 00000 or 11111.
 	 */
 	public static function testRule1(array $matrix, int $height, int $width):int{
-		return self::applyRule1($matrix, $height, $width, true) + self::applyRule1($matrix, $height, $width, false);
+		return (self::applyRule1($matrix, $height, $width, true) + self::applyRule1($matrix, $height, $width, false));
 	}
 
 	/**
@@ -142,15 +142,15 @@ final class MaskPattern{
 	 */
 	private static function applyRule1(array $matrix, int $height, int $width, bool $isHorizontal):int{
 		$penalty = 0;
-		$yLimit  = $isHorizontal ? $height : $width;
-		$xLimit  = $isHorizontal ? $width : $height;
+		$yLimit  = ($isHorizontal) ? $height : $width;
+		$xLimit  = ($isHorizontal) ? $width : $height;
 
 		for($y = 0; $y < $yLimit; $y++){
 			$numSameBitCells = 0;
 			$prevBit         = null;
 
 			for($x = 0; $x < $xLimit; $x++){
-				$bit = $isHorizontal ? $matrix[$y][$x] : $matrix[$x][$y];
+				$bit = ($isHorizontal) ? $matrix[$y][$x] : $matrix[$x][$y];
 
 				if($bit === $prevBit){
 					$numSameBitCells++;
@@ -158,7 +158,7 @@ final class MaskPattern{
 				else{
 
 					if($numSameBitCells >= 5){
-						$penalty += 3 + ($numSameBitCells - 5);
+						$penalty += (3 + ($numSameBitCells - 5));
 					}
 
 					$numSameBitCells = 1;  // Include the cell itself.
@@ -166,7 +166,7 @@ final class MaskPattern{
 				}
 			}
 			if($numSameBitCells >= 5){
-				$penalty += 3 + ($numSameBitCells - 5);
+				$penalty += (3 + ($numSameBitCells - 5));
 			}
 		}
 
@@ -183,27 +183,27 @@ final class MaskPattern{
 
 		foreach($matrix as $y => $row){
 
-			if($y > $height - 2){
+			if($y > ($height - 2)){
 				break;
 			}
 
 			foreach($row as $x => $val){
 
-				if($x > $width - 2){
+				if($x > ($width - 2)){
 					break;
 				}
 
 				if(
-					$val === $row[$x + 1]
-					&& $val === $matrix[$y + 1][$x]
-					&& $val === $matrix[$y + 1][$x + 1]
+					$val === $row[($x + 1)]
+					&& $val === $matrix[($y + 1)][$x]
+					&& $val === $matrix[($y + 1)][($x + 1)]
 				){
 					$penalty++;
 				}
 			}
 		}
 
-		return 3 * $penalty;
+		return (3 * $penalty);
 	}
 
 	/**
@@ -218,34 +218,34 @@ final class MaskPattern{
 			foreach($row as $x => $val){
 
 				if(
-					$x + 6 < $width
+					($x + 6) < $width
 					&&  $val
-					&& !$row[$x + 1]
-					&&  $row[$x + 2]
-					&&  $row[$x + 3]
-					&&  $row[$x + 4]
-					&& !$row[$x + 5]
-					&&  $row[$x + 6]
+					&& !$row[($x + 1)]
+					&&  $row[($x + 2)]
+					&&  $row[($x + 3)]
+					&&  $row[($x + 4)]
+					&& !$row[($x + 5)]
+					&&  $row[($x + 6)]
 					&& (
-						   self::isWhiteHorizontal($row, $width, $x - 4, $x)
-						|| self::isWhiteHorizontal($row, $width, $x + 7, $x + 11)
+						   self::isWhiteHorizontal($row, $width, ($x - 4), $x)
+						|| self::isWhiteHorizontal($row, $width, ($x + 7), ($x + 11))
 					)
 				){
 					$penalties++;
 				}
 
 				if(
-					$y + 6 < $height
+					($y + 6) < $height
 					&&  $val
-					&& !$matrix[$y + 1][$x]
-					&&  $matrix[$y + 2][$x]
-					&&  $matrix[$y + 3][$x]
-					&&  $matrix[$y + 4][$x]
-					&& !$matrix[$y + 5][$x]
-					&&  $matrix[$y + 6][$x]
+					&& !$matrix[($y + 1)][$x]
+					&&  $matrix[($y + 2)][$x]
+					&&  $matrix[($y + 3)][$x]
+					&&  $matrix[($y + 4)][$x]
+					&& !$matrix[($y + 5)][$x]
+					&&  $matrix[($y + 6)][$x]
 					&& (
-						   self::isWhiteVertical($matrix, $height, $x, $y - 4, $y)
-						|| self::isWhiteVertical($matrix, $height, $x, $y + 7, $y + 11)
+						   self::isWhiteVertical($matrix, $height, $x, ($y - 4), $y)
+						|| self::isWhiteVertical($matrix, $height, $x, ($y + 7), ($y + 11))
 					)
 				){
 					$penalties++;
@@ -254,7 +254,7 @@ final class MaskPattern{
 			}
 		}
 
-		return $penalties * 40;
+		return ($penalties * 40);
 	}
 
 	/**
@@ -299,7 +299,7 @@ final class MaskPattern{
 	 */
 	public static function testRule4(array $matrix, int $height, int $width):int{
 		$darkCells  = 0;
-		$totalCells = $height * $width;
+		$totalCells = ($height * $width);
 
 		foreach($matrix as $row){
 			foreach($row as $val){
@@ -309,7 +309,7 @@ final class MaskPattern{
 			}
 		}
 
-		return (int)(abs($darkCells * 2 - $totalCells) * 10 / $totalCells) * 10;
+		return ((int)(abs($darkCells * 2 - $totalCells) * 10 / $totalCells) * 10);
 	}
 
 }

+ 10 - 10
src/Common/ReedSolomonDecoder.php

@@ -85,7 +85,7 @@ final class ReedSolomonDecoder{
 			[$numEccBlocks, $eccPerBlock] = $blockData;
 
 			for($i = 0; $i < $numEccBlocks; $i++, $numResultBlocks++){
-				$result[$numResultBlocks] = [$eccPerBlock, array_fill(0, $numEccCodewords + $eccPerBlock, 0)];
+				$result[$numResultBlocks] = [$eccPerBlock, array_fill(0, ($numEccCodewords + $eccPerBlock), 0)];
 			}
 		}
 
@@ -93,7 +93,7 @@ final class ReedSolomonDecoder{
 		// (where n may be 0) have 1 more byte. Figure out where these start.
 		/** @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset */
 		$shorterBlocksTotalCodewords = count($result[0][1]);
-		$longerBlocksStartAt         = count($result) - 1;
+		$longerBlocksStartAt         = (count($result) - 1);
 
 		while($longerBlocksStartAt >= 0){
 			$numCodewords = count($result[$longerBlocksStartAt][1]);
@@ -107,7 +107,7 @@ final class ReedSolomonDecoder{
 
 		$longerBlocksStartAt++;
 
-		$shorterBlocksNumDataCodewords = $shorterBlocksTotalCodewords - $numEccCodewords;
+		$shorterBlocksNumDataCodewords = ($shorterBlocksTotalCodewords - $numEccCodewords);
 		// The last elements of result may be 1 element longer;
 		// first fill out as many elements as all of them have
 		$rawCodewordsOffset = 0;
@@ -129,7 +129,7 @@ final class ReedSolomonDecoder{
 
 		for($i = $shorterBlocksNumDataCodewords; $i < $max; $i++){
 			for($j = 0; $j < $numResultBlocks; $j++){
-				$iOffset                 = $j < $longerBlocksStartAt ? $i : $i + 1;
+				$iOffset                 = ($j < $longerBlocksStartAt) ? $i : ($i + 1);
 				$result[$j][1][$iOffset] = $rawCodewords[$rawCodewordsOffset++];
 			}
 		}
@@ -147,7 +147,7 @@ final class ReedSolomonDecoder{
 		$codewordsInts = [];
 
 		foreach($codewordBytes as $codewordByte){
-			$codewordsInts[] = $codewordByte & 0xFF;
+			$codewordsInts[] = ($codewordByte & 0xFF);
 		}
 
 		$decoded = $this->decodeWords($codewordsInts, (count($codewordBytes) - $numDataCodewords));
@@ -201,7 +201,7 @@ final class ReedSolomonDecoder{
 		$receivedCount       = count($received);
 
 		for($i = 0; $i < $errorLocationsCount; $i++){
-			$position = $receivedCount - 1 - GF256::log($errorLocations[$i]);
+			$position = ($receivedCount - 1 - GF256::log($errorLocations[$i]));
 
 			if($position < 0){
 				throw new QRCodeException('Bad error location');
@@ -217,7 +217,7 @@ final class ReedSolomonDecoder{
 	 * @return \chillerlan\QRCode\Common\GenericGFPoly[] [sigma, omega]
 	 * @throws \chillerlan\QRCode\QRCodeException
 	 */
-	private function runEuclideanAlgorithm(GenericGFPoly $a, GenericGFPoly $b, int $R):array{
+	private function runEuclideanAlgorithm(GenericGFPoly $a, GenericGFPoly $b, int $z):array{
 		// Assume a's degree is >= b's
 		if($a->getDegree() < $b->getDegree()){
 			$temp = $a;
@@ -230,8 +230,8 @@ final class ReedSolomonDecoder{
 		$tLast = new GenericGFPoly([0]);
 		$t     = new GenericGFPoly([1]);
 
-		// Run Euclidean algorithm until r's degree is less than R/2
-		while(2 * $r->getDegree() >= $R){
+		// Run Euclidean algorithm until r's degree is less than z/2
+		while((2 * $r->getDegree()) >= $z){
 			$rLastLast = $rLast;
 			$tLastLast = $tLast;
 			$rLast     = $r;
@@ -304,7 +304,7 @@ final class ReedSolomonDecoder{
 					// Above should work but fails on some Apple and Linux JDKs due to a Hotspot bug.
 					// Below is a funny-looking workaround from Steven Parkes
 					$term        = GF256::multiply($errorLocations[$j], $xiInverse);
-					$denominator = GF256::multiply($denominator, (($term & 0x1) === 0 ? $term | 1 : $term & ~1));
+					$denominator = GF256::multiply($denominator, ((($term & 0x1) === 0) ? ($term | 1) : ($term & ~1)));
 				}
 			}
 

+ 8 - 8
src/Common/ReedSolomonEncoder.php

@@ -41,10 +41,10 @@ final class ReedSolomonEncoder{
 	public function interleaveEcBytes(BitBuffer $bitBuffer):array{
 		[$numEccCodewords, [[$l1, $b1], [$l2, $b2]]] = $this->version->getRSBlocks($this->eccLevel);
 
-		$rsBlocks = array_fill(0, $l1, [$numEccCodewords + $b1, $b1]);
+		$rsBlocks = array_fill(0, $l1, [($numEccCodewords + $b1), $b1]);
 
 		if($l2 > 0){
-			$rsBlocks = array_merge($rsBlocks, array_fill(0, $l2, [$numEccCodewords + $b2, $b2]));
+			$rsBlocks = array_merge($rsBlocks, array_fill(0, $l2, [($numEccCodewords + $b2), $b2]));
 		}
 
 		$bitBufferData  = $bitBuffer->getBuffer();
@@ -60,10 +60,10 @@ final class ReedSolomonEncoder{
 			$dataBytes[$key] = [];
 
 			for($i = 0; $i < $dataByteCount; $i++){
-				$dataBytes[$key][$i] = $bitBufferData[$i + $dataByteOffset] & 0xff;
+				$dataBytes[$key][$i] = ($bitBufferData[($i + $dataByteOffset)] & 0xff);
 			}
 
-			$ecByteCount    = $rsBlockTotal - $dataByteCount;
+			$ecByteCount    = ($rsBlockTotal - $dataByteCount);
 			$ecBytes[$key]  = $this->encode($dataBytes[$key], $ecByteCount);
 			$maxDataBytes   = max($maxDataBytes, $dataByteCount);
 			$maxEcBytes     = max($maxEcBytes, $ecByteCount);
@@ -72,7 +72,7 @@ final class ReedSolomonEncoder{
 
 		$this->interleavedData      = array_fill(0, $this->version->getTotalCodewords(), 0);
 		$this->interleavedDataIndex = 0;
-		$numRsBlocks                = $l1 + $l2;
+		$numRsBlocks                = ($l1 + $l2);
 
 		$this->interleave($dataBytes, $maxDataBytes, $numRsBlocks);
 		$this->interleave($ecBytes, $maxEcBytes, $numRsBlocks);
@@ -98,11 +98,11 @@ final class ReedSolomonEncoder{
 		;
 
 		$ecBytes = array_fill(0, $rsPolyDegree, 0);
-		$count   = count($modCoefficients) - $rsPolyDegree;
+		$count   = (count($modCoefficients) - $rsPolyDegree);
 
 		foreach($ecBytes as $i => &$val){
-			$modIndex = $i + $count;
-			$val      = $modIndex >= 0 ? $modCoefficients[$modIndex] : 0;
+			$modIndex = ($i + $count);
+			$val      = ($modIndex >= 0) ? $modCoefficients[$modIndex] : 0;
 		}
 
 		return $ecBytes;

+ 2 - 2
src/Common/Version.php

@@ -251,14 +251,14 @@ final class Version{
 	 * the matrix size for the given version
 	 */
 	public function getDimension():int{
-		return $this->version * 4 + 17;
+		return (($this->version * 4) + 17);
 	}
 
 	/**
 	 * the version pattern for the given version
 	 */
 	public function getVersionPattern():?int{
-		return self::VERSION_PATTERN[$this->version] ?? null;
+		return (self::VERSION_PATTERN[$this->version] ?? null);
 	}
 
 	/**

+ 2 - 2
src/Data/Byte.php

@@ -31,7 +31,7 @@ final class Byte extends QRDataModeAbstract{
 	 * @inheritDoc
 	 */
 	public function getLengthInBits():int{
-		return $this->getCharCount() * 8;
+		return ($this->getCharCount() * 8);
 	}
 
 	/**
@@ -69,7 +69,7 @@ final class Byte extends QRDataModeAbstract{
 	public static function decodeSegment(BitBuffer $bitBuffer, int $versionNumber):string{
 		$length = $bitBuffer->read(self::getLengthBits($versionNumber));
 
-		if($bitBuffer->available() < 8 * $length){
+		if($bitBuffer->available() < (8 * $length)){
 			throw new QRCodeDataException('not enough bits available'); // @codeCoverageIgnore
 		}
 

+ 19 - 13
src/Data/Hanzi.php

@@ -50,7 +50,7 @@ final class Hanzi extends QRDataModeAbstract{
 	 * @inheritDoc
 	 */
 	public function getLengthInBits():int{
-		return $this->getCharCount() * 13;
+		return ($this->getCharCount() * 13);
 	}
 
 	/**
@@ -92,13 +92,13 @@ final class Hanzi extends QRDataModeAbstract{
 
 		$len = strlen($string);
 
-		if($len < 2 || $len % 2 !== 0){
+		if($len < 2 || ($len % 2) !== 0){
 			return false;
 		}
 
 		for($i = 0; $i < $len; $i += 2){
 			$byte1 = ord($string[$i]);
-			$byte2 = ord($string[$i + 1]);
+			$byte2 = ord($string[($i + 1)]);
 
 			// byte 1 unused ranges
 			if($byte1 < 0xa1 || ($byte1 > 0xa9 && $byte1 < 0xb0) || $byte1 > 0xf7){
@@ -130,8 +130,8 @@ final class Hanzi extends QRDataModeAbstract{
 
 		$len = strlen($this->data);
 
-		for($i = 0; $i + 1 < $len; $i += 2){
-			$c = ((0xff & ord($this->data[$i])) << 8) | (0xff & ord($this->data[$i + 1]));
+		for($i = 0; ($i + 1) < $len; $i += 2){
+			$c = (((0xff & ord($this->data[$i])) << 8) | (0xff & ord($this->data[($i + 1)])));
 
 			if($c >= 0xa1a1 && $c <= 0xaafe){
 				$c -= 0x0a1a1;
@@ -140,14 +140,14 @@ final class Hanzi extends QRDataModeAbstract{
 				$c -= 0x0a6a1;
 			}
 			else{
-				throw new QRCodeDataException(sprintf('illegal char at %d [%d]', $i + 1, $c));
+				throw new QRCodeDataException(sprintf('illegal char at %d [%d]', ($i + 1), $c));
 			}
 
-			$bitBuffer->put(((($c >> 8) & 0xff) * 0x060) + ($c & 0xff), 13);
+			$bitBuffer->put((((($c >> 8) & 0xff) * 0x060) + ($c & 0xff)), 13);
 		}
 
 		if($i < $len){
-			throw new QRCodeDataException(sprintf('illegal char at %d', $i + 1));
+			throw new QRCodeDataException(sprintf('illegal char at %d', ($i + 1)));
 		}
 
 	}
@@ -158,9 +158,15 @@ final class Hanzi extends QRDataModeAbstract{
 	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
 	 */
 	public static function decodeSegment(BitBuffer $bitBuffer, int $versionNumber):string{
+
+		// Hanzi mode contains a subset indicator right after mode indicator
+		if($bitBuffer->read(4) !== self::GB2312_SUBSET){
+			throw new QRCodeDataException('ecpected subset indicator for Hanzi mode');
+		}
+
 		$length = $bitBuffer->read(self::getLengthBits($versionNumber));
 
-		if($bitBuffer->available() < $length * 13){
+		if($bitBuffer->available() < ($length * 13)){
 			throw new QRCodeDataException('not enough bits available');
 		}
 
@@ -171,15 +177,15 @@ final class Hanzi extends QRDataModeAbstract{
 		while($length > 0){
 			// Each 13 bits encodes a 2-byte character
 			$twoBytes          = $bitBuffer->read(13);
-			$assembledTwoBytes = (((int)($twoBytes / 0x060)) << 8) | ($twoBytes % 0x060);
+			$assembledTwoBytes = ((((int)($twoBytes / 0x060)) << 8) | ($twoBytes % 0x060));
 
 			$assembledTwoBytes += ($assembledTwoBytes < 0x00a00) // 0x003BF
 				? 0x0a1a1  // In the 0xA1A1 to 0xAAFE range
 				: 0x0a6a1; // In the 0xB0A1 to 0xFAFE range
 
-			$buffer[$offset]     = chr(0xff & ($assembledTwoBytes >> 8));
-			$buffer[$offset + 1] = chr(0xff & $assembledTwoBytes);
-			$offset              += 2;
+			$buffer[$offset]       = chr(0xff & ($assembledTwoBytes >> 8));
+			$buffer[($offset + 1)] = chr(0xff & $assembledTwoBytes);
+			$offset                += 2;
 			$length--;
 		}
 

+ 13 - 13
src/Data/Kanji.php

@@ -48,7 +48,7 @@ final class Kanji extends QRDataModeAbstract{
 	 * @inheritDoc
 	 */
 	public function getLengthInBits():int{
-		return $this->getCharCount() * 13;
+		return ($this->getCharCount() * 13);
 	}
 
 	/**
@@ -90,13 +90,13 @@ final class Kanji extends QRDataModeAbstract{
 
 		$len = strlen($string);
 
-		if($len < 2 || $len % 2 !== 0){
+		if($len < 2 || ($len % 2) !== 0){
 			return false;
 		}
 
 		for($i = 0; $i < $len; $i += 2){
 			$byte1 = ord($string[$i]);
-			$byte2 = ord($string[$i + 1]);
+			$byte2 = ord($string[($i + 1)]);
 
 			// byte 1 unused and vendor ranges
 			if($byte1 < 0x81 || ($byte1 > 0x84 && $byte1 < 0x88) || ($byte1 > 0x9f && $byte1 < 0xe0) ||  $byte1 > 0xea){
@@ -127,8 +127,8 @@ final class Kanji extends QRDataModeAbstract{
 
 		$len = strlen($this->data);
 
-		for($i = 0; $i + 1 < $len; $i += 2){
-			$c = ((0xff & ord($this->data[$i])) << 8) | (0xff & ord($this->data[$i + 1]));
+		for($i = 0; ($i + 1) < $len; $i += 2){
+			$c = (((0xff & ord($this->data[$i])) << 8) | (0xff & ord($this->data[($i + 1)])));
 
 			if($c >= 0x8140 && $c <= 0x9ffc){
 				$c -= 0x8140;
@@ -137,14 +137,14 @@ final class Kanji extends QRDataModeAbstract{
 				$c -= 0xc140;
 			}
 			else{
-				throw new QRCodeDataException(sprintf('illegal char at %d [%d]', $i + 1, $c));
+				throw new QRCodeDataException(sprintf('illegal char at %d [%d]', ($i + 1), $c));
 			}
 
-			$bitBuffer->put(((($c >> 8) & 0xff) * 0xc0) + ($c & 0xff), 13);
+			$bitBuffer->put((((($c >> 8) & 0xff) * 0xc0) + ($c & 0xff)), 13);
 		}
 
 		if($i < $len){
-			throw new QRCodeDataException(sprintf('illegal char at %d', $i + 1));
+			throw new QRCodeDataException(sprintf('illegal char at %d', ($i + 1)));
 		}
 
 	}
@@ -157,7 +157,7 @@ final class Kanji extends QRDataModeAbstract{
 	public static function decodeSegment(BitBuffer $bitBuffer, int $versionNumber):string{
 		$length = $bitBuffer->read(self::getLengthBits($versionNumber));
 
-		if($bitBuffer->available() < $length * 13){
+		if($bitBuffer->available() < ($length * 13)){
 			throw new QRCodeDataException('not enough bits available');  // @codeCoverageIgnore
 		}
 
@@ -168,15 +168,15 @@ final class Kanji extends QRDataModeAbstract{
 		while($length > 0){
 			// Each 13 bits encodes a 2-byte character
 			$twoBytes          = $bitBuffer->read(13);
-			$assembledTwoBytes = (((int)($twoBytes / 0x0c0)) << 8) | ($twoBytes % 0x0c0);
+			$assembledTwoBytes = ((((int)($twoBytes / 0x0c0)) << 8) | ($twoBytes % 0x0c0));
 
 			$assembledTwoBytes += ($assembledTwoBytes < 0x01f00)
 				? 0x08140  // In the 0x8140 to 0x9FFC range
 				: 0x0c140; // In the 0xE040 to 0xEBBF range
 
-			$buffer[$offset]     = chr(0xff & ($assembledTwoBytes >> 8));
-			$buffer[$offset + 1] = chr(0xff & $assembledTwoBytes);
-			$offset              += 2;
+			$buffer[$offset]       = chr(0xff & ($assembledTwoBytes >> 8));
+			$buffer[($offset + 1)] = chr(0xff & $assembledTwoBytes);
+			$offset                += 2;
 			$length--;
 		}
 

+ 4 - 4
src/Data/Number.php

@@ -73,7 +73,7 @@ final class Number extends QRDataModeAbstract{
 		$i = 0;
 
 		// encode numeric triplets in 10 bits
-		while($i + 2 < $len){
+		while(($i + 2) < $len){
 			$bitBuffer->put($this->parseInt(substr($this->data, $i, 3)), 10);
 			$i += 3;
 		}
@@ -81,11 +81,11 @@ final class Number extends QRDataModeAbstract{
 		if($i < $len){
 
 			// encode 2 remaining numbers in 7 bits
-			if($len - $i === 2){
+			if(($len - $i) === 2){
 				$bitBuffer->put($this->parseInt(substr($this->data, $i, 2)), 7);
 			}
 			// encode one remaining number in 4 bits
-			elseif($len - $i === 1){
+			elseif(($len - $i) === 1){
 				$bitBuffer->put($this->parseInt(substr($this->data, $i, 1)), 4);
 			}
 
@@ -100,7 +100,7 @@ final class Number extends QRDataModeAbstract{
 		$num = 0;
 
 		foreach(str_split($string) as $chr){
-			$num = $num * 10 + ord($chr) - 48;
+			$num = ($num * 10 + ord($chr) - 48);
 		}
 
 		return $num;

+ 6 - 1
src/Data/QRCodeDataException.php

@@ -12,4 +12,9 @@ namespace chillerlan\QRCode\Data;
 
 use chillerlan\QRCode\QRCodeException;
 
-final class QRCodeDataException extends QRCodeException{}
+/**
+ * An exception container
+ */
+final class QRCodeDataException extends QRCodeException{
+
+}

+ 4 - 4
src/Data/QRData.php

@@ -144,7 +144,7 @@ final class QRData{
 
 			if(!$segment instanceof ECI){
 				// mode length bits margin to the next breakpoint
-				$margin += ($segment instanceof Byte ? 8 : 2);
+				$margin += ($segment instanceof Byte) ? 8 : 2;
 			}
 		}
 
@@ -208,7 +208,7 @@ final class QRData{
 		}
 
 		// add terminator (ISO/IEC 18004:2000 Table 2)
-		if($this->bitBuffer->getLength() + 4 <= $MAX_BITS){
+		if(($this->bitBuffer->getLength() + 4) <= $MAX_BITS){
 			$this->bitBuffer->put(0, 4);
 		}
 
@@ -216,7 +216,7 @@ final class QRData{
 
 		// if the final codeword is not exactly 8 bits in length, it shall be made 8 bits long
 		// by the addition of padding bits with binary value 0
-		while($this->bitBuffer->getLength() % 8 !== 0){
+		while(($this->bitBuffer->getLength() % 8) !== 0){
 			$this->bitBuffer->putBit(false);
 		}
 
@@ -226,7 +226,7 @@ final class QRData{
 		$alternate = false;
 
 		while($this->bitBuffer->getLength() <= $MAX_BITS){
-			$this->bitBuffer->put($alternate ? 0b00010001 : 0b11101100, 8);
+			$this->bitBuffer->put(($alternate) ? 0b00010001 : 0b11101100, 8);
 
 			$alternate = !$alternate;
 		}

+ 43 - 40
src/Data/QRMatrix.php

@@ -65,7 +65,7 @@ class QRMatrix{
 		0b00010000 => [ 1,  1],
 		0b00100000 => [ 0,  1],
 		0b01000000 => [-1,  1],
-		0b10000000 => [-1,  0]
+		0b10000000 => [-1,  0],
 	];
 
 	/**
@@ -133,7 +133,7 @@ class QRMatrix{
 	 *
 	 * @return int[][]|bool[][]
 	 */
-	public function matrix(bool $boolean = false):array{
+	public function matrix(bool $boolean = null):array{
 
 		if(!$boolean){
 			return $this->matrix;
@@ -183,7 +183,7 @@ class QRMatrix{
 	}
 
 	/**
-	 * Returns the value of the module at position [$x, $y] or -1 if the coordinate is outside of the matrix
+	 * Returns the value of the module at position [$x, $y] or -1 if the coordinate is outside the matrix
 	 */
 	public function get(int $x, int $y):int{
 
@@ -203,7 +203,7 @@ class QRMatrix{
 	public function set(int $x, int $y, bool $value, int $M_TYPE):self{
 
 		if(isset($this->matrix[$y][$x])){
-			$this->matrix[$y][$x] = $M_TYPE | ($value ? $this::IS_DARK : 0);
+			$this->matrix[$y][$x] = ($M_TYPE | (($value) ? $this::IS_DARK : 0));
 		}
 
 		return $this;
@@ -274,11 +274,14 @@ class QRMatrix{
 			[$ix, $iy] = $coord;
 
 			// check if the field is the same type
-			if($M_TYPE_VALUE !== null && ($this->get($x + $ix, $y + $iy) | $this::IS_DARK) !== ($M_TYPE_VALUE | $this::IS_DARK)){
+			if(
+				$M_TYPE_VALUE !== null
+				&& ($this->get(($x + $ix), ($y + $iy)) | $this::IS_DARK) !== ($M_TYPE_VALUE | $this::IS_DARK)
+			){
 				continue;
 			}
 
-			if($this->checkType($x + $ix, $y + $iy, $this::IS_DARK)){
+			if($this->checkType(($x + $ix), ($y + $iy), $this::IS_DARK)){
 				$bits |= $bit;
 			}
 		}
@@ -292,7 +295,7 @@ class QRMatrix{
 	 * 4 * version + 9 or moduleCount - 8
 	 */
 	public function setDarkModule():self{
-		$this->set(8, $this->moduleCount - 8, true, $this::M_DARKMODULE);
+		$this->set(8, ($this->moduleCount - 8), true, $this::M_DARKMODULE);
 
 		return $this;
 	}
@@ -306,8 +309,8 @@ class QRMatrix{
 
 		$pos = [
 			[0, 0], // top left
-			[$this->moduleCount - 7, 0], // top right
-			[0, $this->moduleCount - 7], // bottom left
+			[($this->moduleCount - 7), 0], // top right
+			[0, ($this->moduleCount - 7)], // bottom left
 		];
 
 		foreach($pos as $c){
@@ -315,15 +318,15 @@ class QRMatrix{
 				for($x = 0; $x < 7; $x++){
 					// outer (dark) 7*7 square
 					if($x === 0 || $x === 6 || $y === 0 || $y === 6){
-						$this->set($c[0] + $y, $c[1] + $x, true, $this::M_FINDER);
+						$this->set(($c[0] + $y), ($c[1] + $x), true, $this::M_FINDER);
 					}
 					// inner (light) 5*5 square
 					elseif($x === 1 || $x === 5 || $y === 1 || $y === 5){
-						$this->set($c[0] + $y, $c[1] + $x, false, $this::M_FINDER);
+						$this->set(($c[0] + $y), ($c[1] + $x), false, $this::M_FINDER);
 					}
 					// 3*3 dot
 					else{
-						$this->set($c[0] + $y, $c[1] + $x, true, $this::M_FINDER_DOT);
+						$this->set(($c[0] + $y), ($c[1] + $x), true, $this::M_FINDER_DOT);
 					}
 				}
 			}
@@ -341,20 +344,20 @@ class QRMatrix{
 
 		$h = [
 			[7, 0],
-			[$this->moduleCount - 8, 0],
-			[7, $this->moduleCount - 8],
+			[($this->moduleCount - 8), 0],
+			[7, ($this->moduleCount - 8)],
 		];
 
 		$v = [
 			[7, 7],
-			[$this->moduleCount - 1, 7],
-			[7, $this->moduleCount - 8],
+			[($this->moduleCount - 1), 7],
+			[7, ($this->moduleCount - 8)],
 		];
 
 		for($c = 0; $c < 3; $c++){
 			for($i = 0; $i < 8; $i++){
-				$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);
+				$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);
 			}
 		}
 
@@ -382,7 +385,7 @@ class QRMatrix{
 					for($rx = -2; $rx <= 2; $rx++){
 						$v = ($ry === 0 && $rx === 0) || $ry === 2 || $ry === -2 || $rx === 2 || $rx === -2;
 
-						$this->set($x + $rx, $y + $ry, $v, $this::M_ALIGNMENT);
+						$this->set(($x + $rx), ($y + $ry), $v, $this::M_ALIGNMENT);
 					}
 				}
 
@@ -400,13 +403,13 @@ class QRMatrix{
 	 */
 	public function setTimingPattern():self{
 
-		foreach(range(8, $this->moduleCount - 8 - 1) as $i){
+		foreach(range(8, ($this->moduleCount - 8 - 1)) as $i){
 
 			if($this->matrix[6][$i] !== $this::M_NULL || $this->matrix[$i][6] !== $this::M_NULL){
 				continue;
 			}
 
-			$v = $i % 2 === 0;
+			$v = ($i % 2) === 0;
 
 			$this->set($i, 6, $v, $this::M_TIMING); // h
 			$this->set(6, $i, $v, $this::M_TIMING); // v
@@ -427,7 +430,7 @@ class QRMatrix{
 
 			for($i = 0; $i < 18; $i++){
 				$a = (int)($i / 3);
-				$b = $i % 3 + $this->moduleCount - 8 - 3;
+				$b = (($i % 3) + ($this->moduleCount - 8 - 3));
 				$v = (($bits >> $i) & 1) === 1;
 
 				$this->set($b, $a, $v, $this::M_VERSION); // ne
@@ -454,20 +457,20 @@ class QRMatrix{
 				$this->set(8, $i, $v, $this::M_FORMAT);
 			}
 			elseif($i < 8){
-				$this->set(8, $i + 1, $v, $this::M_FORMAT);
+				$this->set(8, ($i + 1), $v, $this::M_FORMAT);
 			}
 			else{
-				$this->set(8, $this->moduleCount - 15 + $i, $v, $this::M_FORMAT);
+				$this->set(8, ($this->moduleCount - 15 + $i), $v, $this::M_FORMAT);
 			}
 
 			if($i < 8){
-				$this->set($this->moduleCount - $i - 1, 8, $v, $this::M_FORMAT);
+				$this->set(($this->moduleCount - $i - 1), 8, $v, $this::M_FORMAT);
 			}
 			elseif($i < 9){
-				$this->set(15 - $i, 8, $v, $this::M_FORMAT);
+				$this->set(((15 - $i)), 8, $v, $this::M_FORMAT);
 			}
 			else{
-				$this->set(15 - $i - 1, 8, $v, $this::M_FORMAT);
+				$this->set((15 - $i - 1), 8, $v, $this::M_FORMAT);
 			}
 
 		}
@@ -484,18 +487,18 @@ class QRMatrix{
 	 */
 	public function setQuietZone(int $quietZoneSize):self{
 
-		if($this->matrix[$this->moduleCount - 1][$this->moduleCount - 1] === $this::M_NULL){
+		if($this->matrix[($this->moduleCount - 1)][($this->moduleCount - 1)] === $this::M_NULL){
 			throw new QRCodeDataException('use only after writing data');
 		}
 
 		// create a matrix with the new size
-		$newSize   = $this->moduleCount + ($quietZoneSize * 2);
+		$newSize   = ($this->moduleCount + ($quietZoneSize * 2));
 		$newMatrix = $this->createMatrix($newSize, $this::M_QUIETZONE);
 
 		// copy over the current matrix
 		for($y = 0; $y < $this->moduleCount; $y++){
 			for($x = 0; $x < $this->moduleCount; $x++){
-				$newMatrix[$y + $quietZoneSize][$x + $quietZoneSize] = $this->matrix[$y][$x];
+				$newMatrix[($y + $quietZoneSize)][($x + $quietZoneSize)] = $this->matrix[$y][$x];
 			}
 		}
 
@@ -527,7 +530,7 @@ class QRMatrix{
 	 */
 	public function setLogoSpace(int $width, int $height = null, int $startX = null, int $startY = null):self{
 
-		// for logos we operate in ECC H (30%) only
+		// for logos, we operate in ECC H (30%) only
 		if($this->eccLevel->getLevel() !== EccLevel::H){
 			throw new QRCodeDataException('ECC level "H" required to add logo space');
 		}
@@ -559,20 +562,20 @@ class QRMatrix{
 		}
 
 		// throw if the logo space exceeds the maximum error correction capacity
-		if($width * $height > floor($length * $length * 0.2)){
+		if(($width * $height) > floor($length * $length * 0.2)){
 			throw new QRCodeDataException('logo space exceeds the maximum error correction capacity');
 		}
 
 		// quiet zone size
-		$qz    = ($this->moduleCount - $length) / 2;
+		$qz    = (($this->moduleCount - $length) / 2);
 		// skip quiet zone and the first 9 rows/columns (finder-, mode-, version- and timing patterns)
-		$start = $qz + 9;
+		$start = ($qz + 9);
 		// skip quiet zone
-		$end   = $this->moduleCount - $qz;
+		$end   = ($this->moduleCount - $qz);
 
 		// determine start coordinates
-		$startX = ($startX !== null ? $startX : ($length - $width) / 2) + $qz;
-		$startY = ($startY !== null ? $startY : ($length - $height) / 2) + $qz;
+		$startX = ((($startX !== null) ? $startX : ($length - $width) / 2) + $qz);
+		$startY = ((($startY !== null) ? $startY : ($length - $height) / 2) + $qz);
 
 		// clear the space
 		foreach($this->matrix as $y => $row){
@@ -601,7 +604,7 @@ class QRMatrix{
 		$iBit      = 7;
 		$direction = true;
 
-		for($i = $this->moduleCount - 1; $i > 0; $i -= 2){
+		for($i = ($this->moduleCount - 1); $i > 0; $i -= 2){
 
 			// skip vertical alignment pattern
 			if($i === 6){
@@ -609,10 +612,10 @@ class QRMatrix{
 			}
 
 			for($count = 0; $count < $this->moduleCount; $count++){
-				$y = $direction ? $this->moduleCount - 1 - $count : $count;
+				$y = ($direction) ? ($this->moduleCount - 1 - $count) : $count;
 
 				for($col = 0; $col < 2; $col++){
-					$x = $i - $col;
+					$x = ($i - $col);
 
 					// skip functional patterns
 					if($this->get($x, $y) !== $this::M_NULL){

+ 32 - 32
src/Decoder/Binarizer.php

@@ -83,9 +83,9 @@ final class Binarizer{
 		$secondPeakScore = 0;
 
 		for($x = 0; $x < $numBuckets; $x++){
-			$distanceToBiggest = $x - $firstPeak;
+			$distanceToBiggest = ($x - $firstPeak);
 			// Encourage more distant second peaks by multiplying by square of distance.
-			$score = $buckets[$x] * $distanceToBiggest * $distanceToBiggest;
+			$score = ($buckets[$x] * $distanceToBiggest * $distanceToBiggest);
 
 			if($score > $secondPeakScore){
 				$secondPeak      = $x;
@@ -102,17 +102,17 @@ final class Binarizer{
 
 		// If there is too little contrast in the image to pick a meaningful black point, throw rather
 		// than waste time trying to decode the image, and risk false positives.
-		if($secondPeak - $firstPeak <= $numBuckets / 16){
+		if(($secondPeak - $firstPeak) <= ($numBuckets / 16)){
 			throw new QRCodeDecoderException('no meaningful dark point found'); // @codeCoverageIgnore
 		}
 
 		// Find a valley between them that is low and closer to the white peak.
-		$bestValley      = $secondPeak - 1;
+		$bestValley      = ($secondPeak - 1);
 		$bestValleyScore = -1;
 
-		for($x = $secondPeak - 1; $x > $firstPeak; $x--){
-			$fromFirst = $x - $firstPeak;
-			$score     = $fromFirst * $fromFirst * ($secondPeak - $x) * ($maxBucketCount - $buckets[$x]);
+		for($x = ($secondPeak - 1); $x > $firstPeak; $x--){
+			$fromFirst = ($x - $firstPeak);
+			$score     = ($fromFirst * $fromFirst * ($secondPeak - $x) * ($maxBucketCount - $buckets[$x]));
 
 			if($score > $bestValleyScore){
 				$bestValley      = $x;
@@ -120,7 +120,7 @@ final class Binarizer{
 			}
 		}
 
-		return $bestValley << self::LUMINANCE_SHIFT;
+		return ($bestValley << self::LUMINANCE_SHIFT);
 	}
 
 	/**
@@ -140,13 +140,13 @@ final class Binarizer{
 		$height = $this->source->getHeight();
 
 		if($width >= self::MINIMUM_DIMENSION && $height >= self::MINIMUM_DIMENSION){
-			$subWidth = $width >> self::BLOCK_SIZE_POWER;
+			$subWidth = ($width >> self::BLOCK_SIZE_POWER);
 
 			if(($width & self::BLOCK_SIZE_MASK) !== 0){
 				$subWidth++;
 			}
 
-			$subHeight = $height >> self::BLOCK_SIZE_POWER;
+			$subHeight = ($height >> self::BLOCK_SIZE_POWER);
 
 			if(($height & self::BLOCK_SIZE_MASK) !== 0){
 				$subHeight++;
@@ -174,8 +174,8 @@ final class Binarizer{
 			$right           = (int)(($width * 4) / 5);
 
 			for($x = (int)($width / 5); $x < $right; $x++){
-				$pixel = $localLuminances[$x] & 0xff;
-				$buckets[$pixel >> self::LUMINANCE_SHIFT]++;
+				$pixel = ($localLuminances[$x] & 0xff);
+				$buckets[($pixel >> self::LUMINANCE_SHIFT)]++;
 			}
 		}
 
@@ -187,10 +187,10 @@ final class Binarizer{
 		$matrix = new BitMatrix(max($width, $height));
 
 		for($y = 0; $y < $height; $y++){
-			$offset = $y * $width;
+			$offset = ($y * $width);
 
 			for($x = 0; $x < $width; $x++){
-				$matrix->set($x, $y, (($this->luminances[$offset + $x] & 0xff) < $blackPoint), QRMatrix::M_DATA);
+				$matrix->set($x, $y, (($this->luminances[($offset + $x)] & 0xff) < $blackPoint), QRMatrix::M_DATA);
 			}
 		}
 
@@ -212,7 +212,7 @@ final class Binarizer{
 
 		for($y = 0; $y < $subHeight; $y++){
 			$yoffset    = ($y << self::BLOCK_SIZE_POWER);
-			$maxYOffset = $height - self::BLOCK_SIZE;
+			$maxYOffset = ($height - self::BLOCK_SIZE);
 
 			if($yoffset > $maxYOffset){
 				$yoffset = $maxYOffset;
@@ -220,7 +220,7 @@ final class Binarizer{
 
 			for($x = 0; $x < $subWidth; $x++){
 				$xoffset    = ($x << self::BLOCK_SIZE_POWER);
-				$maxXOffset = $width - self::BLOCK_SIZE;
+				$maxXOffset = ($width - self::BLOCK_SIZE);
 
 				if($xoffset > $maxXOffset){
 					$xoffset = $maxXOffset;
@@ -230,10 +230,10 @@ final class Binarizer{
 				$min = 255;
 				$max = 0;
 
-				for($yy = 0, $offset = $yoffset * $width + $xoffset; $yy < self::BLOCK_SIZE; $yy++, $offset += $width){
+				for($yy = 0, $offset = ($yoffset * $width + $xoffset); $yy < self::BLOCK_SIZE; $yy++, $offset += $width){
 
 					for($xx = 0; $xx < self::BLOCK_SIZE; $xx++){
-						$pixel = (int)($this->luminances[(int)($offset + $xx)]) & 0xff;
+						$pixel = ((int)($this->luminances[(int)($offset + $xx)]) & 0xff);
 						$sum   += $pixel;
 						// still looking for good contrast
 						if($pixel < $min){
@@ -246,20 +246,20 @@ final class Binarizer{
 					}
 
 					// short-circuit min/max tests once dynamic range is met
-					if($max - $min > self::MIN_DYNAMIC_RANGE){
+					if(($max - $min) > self::MIN_DYNAMIC_RANGE){
 						// finish the rest of the rows quickly
 						for($yy++, $offset += $width; $yy < self::BLOCK_SIZE; $yy++, $offset += $width){
 							for($xx = 0; $xx < self::BLOCK_SIZE; $xx++){
-								$sum += (int)($this->luminances[(int)($offset + $xx)]) & 0xff;
+								$sum += ((int)($this->luminances[(int)($offset + $xx)]) & 0xff);
 							}
 						}
 					}
 				}
 
 				// The default estimate is the average of the values in the block.
-				$average = $sum >> (self::BLOCK_SIZE_POWER * 2);
+				$average = ($sum >> (self::BLOCK_SIZE_POWER * 2));
 
-				if($max - $min <= self::MIN_DYNAMIC_RANGE){
+				if(($max - $min) <= self::MIN_DYNAMIC_RANGE){
 					// If variation within the block is low, assume this is a block with only light or only
 					// dark pixels. In that case we do not want to use the average, as it would divide this
 					// low contrast area into black and white pixels, essentially creating data out of noise.
@@ -277,7 +277,7 @@ final class Binarizer{
 
 						// The (min < bp) is arbitrary but works better than other heuristics that were tried.
 						$averageNeighborBlackPoint = (int)(
-							($blackPoints[$y - 1][$x] + (2 * $blackPoints[$y][$x - 1]) + $blackPoints[$y - 1][$x - 1]) / 4
+							($blackPoints[($y - 1)][$x] + (2 * $blackPoints[$y][($x - 1)]) + $blackPoints[($y - 1)][($x - 1)]) / 4
 						);
 
 						if($min < $averageNeighborBlackPoint){
@@ -304,7 +304,7 @@ final class Binarizer{
 
 		for($y = 0; $y < $subHeight; $y++){
 			$yoffset    = ($y << self::BLOCK_SIZE_POWER);
-			$maxYOffset = $height - self::BLOCK_SIZE;
+			$maxYOffset = ($height - self::BLOCK_SIZE);
 
 			if($yoffset > $maxYOffset){
 				$yoffset = $maxYOffset;
@@ -312,30 +312,30 @@ final class Binarizer{
 
 			for($x = 0; $x < $subWidth; $x++){
 				$xoffset    = ($x << self::BLOCK_SIZE_POWER);
-				$maxXOffset = $width - self::BLOCK_SIZE;
+				$maxXOffset = ($width - self::BLOCK_SIZE);
 
 				if($xoffset > $maxXOffset){
 					$xoffset = $maxXOffset;
 				}
 
-				$left = $this->cap($x, 2, $subWidth - 3);
-				$top  = $this->cap($y, 2, $subHeight - 3);
+				$left = $this->cap($x, 2, ($subWidth - 3));
+				$top  = $this->cap($y, 2, ($subHeight - 3));
 				$sum  = 0;
 
 				for($z = -2; $z <= 2; $z++){
-					$br   = $blackPoints[$top + $z];
-					$sum += $br[$left - 2] + $br[$left - 1] + $br[$left] + $br[$left + 1] + $br[$left + 2];
+					$br   = $blackPoints[($top + $z)];
+					$sum += ($br[($left - 2)] + $br[($left - 1)] + $br[$left] + $br[($left + 1)] + $br[($left + 2)]);
 				}
 
 				$average = (int)($sum / 25);
 
 				// Applies a single threshold to a block of pixels.
-				for($j = 0, $o = $yoffset * $width + $xoffset; $j < self::BLOCK_SIZE; $j++, $o += $width){
+				for($j = 0, $o = ($yoffset * $width + $xoffset); $j < self::BLOCK_SIZE; $j++, $o += $width){
 					for($i = 0; $i < self::BLOCK_SIZE; $i++){
 						// Comparison needs to be <= so that black == 0 pixels are black even if the threshold is 0.
-						$v = (((int)($this->luminances[$o + $i]) & 0xff) <= $average);
+						$v = (((int)($this->luminances[($o + $i)]) & 0xff) <= $average);
 
-						$matrix->set($xoffset + $i, $yoffset + $j, $v, QRMatrix::M_DATA);
+						$matrix->set(($xoffset + $i), ($yoffset + $j), $v, QRMatrix::M_DATA);
 					}
 				}
 			}

+ 16 - 16
src/Decoder/BitMatrix.php

@@ -94,7 +94,7 @@ final class BitMatrix extends QRMatrix{
 	public function mirror():self{
 
 		for($x = 0; $x < $this->moduleCount; $x++){
-			for($y = $x + 1; $y < $this->moduleCount; $y++){
+			for($y = ($x + 1); $y < $this->moduleCount; $y++){
 				if($this->get($x, $y) !== $this->get($y, $x)){
 					$this->flip($y, $x);
 					$this->flip($x, $y);
@@ -128,7 +128,7 @@ final class BitMatrix extends QRMatrix{
 		$direction = true;
 
 		// Read columns in pairs, from right to left
-		for($i = $this->moduleCount - 1; $i > 0; $i -= 2){
+		for($i = ($this->moduleCount - 1); $i > 0; $i -= 2){
 
 			// Skip whole column with vertical alignment pattern;
 			// saves time and makes the other code proceed more cleanly
@@ -137,10 +137,10 @@ final class BitMatrix extends QRMatrix{
 			}
 			// Read alternatingly from bottom to top then top to bottom
 			for($count = 0; $count < $this->moduleCount; $count++){
-				$y = $direction ? $this->moduleCount - 1 - $count : $count;
+				$y = ($direction) ? ($this->moduleCount - 1 - $count) : $count;
 
 				for($col = 0; $col < 2; $col++){
-					$x = $i - $col;
+					$x = ($i - $col);
 
 					// Ignore bits covered by the function pattern
 					if($fp->get($x, $y) !== $this::M_NULL){
@@ -203,13 +203,13 @@ final class BitMatrix extends QRMatrix{
 
 		// Read the top-right/bottom-left pattern too
 		$formatInfoBits2 = 0;
-		$jMin            = $this->moduleCount - 7;
+		$jMin            = ($this->moduleCount - 7);
 
-		for($j = $this->moduleCount - 1; $j >= $jMin; $j--){
+		for($j = ($this->moduleCount - 1); $j >= $jMin; $j--){
 			$formatInfoBits2 = $this->copyVersionBit(8, $j, $formatInfoBits2);
 		}
 
-		for($i = $this->moduleCount - 8; $i < $this->moduleCount; $i++){
+		for($i = ($this->moduleCount - 8); $i < $this->moduleCount; $i++){
 			$formatInfoBits2 = $this->copyVersionBit($i, 8, $formatInfoBits2);
 		}
 
@@ -220,8 +220,8 @@ final class BitMatrix extends QRMatrix{
 			// Should return null, but, some QR codes apparently do not mask this info.
 			// Try again by actually masking the pattern first.
 			$formatInfo = $this->doDecodeFormatInformation(
-				$formatInfoBits1 ^ $this::FORMAT_INFO_MASK_QR,
-				$formatInfoBits2 ^ $this::FORMAT_INFO_MASK_QR
+				($formatInfoBits1 ^ $this::FORMAT_INFO_MASK_QR),
+				($formatInfoBits2 ^ $this::FORMAT_INFO_MASK_QR)
 			);
 
 			// still nothing???
@@ -246,7 +246,7 @@ final class BitMatrix extends QRMatrix{
 			? $this->check($j, $i)
 			: $this->check($i, $j);
 
-		return $bit ? ($versionBits << 1) | 0x1 : $versionBits << 1;
+		return ($bit) ? (($versionBits << 1) | 0x1) : ($versionBits << 1);
 	}
 
 	/**
@@ -302,7 +302,7 @@ final class BitMatrix extends QRMatrix{
 			return $this;
 		}
 
-		$provisionalVersion = ($this->moduleCount - 17) / 4;
+		$provisionalVersion = (($this->moduleCount - 17) / 4);
 
 		// no version info if v < 7
 		if($provisionalVersion < 7){
@@ -313,10 +313,10 @@ final class BitMatrix extends QRMatrix{
 
 		// Read top-right version info: 3 wide by 6 tall
 		$versionBits = 0;
-		$ijMin       = $this->moduleCount - 11;
+		$ijMin       = ($this->moduleCount - 11);
 
 		for($y = 5; $y >= 0; $y--){
-			for($x = $this->moduleCount - 9; $x >= $ijMin; $x--){
+			for($x = ($this->moduleCount - 9); $x >= $ijMin; $x--){
 				$versionBits = $this->copyVersionBit($x, $y, $versionBits);
 			}
 		}
@@ -331,7 +331,7 @@ final class BitMatrix extends QRMatrix{
 		$versionBits = 0;
 
 		for($x = 5; $x >= 0; $x--){
-			for($y = $this->moduleCount - 9; $y >= $ijMin; $y--){
+			for($y = ($this->moduleCount - 9); $y >= $ijMin; $y--){
 				$versionBits = $this->copyVersionBit($x, $y, $versionBits);
 			}
 		}
@@ -390,7 +390,7 @@ final class BitMatrix extends QRMatrix{
 			return $a;
 		}
 
-		return ($a >> $b) & ~((1 << (8 * PHP_INT_SIZE - 1)) >> ($b - 1));
+		return (($a >> $b) & ~((1 << (8 * PHP_INT_SIZE - 1)) >> ($b - 1)));
 	}
 
 	/**
@@ -405,7 +405,7 @@ final class BitMatrix extends QRMatrix{
 		$count = 0;
 
 		for($i = 0; $i < 32; $i += 4){
-			$count += $BITS_SET_IN_HALF_BYTE[$this->uRShift($a, $i) & 0x0F];
+			$count += $BITS_SET_IN_HALF_BYTE[($this->uRShift($a, $i) & 0x0F)];
 		}
 
 		return $count;

+ 69 - 56
src/Decoder/Decoder.php

@@ -11,7 +11,7 @@
 
 namespace chillerlan\QRCode\Decoder;
 
-use chillerlan\QRCode\Common\{BitBuffer, EccLevel, MaskPattern, Mode, ReedSolomonDecoder, Version};
+use chillerlan\QRCode\Common\{BitBuffer, EccLevel, ECICharset, MaskPattern, Mode, ReedSolomonDecoder, Version};
 use chillerlan\QRCode\Data\{AlphaNum, Byte, ECI, Hanzi, Kanji, Number};
 use chillerlan\QRCode\Detector\Detector;
 use Throwable;
@@ -28,6 +28,8 @@ final class Decoder{
 	private ?Version     $version = null;
 	private ?EccLevel    $eccLevel = null;
 	private ?MaskPattern $maskPattern = null;
+	private BitBuffer    $bitBuffer;
+	private ?ECICharset  $eciCharset = null;
 
 	/**
 	 * Decodes a QR Code represented as a BitMatrix.
@@ -89,23 +91,24 @@ final class Decoder{
 	 * @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException
 	 */
 	private function decodeBitStream(BitBuffer $bitBuffer):DecoderResult{
-		$versionNumber  = $this->version->getVersionNumber();
-		$symbolSequence = -1;
-		$parityData     = -1;
-		$eciCharset     = null;
-		$fc1InEffect    = false;
-		$result         = '';
+		$this->bitBuffer  = $bitBuffer;
+		$this->eciCharset = null;
+		$versionNumber    = $this->version->getVersionNumber();
+		$symbolSequence   = -1;
+		$parityData       = -1;
+		$fc1InEffect      = false;
+		$result           = '';
 
 		// While still another segment to read...
-		while($bitBuffer->available() >= 4){
-			$datamode = $bitBuffer->read(4); // mode is encoded by 4 bits
+		while($this->bitBuffer->available() >= 4){
+			$datamode = $this->bitBuffer->read(4); // mode is encoded by 4 bits
 
 			// OK, assume we're done. Really, a TERMINATOR mode should have been recorded here
 			if($datamode === Mode::TERMINATOR){
 				break;
 			}
 			elseif($datamode === Mode::ECI){
-				$eciCharset = ECI::parseValue($bitBuffer);
+				$this->eciCharset = ECI::parseValue($this->bitBuffer);
 			}
 			elseif($datamode === Mode::FNC1_FIRST || $datamode === Mode::FNC1_SECOND){
 				// We do little with FNC1 except alter the parsed result a bit according to the spec
@@ -113,64 +116,28 @@ final class Decoder{
 			}
 			elseif($datamode === Mode::STRCTURED_APPEND){
 
-				if($bitBuffer->available() < 16){
+				if($this->bitBuffer->available() < 16){
 					throw new QRCodeDecoderException('structured append: not enough bits left');
 				}
 				// sequence number and parity is added later to the result metadata
 				// Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue
-				$symbolSequence = $bitBuffer->read(8);
-				$parityData     = $bitBuffer->read(8);
+				$symbolSequence = $this->bitBuffer->read(8);
+				$parityData     = $this->bitBuffer->read(8);
 			}
 			elseif($datamode === Mode::NUMBER){
-				$result .= Number::decodeSegment($bitBuffer, $versionNumber);
+				$result .= Number::decodeSegment($this->bitBuffer, $versionNumber);
 			}
 			elseif($datamode === Mode::ALPHANUM){
-				$str = AlphaNum::decodeSegment($bitBuffer, $versionNumber);
-
-				// See section 6.4.8.1, 6.4.8.2
-				if($fc1InEffect){ // ???
-					// We need to massage the result a bit if in an FNC1 mode:
-					$str = str_replace(chr(0x1d), '%', $str);
-					$str = str_replace('%%', '%', $str);
-				}
-
-				$result .= $str;
+				$result .= $this->decodeAlphanumSegment($versionNumber, $fc1InEffect);
 			}
 			elseif($datamode === Mode::BYTE){
-				$str = Byte::decodeSegment($bitBuffer, $versionNumber);
-
-				if($eciCharset !== null){
-					$encoding = $eciCharset->getName();
-
-					if($encoding === null){
-						// The spec isn't clear on this mode; see
-						// section 6.4.5: t does not say which encoding to assuming
-						// upon decoding. I have seen ISO-8859-1 used as well as
-						// Shift_JIS -- without anything like an ECI designator to
-						// give a hint.
-						$encoding = mb_detect_encoding($str, ['ISO-8859-1', 'Windows-1252', 'SJIS', 'UTF-8'], true);
-
-						if($encoding === false){
-							throw new QRCodeDecoderException('could not determine encoding in ECI mode');
-						}
-					}
-
-					$eciCharset = null;
-					$str = mb_convert_encoding($str, mb_internal_encoding(), $encoding);
-				}
-
-				$result .= $str;
+				$result .= $this->decodeByteSegment($versionNumber);
 			}
 			elseif($datamode === Mode::KANJI){
-				$result .= Kanji::decodeSegment($bitBuffer, $versionNumber);
+				$result .= Kanji::decodeSegment($this->bitBuffer, $versionNumber);
 			}
 			elseif($datamode === Mode::HANZI){
-				// Hanzi mode contains a subset indicator right after mode indicator
-				if($bitBuffer->read(4) !== Hanzi::GB2312_SUBSET){
-					throw new QRCodeDecoderException('ecpected subset indicator for Hanzi mode');
-				}
-
-				$result .= Hanzi::decodeSegment($bitBuffer, $versionNumber);
+				$result .= Hanzi::decodeSegment($this->bitBuffer, $versionNumber);
 			}
 			else{
 				throw new QRCodeDecoderException('invalid data mode');
@@ -179,14 +146,60 @@ final class Decoder{
 		}
 
 		return new DecoderResult([
-			'rawBytes'                 => $bitBuffer,
+			'rawBytes'                 => $this->bitBuffer,
 			'data'                     => $result,
 			'version'                  => $this->version,
 			'eccLevel'                 => $this->eccLevel,
 			'maskPattern'              => $this->maskPattern,
 			'structuredAppendParity'   => $parityData,
-			'structuredAppendSequence' => $symbolSequence
+			'structuredAppendSequence' => $symbolSequence,
 		]);
 	}
 
+	/**
+	 *
+	 */
+	private function decodeAlphanumSegment(int $versionNumber, bool $fc1InEffect):string{
+		$str = AlphaNum::decodeSegment($this->bitBuffer, $versionNumber);
+
+		// See section 6.4.8.1, 6.4.8.2
+		if($fc1InEffect){ // ???
+			// We need to massage the result a bit if in an FNC1 mode:
+			$str = str_replace(chr(0x1d), '%', $str);
+			$str = str_replace('%%', '%', $str);
+		}
+
+		return $str;
+	}
+
+	/**
+	 * @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException
+	 */
+	private function decodeByteSegment(int $versionNumber):string{
+		$str = Byte::decodeSegment($this->bitBuffer, $versionNumber);
+
+		if($this->eciCharset === null){
+			return $str;
+		}
+
+		$encoding = $this->eciCharset->getName();
+
+		if($encoding === null){
+			// The spec isn't clear on this mode; see
+			// section 6.4.5: t does not say which encoding to assuming
+			// upon decoding. I have seen ISO-8859-1 used as well as
+			// Shift_JIS -- without anything like an ECI designator to
+			// give a hint.
+			$encoding = mb_detect_encoding($str, ['ISO-8859-1', 'Windows-1252', 'SJIS', 'UTF-8'], true);
+
+			if($encoding === false){
+				throw new QRCodeDecoderException('could not determine encoding in ECI mode');
+			}
+		}
+
+		$this->eciCharset = null;
+
+		return mb_convert_encoding($str, mb_internal_encoding(), $encoding);
+	}
+
 }

+ 1 - 1
src/Decoder/IMagickLuminanceSource.php

@@ -55,7 +55,7 @@ class IMagickLuminanceSource extends LuminanceSourceAbstract{
 		$count  = count($pixels);
 
 		for($i = 0; $i < $count; $i += 3){
-			$this->setLuminancePixel($pixels[$i] & 0xff, $pixels[$i + 1] & 0xff, $pixels[$i + 2] & 0xff);
+			$this->setLuminancePixel(($pixels[$i] & 0xff), ($pixels[($i + 1)] & 0xff), ($pixels[($i + 2)] & 0xff));
 		}
 	}
 

+ 4 - 4
src/Decoder/LuminanceSourceAbstract.php

@@ -36,7 +36,7 @@ abstract class LuminanceSourceAbstract implements LuminanceSourceInterface{
 	public function __construct(int $width, int $height, SettingsContainerInterface $options = null){
 		$this->width   = $width;
 		$this->height  = $height;
-		$this->options = $options ?? new QROptions;
+		$this->options = ($options ?? new QROptions);
 
 		$this->luminances = [];
 	}
@@ -65,7 +65,7 @@ abstract class LuminanceSourceAbstract implements LuminanceSourceInterface{
 
 		$arr = [];
 
-		array_splice($arr, 0, $this->width, array_slice($this->luminances, $y * $this->width, $this->width));
+		array_splice($arr, 0, $this->width, array_slice($this->luminances, ($y * $this->width), $this->width));
 
 		return $arr;
 	}
@@ -74,11 +74,11 @@ abstract class LuminanceSourceAbstract implements LuminanceSourceInterface{
 	 *
 	 */
 	protected function setLuminancePixel(int $r, int $g, int $b):void{
-		$this->luminances[] = $r === $g && $g === $b
+		$this->luminances[] = ($r === $g && $g === $b)
 			// Image is already greyscale, so pick any channel.
 			? $r // (($r + 128) % 256) - 128;
 			// Calculate luminance cheaply, favoring green.
-			: ($r + 2 * $g + $b) / 4; // (((($r + 2 * $g + $b) / 4) + 128) % 256) - 128;
+			: (($r + 2 * $g + $b) / 4); // (((($r + 2 * $g + $b) / 4) + 128) % 256) - 128;
 	}
 
 	/**

+ 6 - 1
src/Decoder/QRCodeDecoderException.php

@@ -12,4 +12,9 @@ namespace chillerlan\QRCode\Decoder;
 
 use chillerlan\QRCode\QRCodeException;
 
-final class QRCodeDecoderException extends QRCodeException{}
+/**
+ * An exception container
+ */
+final class QRCodeDecoderException extends QRCodeException{
+
+}

+ 3 - 3
src/Detector/AlignmentPattern.php

@@ -25,9 +25,9 @@ final class AlignmentPattern extends ResultPoint{
 	 */
 	public function combineEstimate(float $i, float $j, float $newModuleSize):self{
 		return new self(
-			($this->x + $j) / 2.0,
-			($this->y + $i) / 2.0,
-			($this->estimatedModuleSize + $newModuleSize) / 2.0
+			(($this->x + $j) / 2.0),
+			(($this->y + $i) / 2.0),
+			(($this->estimatedModuleSize + $newModuleSize) / 2.0)
 		);
 	}
 

+ 10 - 11
src/Detector/AlignmentPatternFinder.php

@@ -59,15 +59,15 @@ final class AlignmentPatternFinder{
 	 * @return \chillerlan\QRCode\Detector\AlignmentPattern|null
 	 */
 	public function find(int $startX, int $startY, int $width, int $height):?AlignmentPattern{
-		$maxJ       = $startX + $width;
-		$middleI    = $startY + ($height / 2);
+		$maxJ       = ($startX + $width);
+		$middleI    = ($startY + ($height / 2));
 		$stateCount = [];
 
 		// We are looking for black/white/black modules in 1:1:1 ratio;
 		// this tracks the number of black/white/black modules seen so far
 		for($iGen = 0; $iGen < $height; $iGen++){
 			// Search from middle outwards
-			$i             = (int)($middleI + (($iGen & 0x01) === 0 ? ($iGen + 1) / 2 : -(($iGen + 1) / 2)));
+			$i             = (int)($middleI + ((($iGen & 0x01) === 0) ? ($iGen + 1) / 2 : -(($iGen + 1) / 2)));
 			$stateCount[0] = 0;
 			$stateCount[1] = 0;
 			$stateCount[2] = 0;
@@ -150,11 +150,10 @@ final class AlignmentPatternFinder{
 	 *         used by alignment patterns to be considered a match
 	 */
 	private function foundPatternCross(array $stateCount):bool{
-		$moduleSize  = $this->moduleSize;
-		$maxVariance = $moduleSize / 2.0;
+		$maxVariance = ($this->moduleSize / 2.0);
 
 		for($i = 0; $i < 3; $i++){
-			if(abs($moduleSize - $stateCount[$i]) >= $maxVariance){
+			if(abs($this->moduleSize - $stateCount[$i]) >= $maxVariance){
 				return false;
 			}
 		}
@@ -175,12 +174,12 @@ final class AlignmentPatternFinder{
 	 * @return \chillerlan\QRCode\Detector\AlignmentPattern|null if we have found the same pattern twice, or null if not
 	 */
 	private function handlePossibleCenter(array $stateCount, int $i, int $j):?AlignmentPattern{
-		$stateCountTotal = $stateCount[0] + $stateCount[1] + $stateCount[2];
+		$stateCountTotal = ($stateCount[0] + $stateCount[1] + $stateCount[2]);
 		$centerJ         = $this->centerFromEnd($stateCount, $j);
-		$centerI         = $this->crossCheckVertical($i, (int)$centerJ, 2 * $stateCount[1], $stateCountTotal);
+		$centerI         = $this->crossCheckVertical($i, (int)$centerJ, (2 * $stateCount[1]), $stateCountTotal);
 
 		if($centerI !== null){
-			$estimatedModuleSize = (float)($stateCount[0] + $stateCount[1] + $stateCount[2]) / 3.0;
+			$estimatedModuleSize = (($stateCount[0] + $stateCount[1] + $stateCount[2]) / 3.0);
 
 			foreach($this->possibleCenters as $center){
 				// Look for about the same center and module size:
@@ -251,7 +250,7 @@ final class AlignmentPatternFinder{
 		}
 
 		// Now also count down from center
-		$i = $startI + 1;
+		$i = ($startI + 1);
 		while($i < $maxI && $this->matrix->check($centerJ, $i) && $stateCount[1] <= $maxCount){
 			$stateCount[1]++;
 			$i++;
@@ -270,7 +269,7 @@ final class AlignmentPatternFinder{
 			return null;
 		}
 
-		if(5 * abs(($stateCount[0] + $stateCount[1] + $stateCount[2]) - $originalStateCountTotal) >= 2 * $originalStateCountTotal){
+		if((5 * abs(($stateCount[0] + $stateCount[1] + $stateCount[2]) - $originalStateCountTotal)) >= (2 * $originalStateCountTotal)){
 			return null;
 		}
 

+ 36 - 36
src/Detector/Detector.php

@@ -48,12 +48,12 @@ final class Detector{
 		// Anything above version 1 has an alignment pattern
 		if(!empty($provisionalVersion->getAlignmentPattern())){
 			// Guess where a "bottom right" finder pattern would have been
-			$bottomRightX = $topRight->getX() - $topLeft->getX() + $bottomLeft->getX();
-			$bottomRightY = $topRight->getY() - $topLeft->getY() + $bottomLeft->getY();
+			$bottomRightX = ($topRight->getX() - $topLeft->getX() + $bottomLeft->getX());
+			$bottomRightY = ($topRight->getY() - $topLeft->getY() + $bottomLeft->getY());
 
 			// Estimate that alignment pattern is closer by 3 modules
 			// from "bottom right" to known top left location
-			$correctionToTopLeft = 1.0 - 3.0 / (float)($provisionalVersion->getDimension() - 7);
+			$correctionToTopLeft = (1.0 - 3.0 / (float)($provisionalVersion->getDimension() - 7));
 			$estAlignmentX       = (int)($topLeft->getX() + $correctionToTopLeft * ($bottomRightX - $topLeft->getX()));
 			$estAlignmentY       = (int)($topLeft->getY() + $correctionToTopLeft * ($bottomRightY - $topLeft->getY()));
 
@@ -81,10 +81,10 @@ final class Detector{
 	 */
 	private function calculateModuleSize(FinderPattern $topLeft, FinderPattern $topRight, FinderPattern $bottomLeft):float{
 		// Take the average
-		$moduleSize = (
+		$moduleSize = ((
 			$this->calculateModuleSizeOneWay($topLeft, $topRight) +
 			$this->calculateModuleSizeOneWay($topLeft, $bottomLeft)
-		) / 2.0;
+		) / 2.0);
 
 		if($moduleSize < 1.0){
 			throw new QRCodeDetectorException('module size < 1.0');
@@ -104,15 +104,15 @@ final class Detector{
 		$moduleSizeEst2 = $this->sizeOfBlackWhiteBlackRunBothWays($b->getX(), $b->getY(), $a->getX(), $a->getY());
 
 		if(is_nan($moduleSizeEst1)){
-			return $moduleSizeEst2 / 7.0;
+			return ($moduleSizeEst2 / 7.0);
 		}
 
 		if(is_nan($moduleSizeEst2)){
-			return $moduleSizeEst1 / 7.0;
+			return ($moduleSizeEst1 / 7.0);
 		}
 		// Average them, and divide by 7 since we've counted the width of 3 black modules,
 		// and 1 white and 1 black module on either side. Ergo, divide sum by 14.
-		return ($moduleSizeEst1 + $moduleSizeEst2) / 14.0;
+		return (($moduleSizeEst1 + $moduleSizeEst2) / 14.0);
 	}
 
 	/**
@@ -127,34 +127,34 @@ final class Detector{
 		$dimension = $this->matrix->size();
 		// Now count other way -- don't run off image though of course
 		$scale     = 1.0;
-		$otherToX  = $fromX - ($toX - $fromX);
+		$otherToX  = ($fromX - ($toX - $fromX));
 
 		if($otherToX < 0){
-			$scale    = $fromX / ($fromX - $otherToX);
+			$scale    = ($fromX / ($fromX - $otherToX));
 			$otherToX = 0;
 		}
 		elseif($otherToX >= $dimension){
-			$scale    = ($dimension - 1 - $fromX) / ($otherToX - $fromX);
-			$otherToX = $dimension - 1;
+			$scale    = (($dimension - 1 - $fromX) / ($otherToX - $fromX));
+			$otherToX = ($dimension - 1);
 		}
 
 		$otherToY = (int)($fromY - ($toY - $fromY) * $scale);
 		$scale    = 1.0;
 
 		if($otherToY < 0){
-			$scale    = $fromY / ($fromY - $otherToY);
+			$scale    = ($fromY / ($fromY - $otherToY));
 			$otherToY = 0;
 		}
 		elseif($otherToY >= $dimension){
-			$scale    = ($dimension - 1 - $fromY) / ($otherToY - $fromY);
-			$otherToY = $dimension - 1;
+			$scale    = (($dimension - 1 - $fromY) / ($otherToY - $fromY));
+			$otherToY = ($dimension - 1);
 		}
 
 		$otherToX = (int)($fromX + ($otherToX - $fromX) * $scale);
 		$result   += $this->sizeOfBlackWhiteBlackRun((int)$fromX, (int)$fromY, $otherToX, $otherToY);
 
 		// Middle pixel is double-counted this way; subtract 1
-		return $result - 1.0;
+		return ($result - 1.0);
 	}
 
 	/**
@@ -181,18 +181,18 @@ final class Detector{
 
 		$dx    = abs($toX - $fromX);
 		$dy    = abs($toY - $fromY);
-		$error = -$dx / 2;
-		$xstep = $fromX < $toX ? 1 : -1;
-		$ystep = $fromY < $toY ? 1 : -1;
+		$error = (-$dx / 2);
+		$xstep = (($fromX < $toX) ? 1 : -1);
+		$ystep = (($fromY < $toY) ? 1 : -1);
 
 		// In black pixels, looking for white, first or second time.
 		$state  = 0;
 		// Loop up until x == toX, but not beyond
-		$xLimit = $toX + $xstep;
+		$xLimit = ($toX + $xstep);
 
 		for($x = $fromX, $y = $fromY; $x !== $xLimit; $x += $xstep){
-			$realX = $steep ? $y : $x;
-			$realY = $steep ? $x : $y;
+			$realX = ($steep) ? $y : $x;
+			$realY = ($steep) ? $x : $y;
 
 			// Does current pixel mean we have moved white to black or vice versa?
 			// Scanning black in state 0,2 and white in state 1, so if we find the wrong
@@ -223,7 +223,7 @@ final class Detector{
 		// is "white" so this last po$at (toX+xStep,toY) is the right ending. This is really a
 		// small approximation; (toX+xStep,toY+yStep) might be really correct. Ignore this.
 		if($state === 2){
-			return FinderPattern::distance($toX + $xstep, $toY, $fromX, $fromY);
+			return FinderPattern::distance(($toX + $xstep), $toY, $fromX, $fromY);
 		}
 
 		// else we didn't find even black-white-black; no estimate is really possible
@@ -253,7 +253,7 @@ final class Detector{
 				throw new QRCodeDetectorException('estimated dimension: '.$dimension);
 		}
 
-		if($dimension % 4 !== 1){
+		if(($dimension % 4) !== 1){
 			throw new QRCodeDetectorException('dimension mod 4 is not 1');
 		}
 
@@ -280,25 +280,25 @@ final class Detector{
 		// Look for an alignment pattern (3 modules in size) around where it should be
 		$dimension           = $this->matrix->size();
 		$allowance           = (int)($allowanceFactor * $overallEstModuleSize);
-		$alignmentAreaLeftX  = max(0, $estAlignmentX - $allowance);
-		$alignmentAreaRightX = min($dimension - 1, $estAlignmentX + $allowance);
+		$alignmentAreaLeftX  = max(0, ($estAlignmentX - $allowance));
+		$alignmentAreaRightX = min(($dimension - 1), ($estAlignmentX + $allowance));
 
-		if($alignmentAreaRightX - $alignmentAreaLeftX < $overallEstModuleSize * 3){
+		if(($alignmentAreaRightX - $alignmentAreaLeftX) < ($overallEstModuleSize * 3)){
 			return null;
 		}
 
-		$alignmentAreaTopY    = max(0, $estAlignmentY - $allowance);
-		$alignmentAreaBottomY = min($dimension - 1, $estAlignmentY + $allowance);
+		$alignmentAreaTopY    = max(0, ($estAlignmentY - $allowance));
+		$alignmentAreaBottomY = min(($dimension - 1), ($estAlignmentY + $allowance));
 
-		if($alignmentAreaBottomY - $alignmentAreaTopY < $overallEstModuleSize * 3){
+		if(($alignmentAreaBottomY - $alignmentAreaTopY) < ($overallEstModuleSize * 3)){
 			return null;
 		}
 
 		return (new AlignmentPatternFinder($this->matrix, $overallEstModuleSize))->find(
 			$alignmentAreaLeftX,
 			$alignmentAreaTopY,
-			$alignmentAreaRightX - $alignmentAreaLeftX,
-			$alignmentAreaBottomY - $alignmentAreaTopY,
+			($alignmentAreaRightX - $alignmentAreaLeftX),
+			($alignmentAreaBottomY - $alignmentAreaTopY),
 		);
 	}
 
@@ -312,18 +312,18 @@ final class Detector{
 		int              $size,
 		AlignmentPattern $ap = null
 	):PerspectiveTransform{
-		$dimMinusThree = (float)$size - 3.5;
+		$dimMinusThree = ($size - 3.5);
 
 		if($ap instanceof AlignmentPattern){
 			$bottomRightX       = $ap->getX();
 			$bottomRightY       = $ap->getY();
-			$sourceBottomRightX = $dimMinusThree - 3.0;
+			$sourceBottomRightX = ($dimMinusThree - 3.0);
 			$sourceBottomRightY = $sourceBottomRightX;
 		}
 		else{
 			// Don't have an alignment pattern, just make up the bottom-right point
-			$bottomRightX       = ($ne->getX() - $nw->getX()) + $sw->getX();
-			$bottomRightY       = ($ne->getY() - $nw->getY()) + $sw->getY();
+			$bottomRightX       = ($ne->getX() - $nw->getX() + $sw->getX());
+			$bottomRightY       = ($ne->getY() - $nw->getY() + $sw->getY());
 			$sourceBottomRightX = $dimMinusThree;
 			$sourceBottomRightY = $dimMinusThree;
 		}

+ 5 - 5
src/Detector/FinderPattern.php

@@ -30,7 +30,7 @@ final class FinderPattern extends ResultPoint{
 	public function __construct(float $posX, float $posY, float $estimatedModuleSize, int $count = null){
 		parent::__construct($posX, $posY, $estimatedModuleSize);
 
-		$this->count = $count ?? 1;
+		$this->count = ($count ?? 1);
 	}
 
 	/**
@@ -62,7 +62,7 @@ final class FinderPattern extends ResultPoint{
 	 * based on count.
 	 */
 	public function combineEstimate(float $i, float $j, float $newModuleSize):self{
-		$combinedCount = $this->count + 1;
+		$combinedCount = ($this->count + 1);
 
 		return new self(
 			($this->count * $this->x + $j) / $combinedCount,
@@ -76,10 +76,10 @@ final class FinderPattern extends ResultPoint{
 	 *
 	 */
 	private static function squaredDistance(float $aX, float $aY, float $bX, float $bY):float{
-		$xDiff = $aX - $bX;
-		$yDiff = $aY - $bY;
+		$xDiff = ($aX - $bX);
+		$yDiff = ($aY - $bY);
 
-		return $xDiff * $xDiff + $yDiff * $yDiff;
+		return ($xDiff * $xDiff + $yDiff * $yDiff);
 	}
 
 	/**

+ 33 - 30
src/Detector/FinderPatternFinder.php

@@ -64,7 +64,7 @@ final class FinderPatternFinder{
 
 		$done = false;
 
-		for($i = $iSkip - 1; $i < $dimension && !$done; $i += $iSkip){
+		for($i = ($iSkip - 1); ($i < $dimension) && !$done; $i += $iSkip){
 			// Get a row of black/white values
 			$stateCount   = $this->getCrossCheckStateCount();
 			$currentState = 0;
@@ -110,8 +110,8 @@ final class FinderPatternFinder{
 											// Skip by rowSkip, but back off by $stateCount[2] (size of last center
 											// of pattern we saw) to be conservative, and also back off by iSkip which
 											// is about to be re-added
-											$i += $rowSkip - $stateCount[2] - $iSkip;
-											$j = $dimension - 1;
+											$i += ($rowSkip - $stateCount[2] - $iSkip);
+											$j = ($dimension - 1);
 										}
 									}
 								}
@@ -230,13 +230,13 @@ final class FinderPatternFinder{
 			return false;
 		}
 
-		$moduleSize  = $totalModuleSize / 7.0;
-		$maxVariance = $moduleSize / $variance;
+		$moduleSize  = ($totalModuleSize / 7.0);
+		$maxVariance = ($moduleSize / $variance);
 
 		return
 			abs($moduleSize - $stateCount[0]) < $maxVariance
 			&& abs($moduleSize - $stateCount[1]) < $maxVariance
-			&& abs(3.0 * $moduleSize - $stateCount[2]) < 3 * $maxVariance
+			&& abs(3.0 * $moduleSize - $stateCount[2]) < (3 * $maxVariance)
 			&& abs($moduleSize - $stateCount[3]) < $maxVariance
 			&& abs($moduleSize - $stateCount[4]) < $maxVariance;
 	}
@@ -257,7 +257,7 @@ final class FinderPatternFinder{
 		// Start counting up, left from center finding black center mass
 		$i = 0;
 
-		while($centerI >= $i && $centerJ >= $i && $this->matrix->check($centerJ - $i, $centerI - $i)){
+		while($centerI >= $i && $centerJ >= $i && $this->matrix->check(($centerJ - $i), ($centerI - $i))){
 			$stateCount[2]++;
 			$i++;
 		}
@@ -267,7 +267,7 @@ final class FinderPatternFinder{
 		}
 
 		// Continue up, left finding white space
-		while($centerI >= $i && $centerJ >= $i && !$this->matrix->check($centerJ - $i, $centerI - $i)){
+		while($centerI >= $i && $centerJ >= $i && !$this->matrix->check(($centerJ - $i), ($centerI - $i))){
 			$stateCount[1]++;
 			$i++;
 		}
@@ -277,7 +277,7 @@ final class FinderPatternFinder{
 		}
 
 		// Continue up, left finding black border
-		while($centerI >= $i && $centerJ >= $i && $this->matrix->check($centerJ - $i, $centerI - $i)){
+		while($centerI >= $i && $centerJ >= $i && $this->matrix->check(($centerJ - $i), ($centerI - $i))){
 			$stateCount[0]++;
 			$i++;
 		}
@@ -290,12 +290,12 @@ final class FinderPatternFinder{
 
 		// Now also count down, right from center
 		$i = 1;
-		while($centerI + $i < $dimension && $centerJ + $i < $dimension && $this->matrix->check($centerJ + $i, $centerI + $i)){
+		while(($centerI + $i) < $dimension && ($centerJ + $i) < $dimension && $this->matrix->check(($centerJ + $i), ($centerI + $i))){
 			$stateCount[2]++;
 			$i++;
 		}
 
-		while($centerI + $i < $dimension && $centerJ + $i < $dimension && !$this->matrix->check($centerJ + $i, $centerI + $i)){
+		while(($centerI + $i) < $dimension && ($centerJ + $i) < $dimension && !$this->matrix->check(($centerJ + $i), ($centerI + $i))){
 			$stateCount[3]++;
 			$i++;
 		}
@@ -304,7 +304,7 @@ final class FinderPatternFinder{
 			return false;
 		}
 
-		while($centerI + $i < $dimension && $centerJ + $i < $dimension && $this->matrix->check($centerJ + $i, $centerI + $i)){
+		while(($centerI + $i) < $dimension && ($centerJ + $i) < $dimension && $this->matrix->check(($centerJ + $i), ($centerI + $i))){
 			$stateCount[4]++;
 			$i++;
 		}
@@ -365,7 +365,7 @@ final class FinderPatternFinder{
 		}
 
 		// Now also count down from center
-		$i = $startI + 1;
+		$i = ($startI + 1);
 		while($i < $maxI && $this->matrix->check($centerJ, $i)){
 			$stateCount[2]++;
 			$i++;
@@ -395,9 +395,9 @@ final class FinderPatternFinder{
 
 		// If we found a finder-pattern-like section, but its size is more than 40% different from
 		// the original, assume it's a false positive
-		$stateCountTotal = $stateCount[0] + $stateCount[1] + $stateCount[2] + $stateCount[3] + $stateCount[4];
+		$stateCountTotal = ($stateCount[0] + $stateCount[1] + $stateCount[2] + $stateCount[3] + $stateCount[4]);
 
-		if(5 * abs($stateCountTotal - $originalStateCountTotal) >= 2 * $originalStateCountTotal){
+		if((5 * abs($stateCountTotal - $originalStateCountTotal)) >= (2 * $originalStateCountTotal)){
 			return null;
 		}
 
@@ -446,7 +446,7 @@ final class FinderPatternFinder{
 			return null;
 		}
 
-		$j = $startJ + 1;
+		$j = ($startJ + 1);
 		while($j < $maxJ && $this->matrix->check($j, $centerI)){
 			$stateCount[2]++;
 			$j++;
@@ -476,9 +476,9 @@ final class FinderPatternFinder{
 
 		// If we found a finder-pattern-like section, but its size is significantly different from
 		// the original, assume it's a false positive
-		$stateCountTotal = $stateCount[0] + $stateCount[1] + $stateCount[2] + $stateCount[3] + $stateCount[4];
+		$stateCountTotal = ($stateCount[0] + $stateCount[1] + $stateCount[2] + $stateCount[3] + $stateCount[4]);
 
-		if(5 * abs($stateCountTotal - $originalStateCountTotal) >= $originalStateCountTotal){
+		if((5 * abs($stateCountTotal - $originalStateCountTotal)) >= $originalStateCountTotal){
 			return null;
 		}
 
@@ -508,7 +508,7 @@ final class FinderPatternFinder{
 	 * @return bool if a finder pattern candidate was found this time
 	 */
 	private function handlePossibleCenter(array $stateCount, int $i, int $j):bool{
-		$stateCountTotal = $stateCount[0] + $stateCount[1] + $stateCount[2] + $stateCount[3] + $stateCount[4];
+		$stateCountTotal = ($stateCount[0] + $stateCount[1] + $stateCount[2] + $stateCount[3] + $stateCount[4]);
 		$centerJ         = $this->centerFromEnd($stateCount, $j);
 		$centerI         = $this->crossCheckVertical($i, (int)$centerJ, $stateCount[2], $stateCountTotal);
 
@@ -516,10 +516,13 @@ final class FinderPatternFinder{
 			// Re-cross check
 			$centerJ = $this->crossCheckHorizontal((int)$centerJ, (int)$centerI, $stateCount[2], $stateCountTotal);
 			if($centerJ !== null && ($this->crossCheckDiagonal((int)$centerI, (int)$centerJ))){
-				$estimatedModuleSize = $stateCountTotal / 7.0;
+				$estimatedModuleSize = ($stateCountTotal / 7.0);
 				$found               = false;
 
-				for($index = 0; $index < count($this->possibleCenters); $index++){
+				// cautious (was in for fool in which $this->possibleCenters is updated)
+				$count = count($this->possibleCenters);
+
+				for($index = 0; $index < $count; $index++){
 					$center = $this->possibleCenters[$index];
 					// Look for about the same center and module size:
 					if($center->aboutEquals($estimatedModuleSize, $centerI, $centerJ)){
@@ -604,14 +607,14 @@ final class FinderPatternFinder{
 		// and that we need to keep looking. We detect this by asking if the estimated module sizes
 		// vary too much. We arbitrarily say that when the total deviation from average exceeds
 		// 5% of the total module size estimates, it's too much.
-		$average        = $totalModuleSize / (float)$max;
+		$average        = ($totalModuleSize / (float)$max);
 		$totalDeviation = 0.0;
 
 		foreach($this->possibleCenters as $pattern){
 			$totalDeviation += abs($pattern->getEstimatedModuleSize() - $average);
 		}
 
-		return $totalDeviation <= 0.05 * $totalModuleSize;
+		return $totalDeviation <= (0.05 * $totalModuleSize);
 	}
 
 	/**
@@ -629,26 +632,26 @@ 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;
 		$bestPatterns = [];
 
-		for($i = 0; $i < $startSize - 2; $i++){
+		for($i = 0; $i < ($startSize - 2); $i++){
 			$fpi           = $this->possibleCenters[$i];
 			$minModuleSize = $fpi->getEstimatedModuleSize();
 
-			for($j = $i + 1; $j < $startSize - 1; $j++){
+			for($j = ($i + 1); $j < ($startSize - 1); $j++){
 				$fpj      = $this->possibleCenters[$j];
 				$squares0 = $fpi->getSquaredDistance($fpj);
 
-				for($k = $j + 1; $k < $startSize; $k++){
+				for($k = ($j + 1); $k < $startSize; $k++){
 					$fpk           = $this->possibleCenters[$k];
 					$maxModuleSize = $fpk->getEstimatedModuleSize();
 
 					// module size is not similar
-					if($maxModuleSize > $minModuleSize * 1.4){
+					if($maxModuleSize > ($minModuleSize * 1.4)){
 						continue;
 					}
 
@@ -698,7 +701,7 @@ final class FinderPatternFinder{
 					// we need to check both two equal sides separately.
 					// The value of |c^2 - 2 * b^2| + |c^2 - 2 * a^2| increases as dissimilarity
 					// from isosceles right triangle.
-					$d = abs($c - 2 * $b) + abs($c - 2 * $a);
+					$d = (abs($c - 2 * $b) + abs($c - 2 * $a));
 
 					if($d < $distortion){
 						$distortion   = $d;
@@ -761,7 +764,7 @@ final class FinderPatternFinder{
 		$bX = $pointB->getX();
 		$bY = $pointB->getY();
 
-		return (($pointC->getX() - $bX) * ($pointA->getY() - $bY)) - (($pointC->getY() - $bY) * ($pointA->getX() - $bX));
+		return ((($pointC->getX() - $bX) * ($pointA->getY() - $bY)) - (($pointC->getY() - $bY) * ($pointA->getX() - $bX)));
 	}
 
 }

+ 18 - 13
src/Detector/GridSampler.php

@@ -55,7 +55,7 @@ final class GridSampler{
 		// Check and nudge points from start until we see some that are OK:
 		for($offset = 0; $offset < $max && $nudged; $offset += 2){
 			$x = (int)$points[$offset];
-			$y = (int)$points[$offset + 1];
+			$y = (int)$points[($offset + 1)];
 
 			if($x < -1 || $x > $dimension || $y < -1 || $y > $dimension){
 				throw new QRCodeDetectorException(sprintf('checkAndNudgePoints 1, x: %s, y: %s, d: %s', $x, $y, $dimension));
@@ -68,24 +68,27 @@ final class GridSampler{
 				$nudged          = true;
 			}
 			elseif($x === $dimension){
-				$points[$offset] = $dimension - 1;
+				$points[$offset] = ($dimension - 1);
 				$nudged          = true;
 			}
+
 			if($y === -1){
-				$points[$offset + 1] = 0.0;
-				$nudged              = true;
+				$points[($offset + 1)] = 0.0;
+				$nudged                = true;
 			}
 			elseif($y === $dimension){
-				$points[$offset + 1] = $dimension - 1;
-				$nudged              = true;
+				$points[($offset + 1)] = ($dimension - 1);
+				$nudged                = true;
 			}
+
 		}
 		// Check and nudge points from end:
 		$nudged = true;
+		$offset = (count($points) - 2);
 
-		for($offset = count($points) - 2; $offset >= 0 && $nudged; $offset -= 2){
+		for(; $offset >= 0 && $nudged; $offset -= 2){
 			$x = (int)$points[$offset];
-			$y = (int)$points[$offset + 1];
+			$y = (int)$points[($offset + 1)];
 
 			if($x < -1 || $x > $dimension || $y < -1 || $y > $dimension){
 				throw new QRCodeDetectorException(sprintf('checkAndNudgePoints 2, x: %s, y: %s, d: %s', $x, $y, $dimension));
@@ -98,17 +101,19 @@ final class GridSampler{
 				$nudged          = true;
 			}
 			elseif($x === $dimension){
-				$points[$offset] = $dimension - 1;
+				$points[$offset] = ($dimension - 1);
 				$nudged          = true;
 			}
+
 			if($y === -1){
-				$points[$offset + 1] = 0.0;
-				$nudged              = true;
+				$points[($offset + 1)] = 0.0;
+				$nudged                = true;
 			}
 			elseif($y === $dimension){
-				$points[$offset + 1] = $dimension - 1;
-				$nudged              = true;
+				$points[($offset + 1)] = ($dimension - 1);
+				$nudged                = true;
 			}
+
 		}
 	}
 

+ 45 - 41
src/Detector/PerspectiveTransform.php

@@ -84,15 +84,15 @@ final class PerspectiveTransform{
 	private function buildAdjoint():self{
 		// Adjoint is the transpose of the cofactor matrix:
 		return $this->set(
-			$this->a22 * $this->a33 - $this->a23 * $this->a32,
-			$this->a23 * $this->a31 - $this->a21 * $this->a33,
-			$this->a21 * $this->a32 - $this->a22 * $this->a31,
-			$this->a13 * $this->a32 - $this->a12 * $this->a33,
-			$this->a11 * $this->a33 - $this->a13 * $this->a31,
-			$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->a22 * $this->a33 - $this->a23 * $this->a32),
+			($this->a23 * $this->a31 - $this->a21 * $this->a33),
+			($this->a21 * $this->a32 - $this->a22 * $this->a31),
+			($this->a13 * $this->a32 - $this->a12 * $this->a33),
+			($this->a11 * $this->a33 - $this->a13 * $this->a31),
+			($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)
 		);
 	}
 
@@ -103,26 +103,32 @@ final class PerspectiveTransform{
 		float $x0, float $y0, float $x1, float $y1,
 		float $x2, float $y2, float $x3, float $y3
 	):self{
-		$dx3 = $x0 - $x1 + $x2 - $x3;
-		$dy3 = $y0 - $y1 + $y2 - $y3;
+		$dx3 = ($x0 - $x1 + $x2 - $x3);
+		$dy3 = ($y0 - $y1 + $y2 - $y3);
 
 		if($dx3 === 0.0 && $dy3 === 0.0){
 			// Affine
-			return $this->set($x1 - $x0, $x2 - $x1, $x0, $y1 - $y0, $y2 - $y1, $y0, 0.0, 0.0, 1.0);
+			return $this->set(($x1 - $x0), ($x2 - $x1), $x0, ($y1 - $y0), ($y2 - $y1), $y0, 0.0, 0.0, 1.0);
 		}
 
-		$dx1         = $x1 - $x2;
-		$dx2         = $x3 - $x2;
-		$dy1         = $y1 - $y2;
-		$dy2         = $y3 - $y2;
-		$denominator = $dx1 * $dy2 - $dx2 * $dy1;
-		$a13         = ($dx3 * $dy2 - $dx2 * $dy3) / $denominator;
-		$a23         = ($dx1 * $dy3 - $dx3 * $dy1) / $denominator;
+		$dx1         = ($x1 - $x2);
+		$dx2         = ($x3 - $x2);
+		$dy1         = ($y1 - $y2);
+		$dy2         = ($y3 - $y2);
+		$denominator = ($dx1 * $dy2 - $dx2 * $dy1);
+		$a13         = (($dx3 * $dy2 - $dx2 * $dy3) / $denominator);
+		$a23         = (($dx1 * $dy3 - $dx3 * $dy1) / $denominator);
 
 		return $this->set(
-			$x1 - $x0 + $a13 * $x1, $x3 - $x0 + $a23 * $x3, $x0,
-			$y1 - $y0 + $a13 * $y1, $y3 - $y0 + $a23 * $y3, $y0,
-			$a13, $a23, 1.0
+			($x1 - $x0 + $a13 * $x1),
+			($x3 - $x0 + $a23 * $x3),
+			$x0,
+			($y1 - $y0 + $a13 * $y1),
+			($y3 - $y0 + $a23 * $y3),
+			$y0,
+			$a13,
+			$a23,
+			1.0
 		);
 	}
 
@@ -131,15 +137,15 @@ final class PerspectiveTransform{
 	 */
 	private function times(PerspectiveTransform $other):self{
 		return $this->set(
-			$this->a11 * $other->a11 + $this->a21 * $other->a12 + $this->a31 * $other->a13,
-			$this->a11 * $other->a21 + $this->a21 * $other->a22 + $this->a31 * $other->a23,
-			$this->a11 * $other->a31 + $this->a21 * $other->a32 + $this->a31 * $other->a33,
-			$this->a12 * $other->a11 + $this->a22 * $other->a12 + $this->a32 * $other->a13,
-			$this->a12 * $other->a21 + $this->a22 * $other->a22 + $this->a32 * $other->a23,
-			$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->a11 * $other->a11 + $this->a21 * $other->a12 + $this->a31 * $other->a13),
+			($this->a11 * $other->a21 + $this->a21 * $other->a22 + $this->a31 * $other->a23),
+			($this->a11 * $other->a31 + $this->a21 * $other->a32 + $this->a31 * $other->a33),
+			($this->a12 * $other->a11 + $this->a22 * $other->a12 + $this->a32 * $other->a13),
+			($this->a12 * $other->a21 + $this->a22 * $other->a22 + $this->a32 * $other->a23),
+			($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)
 		);
 	}
 
@@ -149,27 +155,25 @@ final class PerspectiveTransform{
 	public function transformPoints(array &$xValues, array &$yValues = null):void{
 		$max = count($xValues);
 
-		// @codeCoverageIgnoreStart (unused)
 		if($yValues !== null){
 
 			for($i = 0; $i < $max; $i++){
 				$x           = $xValues[$i];
 				$y           = $yValues[$i];
-				$denominator = $this->a13 * $x + $this->a23 * $y + $this->a33;
-				$xValues[$i] = ($this->a11 * $x + $this->a21 * $y + $this->a31) / $denominator;
-				$yValues[$i] = ($this->a12 * $x + $this->a22 * $y + $this->a32) / $denominator;
+				$denominator = ($this->a13 * $x + $this->a23 * $y + $this->a33);
+				$xValues[$i] = (($this->a11 * $x + $this->a21 * $y + $this->a31) / $denominator);
+				$yValues[$i] = (($this->a12 * $x + $this->a22 * $y + $this->a32) / $denominator);
 			}
 
 			return;
 		}
-		// @codeCoverageIgnoreEnd
 
 		for($i = 0; $i < $max; $i += 2){
-			$x               = $xValues[$i];
-			$y               = $xValues[$i + 1];
-			$denominator     = $this->a13 * $x + $this->a23 * $y + $this->a33;
-			$xValues[$i]     = ($this->a11 * $x + $this->a21 * $y + $this->a31) / $denominator;
-			$xValues[$i + 1] = ($this->a12 * $x + $this->a22 * $y + $this->a32) / $denominator;
+			$x                 = $xValues[$i];
+			$y                 = $xValues[($i + 1)];
+			$denominator       = ($this->a13 * $x + $this->a23 * $y + $this->a33);
+			$xValues[$i]       = (($this->a11 * $x + $this->a21 * $y + $this->a31) / $denominator);
+			$xValues[($i + 1)] = (($this->a12 * $x + $this->a22 * $y + $this->a32) / $denominator);
 		}
 	}
 

+ 6 - 1
src/Detector/QRCodeDetectorException.php

@@ -12,4 +12,9 @@ namespace chillerlan\QRCode\Detector;
 
 use chillerlan\QRCode\QRCodeException;
 
-final class QRCodeDetectorException extends QRCodeException{}
+/**
+ * An exception container
+ */
+final class QRCodeDetectorException extends QRCodeException{
+
+}

+ 6 - 1
src/Output/QRCodeOutputException.php

@@ -12,4 +12,9 @@ namespace chillerlan\QRCode\Output;
 
 use chillerlan\QRCode\QRCodeException;
 
-final class QRCodeOutputException extends QRCodeException{}
+/**
+ * An exception container
+ */
+final class QRCodeOutputException extends QRCodeException{
+
+}

+ 6 - 6
src/Output/QREps.php

@@ -49,7 +49,7 @@ class QREps extends QROutputAbstract{
 
 		for($i = 0; $i < 3; $i++){
 			// clamp value and convert from 0-255 to 0-1 RGB range
-			$val[] = round(max(0, min(255, $value[$i])) / 255, 6);
+			$val[] = round((max(0, min(255, $value[$i])) / 255), 6);
 		}
 
 		return $val;
@@ -59,7 +59,7 @@ class QREps extends QROutputAbstract{
 	 * @inheritDoc
 	 */
 	protected function getDefaultModuleValue(bool $isDark):array{
-		return $isDark ? [0.0, 0.0, 0.0] : [1.0, 1.0, 1.0];
+		return ($isDark) ? [0.0, 0.0, 0.0] : [1.0, 1.0, 1.0];
 	}
 
 	/**
@@ -81,7 +81,7 @@ class QREps extends QROutputAbstract{
 			'%%BeginProlog',
 			'/F { rectfill } def',
 			'/S { setrgbcolor } def',
-			'%%EndProlog'
+			'%%EndProlog',
 		];
 
 		// create the path elements
@@ -116,11 +116,11 @@ class QREps extends QROutputAbstract{
 			return '';
 		}
 
-		$outputX = $x * $this->scale;
+		$outputX = ($x * $this->scale);
 		// Actual size - one block = Topmost y pos.
-		$top     = $this->length - $this->scale;
+		$top     = ($this->length - $this->scale);
 		// Apparently y-axis is inverted (y0 is at bottom and not top) in EPS, so we have to switch the y-axis here
-		$outputY = $top - ($y * $this->scale);
+		$outputY = ($top - ($y * $this->scale));
 
 		return sprintf('%d %d %d %d F', $outputX, $outputY, $this->scale, $this->scale);
 	}

+ 2 - 2
src/Output/QRFpdf.php

@@ -81,7 +81,7 @@ class QRFpdf extends QROutputAbstract{
 	 * @inheritDoc
 	 */
 	protected function getDefaultModuleValue(bool $isDark):array{
-		return $isDark ? [0, 0, 0] : [255, 255, 255];
+		return ($isDark) ? [0, 0, 0] : [255, 255, 255];
 	}
 
 	/**
@@ -120,7 +120,7 @@ class QRFpdf extends QROutputAbstract{
 					$prevColor = $color;
 				}
 
-				$fpdf->Rect($x * $this->scale, $y * $this->scale, $this->scale, $this->scale, 'F');
+				$fpdf->Rect(($x * $this->scale), ($y * $this->scale), $this->scale, $this->scale, 'F');
 			}
 
 		}

+ 7 - 7
src/Output/QRGdImage.php

@@ -86,7 +86,7 @@ class QRGdImage extends QROutputAbstract{
 	 * @inheritDoc
 	 */
 	protected function getDefaultModuleValue(bool $isDark):array{
-		return $isDark ? [0, 0, 0] : [255, 255, 255];
+		return ($isDark) ? [0, 0, 0] : [255, 255, 255];
 	}
 
 	/**
@@ -106,7 +106,7 @@ class QRGdImage extends QROutputAbstract{
 
 		// we're scaling the image up in order to draw crisp round circles, otherwise they appear square-y on small scales
 		if($this->options->drawCircularModules && $this->options->scale <= 20){
-			$this->length  = ($this->length + 2) * 10;
+			$this->length  = (($this->length + 2) * 10);
 			$this->scale  *= 10;
 		}
 
@@ -143,7 +143,7 @@ class QRGdImage extends QROutputAbstract{
 
 		// scale down to the expected size
 		if($this->options->drawCircularModules && $this->options->scale <= 20){
-			$this->image = imagescale($this->image, $this->length/10, $this->length/10, IMG_BILINEAR_FIXED);
+			$this->image = imagescale($this->image, ($this->length / 10), ($this->length / 10), IMG_BILINEAR_FIXED);
 		}
 
 		if($this->options->returnResource){
@@ -183,10 +183,10 @@ class QRGdImage extends QROutputAbstract{
 			)
 			: imagefilledrectangle(
 				$this->image,
-				$x * $this->scale,
-				$y * $this->scale,
-				($x + 1) * $this->scale,
-				($y + 1) * $this->scale,
+				($x * $this->scale),
+				($y * $this->scale),
+				(($x + 1) * $this->scale),
+				(($y + 1) * $this->scale),
 				$color
 			);
 	}

+ 15 - 11
src/Output/QRImagick.php

@@ -40,6 +40,10 @@ class QRImagick extends QROutputAbstract{
 			throw new QRCodeOutputException('ext-imagick not loaded'); // @codeCoverageIgnore
 		}
 
+		if(!extension_loaded('fileinfo')){
+			throw new QRCodeOutputException('ext-fileinfo not loaded'); // @codeCoverageIgnore
+		}
+
 		parent::__construct($options, $matrix);
 	}
 
@@ -61,7 +65,7 @@ class QRImagick extends QROutputAbstract{
 	 * @inheritDoc
 	 */
 	protected function getDefaultModuleValue(bool $isDark):ImagickPixel{
-		return new ImagickPixel($isDark ? $this->options->markupDark : $this->options->markupLight);
+		return new ImagickPixel(($isDark) ? $this->options->markupDark : $this->options->markupLight);
 	}
 
 	/**
@@ -72,11 +76,11 @@ class QRImagick extends QROutputAbstract{
 	public function dump(string $file = null){
 		$this->imagick = new Imagick;
 
-		$bgColor = $this->options->imageTransparent ? 'transparent' : 'white';
+		$bgColor = ($this->options->imageTransparent) ? 'transparent' : 'white';
 
 		// keep the imagickBG property for now (until v6)
 		if($this->moduleValueIsValid($this->options->bgColor ?? $this->options->imagickBG)){
-			$bgColor = $this->options->bgColor ?? $this->options->imagickBG;
+			$bgColor = ($this->options->bgColor ?? $this->options->imagickBG);
 		}
 
 		$this->imagick->newImage($this->length, $this->length, new ImagickPixel($bgColor), $this->options->imagickFormat);
@@ -129,16 +133,16 @@ class QRImagick extends QROutputAbstract{
 
 		$this->options->drawCircularModules && !$this->matrix->checkTypeIn($x, $y, $this->options->keepAsSquare)
 			? $this->imagickDraw->circle(
-				($x + 0.5) * $this->scale,
-				($y + 0.5) * $this->scale,
-				($x + 0.5 + $this->options->circleRadius) * $this->scale,
-				($y + 0.5) * $this->scale
+				(($x + 0.5) * $this->scale),
+				(($y + 0.5) * $this->scale),
+				(($x + 0.5 + $this->options->circleRadius) * $this->scale),
+				(($y + 0.5) * $this->scale)
 			)
 			: $this->imagickDraw->rectangle(
-				$x * $this->scale,
-				$y * $this->scale,
-				($x + 1) * $this->scale,
-				($y + 1) * $this->scale
+				($x * $this->scale),
+				($y * $this->scale),
+				(($x + 1) * $this->scale),
+				(($y + 1) * $this->scale)
 			);
 	}
 

+ 1 - 1
src/Output/QRMarkup.php

@@ -35,7 +35,7 @@ abstract class QRMarkup extends QROutputAbstract{
 	 * @inheritDoc
 	 */
 	protected function getDefaultModuleValue(bool $isDark):string{
-		return $isDark ? $this->options->markupDark : $this->options->markupLight;
+		return ($isDark) ? $this->options->markupDark : $this->options->markupLight;
 	}
 
 	/**

+ 5 - 5
src/Output/QRMarkupSVG.php

@@ -50,15 +50,15 @@ class QRMarkupSVG extends QRMarkup{
 	 * returns the <svg> header with the given options parsed
 	 */
 	protected function header():string{
-		$width  = $this->options->svgWidth !== null ? sprintf(' width="%s"', $this->options->svgWidth) : '';
-		$height = $this->options->svgHeight !== null ? sprintf(' height="%s"', $this->options->svgHeight) : '';
+		$width  = ($this->options->svgWidth !== null) ? sprintf(' width="%s"', $this->options->svgWidth) : '';
+		$height = ($this->options->svgHeight !== null) ? sprintf(' height="%s"', $this->options->svgHeight) : '';
 
 		/** @noinspection HtmlUnknownAttribute */
 		return sprintf(
 			'<?xml version="1.0" encoding="UTF-8"?>%6$s'.
 			'<svg xmlns="http://www.w3.org/2000/svg" class="qr-svg %1$s" viewBox="0 0 %2$s %2$s" preserveAspectRatio="%3$s"%4$s%5$s>%6$s',
 			$this->options->cssClass,
-			$this->options->svgViewBoxSize ?? $this->moduleCount,
+			($this->options->svgViewBoxSize ?? $this->moduleCount),
 			$this->options->svgPreserveAspectRatio,
 			$width,
 			$height,
@@ -110,7 +110,7 @@ class QRMarkupSVG extends QRMarkup{
 			$format,
 			$this->getCssClass($M_TYPE),
 			$path,
-			$this->moduleValues[$M_TYPE] ?? '', // value may or may not exist
+			($this->moduleValues[$M_TYPE] ?? ''), // value may or may not exist
 			$this->options->svgOpacity
 		);
 	}
@@ -121,7 +121,7 @@ class QRMarkupSVG extends QRMarkup{
 	protected function getCssClass(int $M_TYPE):string{
 		return implode(' ', [
 			'qr-'.$M_TYPE,
-			($M_TYPE & QRMatrix::IS_DARK) === QRMatrix::IS_DARK ? 'dark' : 'light',
+			(($M_TYPE & QRMatrix::IS_DARK) === QRMatrix::IS_DARK) ? 'dark' : 'light',
 			$this->options->cssClass,
 		]);
 	}

+ 2 - 2
src/Output/QROutputAbstract.php

@@ -73,7 +73,7 @@ abstract class QROutputAbstract implements QROutputInterface{
 	protected function setMatrixDimensions():void{
 		$this->moduleCount = $this->matrix->size();
 		$this->scale       = $this->options->scale;
-		$this->length      = $this->moduleCount * $this->scale;
+		$this->length      = ($this->moduleCount * $this->scale);
 	}
 
 	/**
@@ -82,7 +82,7 @@ abstract class QROutputAbstract implements QROutputInterface{
 	protected function setModuleValues():void{
 
 		foreach($this::DEFAULT_MODULE_VALUES as $M_TYPE => $defaultValue){
-			$value = $this->options->moduleValues[$M_TYPE] ?? null;
+			$value = ($this->options->moduleValues[$M_TYPE] ?? null);
 
 			$this->moduleValues[$M_TYPE] = $this->moduleValueIsValid($value)
 				? $this->getModuleValue($value)

+ 33 - 33
src/Output/QROutputInterface.php

@@ -18,34 +18,34 @@ use chillerlan\QRCode\Data\QRMatrix;
 interface QROutputInterface{
 
 	/** @var string */
-	const MARKUP_HTML = 'html';
+	public const MARKUP_HTML = 'html';
 	/** @var string */
-	const MARKUP_SVG  = 'svg';
+	public const MARKUP_SVG  = 'svg';
 	/** @var string */
-	const GDIMAGE_PNG = 'png';
+	public const GDIMAGE_PNG = 'png';
 	/** @var string */
-	const GDIMAGE_JPG = 'jpg';
+	public const GDIMAGE_JPG = 'jpg';
 	/** @var string */
-	const GDIMAGE_GIF = 'gif';
+	public const GDIMAGE_GIF = 'gif';
 	/** @var string */
-	const STRING_JSON = 'json';
+	public const STRING_JSON = 'json';
 	/** @var string */
-	const STRING_TEXT = 'text';
+	public const STRING_TEXT = 'text';
 	/** @var string */
-	const IMAGICK     = 'imagick';
+	public const IMAGICK     = 'imagick';
 	/** @var string */
-	const FPDF        = 'fpdf';
+	public const FPDF        = 'fpdf';
 	/** @var string */
-	const EPS         = 'eps';
+	public const EPS         = 'eps';
 	/** @var string */
-	const CUSTOM      = 'custom';
+	public const CUSTOM      = 'custom';
 
 	/**
 	 * Map of built-in output modes => modules
 	 *
 	 * @var string[]
 	 */
-	const MODES = [
+	public const MODES = [
 		self::MARKUP_SVG  => QRMarkupSVG::class,
 		self::MARKUP_HTML => QRMarkupHTML::class,
 		self::GDIMAGE_PNG => QRGdImage::class,
@@ -61,29 +61,29 @@ interface QROutputInterface{
 	/**
 	 * @var bool[]
 	 */
-	const DEFAULT_MODULE_VALUES = [
+	public const DEFAULT_MODULE_VALUES = [
 		// light
-		QRMatrix::M_NULL                           => false,
-		QRMatrix::M_DATA                           => false,
-		QRMatrix::M_FINDER                         => false,
-		QRMatrix::M_SEPARATOR                      => false,
-		QRMatrix::M_ALIGNMENT                      => false,
-		QRMatrix::M_TIMING                         => false,
-		QRMatrix::M_FORMAT                         => false,
-		QRMatrix::M_VERSION                        => false,
-		QRMatrix::M_QUIETZONE                      => false,
-		QRMatrix::M_LOGO                           => false,
-		QRMatrix::M_TEST                           => false,
+		QRMatrix::M_NULL                             => false,
+		QRMatrix::M_DATA                             => false,
+		QRMatrix::M_FINDER                           => false,
+		QRMatrix::M_SEPARATOR                        => false,
+		QRMatrix::M_ALIGNMENT                        => false,
+		QRMatrix::M_TIMING                           => false,
+		QRMatrix::M_FORMAT                           => false,
+		QRMatrix::M_VERSION                          => false,
+		QRMatrix::M_QUIETZONE                        => false,
+		QRMatrix::M_LOGO                             => false,
+		QRMatrix::M_TEST                             => false,
 		// dark
-		QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK => true,
-		QRMatrix::M_DATA | QRMatrix::IS_DARK       => true,
-		QRMatrix::M_FINDER | QRMatrix::IS_DARK     => true,
-		QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK  => true,
-		QRMatrix::M_TIMING | QRMatrix::IS_DARK     => true,
-		QRMatrix::M_FORMAT | QRMatrix::IS_DARK     => true,
-		QRMatrix::M_VERSION | QRMatrix::IS_DARK    => true,
-		QRMatrix::M_FINDER_DOT | QRMatrix::IS_DARK => true,
-		QRMatrix::M_TEST | QRMatrix::IS_DARK       => true,
+		(QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK) => true,
+		(QRMatrix::M_DATA | QRMatrix::IS_DARK)       => true,
+		(QRMatrix::M_FINDER | QRMatrix::IS_DARK)     => true,
+		(QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK)  => true,
+		(QRMatrix::M_TIMING | QRMatrix::IS_DARK)     => true,
+		(QRMatrix::M_FORMAT | QRMatrix::IS_DARK)     => true,
+		(QRMatrix::M_VERSION | QRMatrix::IS_DARK)    => true,
+		(QRMatrix::M_FINDER_DOT | QRMatrix::IS_DARK) => true,
+		(QRMatrix::M_TEST | QRMatrix::IS_DARK)       => true,
 	];
 
 	/**

+ 1 - 1
src/Output/QRString.php

@@ -38,7 +38,7 @@ class QRString extends QROutputAbstract{
 	 * @inheritDoc
 	 */
 	protected function getDefaultModuleValue(bool $isDark):string{
-		return $isDark ? $this->options->textDark : $this->options->textLight;
+		return ($isDark) ? $this->options->textDark : $this->options->textLight;
 	}
 
 	/**

+ 3 - 3
src/QRCode.php

@@ -179,7 +179,7 @@ class QRCode{
 	 * QRCode constructor.
 	 */
 	public function __construct(SettingsContainerInterface $options = null){
-		$this->setOptions($options ?? new QROptions);
+		$this->setOptions(($options ?? new QROptions));
 	}
 
 	/**
@@ -246,7 +246,7 @@ class QRCode{
 
 			// check whether one of the dimensions was omitted
 			if($logoSpaceWidth === null || $logoSpaceHeight === null){
-				$logoSpaceWidth  = $logoSpaceWidth ?? $logoSpaceHeight ?? 0;
+				$logoSpaceWidth  = ($logoSpaceWidth ?? $logoSpaceHeight ?? 0);
 				$logoSpaceHeight = null;
 			}
 
@@ -271,7 +271,7 @@ class QRCode{
 	 * @throws \chillerlan\QRCode\Output\QRCodeOutputException
 	 */
 	protected function initOutputInterface(QRMatrix $matrix):QROutputInterface{
-		$outputInterface = QROutputInterface::MODES[$this->options->outputType] ?? null;
+		$outputInterface =( QROutputInterface::MODES[$this->options->outputType] ?? null);
 
 		if($this->options->outputType === QROutputInterface::CUSTOM){
 			$outputInterface = $this->options->outputInterface;

+ 3 - 1
src/QRCodeException.php

@@ -15,4 +15,6 @@ use Exception;
 /**
  * An exception container
  */
-class QRCodeException extends Exception{}
+class QRCodeException extends Exception{
+
+}

+ 2 - 2
src/QROptionsTrait.php

@@ -389,7 +389,7 @@ trait QROptionsTrait{
 	 * sets/clamps the version number
 	 */
 	protected function set_version(int $version):void{
-		$this->version = $version !== Version::AUTO ? max(1, min(40, $version)) : Version::AUTO;
+		$this->version = ($version !== Version::AUTO) ? max(1, min(40, $version)) : Version::AUTO;
 	}
 
 	/**
@@ -451,7 +451,7 @@ trait QROptionsTrait{
 	 * enables Imagick for the QR Code reader if the extension is available
 	 */
 	protected function set_readerUseImagickIfAvailable(bool $useImagickIfAvailable):void{
-		$this->readerUseImagickIfAvailable = $useImagickIfAvailable && extension_loaded('imagick');
+		$this->readerUseImagickIfAvailable = ($useImagickIfAvailable && extension_loaded('imagick'));
 	}
 
 	/**

+ 2 - 2
tests/Common/EccLevelTest.php

@@ -23,8 +23,8 @@ final class EccLevelTest extends TestCase{
 	public function testConstructInvalidEccException():void{
 		$this->expectException(QRCodeException::class);
 		$this->expectExceptionMessage('invalid ECC level');
-
-		$ecc = new EccLevel(69);
+		/** @phan-suppress-next-line PhanNoopNew */
+		new EccLevel(69);
 	}
 
 	public function testToString():void{

+ 4 - 2
tests/Common/MaskPatternTest.php

@@ -7,6 +7,8 @@
  * @author       smiley <smiley@chillerlan.net>
  * @copyright    2021 smiley
  * @license      Apache-2.0
+ *
+ * @codingStandardsIgnoreFile Squiz.Arrays.ArrayDeclaration.NoCommaAfterLast
  */
 
 namespace chillerlan\QRCodeTest\Common;
@@ -121,8 +123,8 @@ final class MaskPatternTest extends TestCase{
 	public function testInvalidMaskPatternException():void{
 		$this->expectException(QRCodeException::class);
 		$this->expectExceptionMessage('invalid mask pattern');
-
-		$maskPattern = new MaskPattern(42);
+		/** @phan-suppress-next-line PhanNoopNew */
+		new MaskPattern(42);
 	}
 
 	public function testPenaltyRule1():void{

+ 6 - 6
tests/Common/ModeTest.php

@@ -43,22 +43,22 @@ final class ModeTest extends TestCase{
 	public function testGetLengthBitsForVersionInvalidModeException():void{
 		$this->expectException(QRCodeException::class);
 		$this->expectExceptionMessage('invalid mode given');
-
-		$bits = Mode::getLengthBitsForVersion(42, 69);
+		/** @phan-suppress-next-line PhanNoopNew */
+		Mode::getLengthBitsForVersion(42, 69);
 	}
 
 	public function testGetLengthBitsForVersionInvalidVersionException():void{
 		$this->expectException(QRCodeException::class);
 		$this->expectExceptionMessage('invalid version number');
-
-		$bits = Mode::getLengthBitsForVersion(Mode::BYTE, 69);
+		/** @phan-suppress-next-line PhanNoopNew */
+		Mode::getLengthBitsForVersion(Mode::BYTE, 69);
 	}
 
 	public function testGetLengthBitsForModeInvalidModeException():void{
 		$this->expectException(QRCodeException::class);
 		$this->expectExceptionMessage('invalid mode given');
-
-		$bits = Mode::getLengthBitsForMode(42);
+		/** @phan-suppress-next-line PhanNoopNew */
+		Mode::getLengthBitsForMode(42);
 	}
 
 }

+ 2 - 2
tests/Common/VersionTest.php

@@ -59,8 +59,8 @@ final class VersionTest extends TestCase{
 	public function testConstructInvalidVersion():void{
 		$this->expectException(QRCodeException::class);
 		$this->expectExceptionMessage('invalid version given');
-
-		$version = new Version(69);
+		/** @phan-suppress-next-line PhanNoopNew */
+		new Version(69);
 	}
 
 }

+ 1 - 5
tests/Data/DataInterfaceTestAbstract.php

@@ -13,7 +13,7 @@ namespace chillerlan\QRCodeTest\Data;
 use chillerlan\QRCode\Common\{MaskPattern, Version};
 use chillerlan\QRCode\QROptions;
 use PHPUnit\Framework\TestCase;
-use chillerlan\QRCode\Data\{Hanzi, QRCodeDataException, QRData, QRDataModeInterface, QRMatrix};
+use chillerlan\QRCode\Data\{QRCodeDataException, QRData, QRDataModeInterface, QRMatrix};
 use ReflectionClass;
 
 use function hex2bin;
@@ -133,10 +133,6 @@ abstract class DataInterfaceTestAbstract extends TestCase{
 		$bitBuffer = $this->QRData->getBitBuffer();
 		// read the first 4 bits
 		$this::assertSame($datamodeInterface->getDataMode(), $bitBuffer->read(4));
-		// hanzi mode starts with a subset indicator
-		if($datamodeInterface instanceof Hanzi){
-			$this::assertSame(Hanzi::GB2312_SUBSET, $bitBuffer->read(4));
-		}
 		// decode the data
 		/** @noinspection PhpUndefinedMethodInspection */
 		$this::assertSame($this->testdata, $this->FQN::decodeSegment($bitBuffer, $options->version));

+ 1 - 1
tests/Data/QRDataTest.php

@@ -37,7 +37,7 @@ class QRDataTest extends TestCase{
 			17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236,
 			17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236,
 			17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236,
-			17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236
+			17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236,
 		];
 
 		$options     = new QROptions(['version' => 3]);

+ 58 - 53
tests/Data/QRMatrixTest.php

@@ -55,37 +55,37 @@ final class QRMatrixTest extends TestCase{
 			// 🔴 🟠 🟡 🟢 🔵 🟣 ⚫️ ⚪️ 🟤
 			// 🟥 🟧 🟨 🟩 🟦 🟪 ⬛ ⬜ 🟫
 			// finder
-			QRMatrix::M_FINDER | QRMatrix::IS_DARK     => '🟥', // dark (true)
-			QRMatrix::M_FINDER                         => '🔴', // light (false)
-			QRMatrix::M_FINDER_DOT | QRMatrix::IS_DARK => '🟥', // finder dot, dark (true)
+			(QRMatrix::M_FINDER | QRMatrix::IS_DARK)     => '🟥', // dark (true)
+			QRMatrix::M_FINDER                           => '🔴', // light (false)
+			(QRMatrix::M_FINDER_DOT | QRMatrix::IS_DARK) => '🟥', // finder dot, dark (true)
 			// alignment
-			QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK  => '🟧',
-			QRMatrix::M_ALIGNMENT                      => '🟠',
+			(QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK)  => '🟧',
+			QRMatrix::M_ALIGNMENT                        => '🟠',
 			// timing
-			QRMatrix::M_TIMING | QRMatrix::IS_DARK     => '🟨',
-			QRMatrix::M_TIMING                         => '🟡',
+			(QRMatrix::M_TIMING | QRMatrix::IS_DARK)     => '🟨',
+			QRMatrix::M_TIMING                           => '🟡',
 			// format
-			QRMatrix::M_FORMAT | QRMatrix::IS_DARK     => '🟪',
-			QRMatrix::M_FORMAT                         => '🟣',
+			(QRMatrix::M_FORMAT | QRMatrix::IS_DARK)     => '🟪',
+			QRMatrix::M_FORMAT                           => '🟣',
 			// version
-			QRMatrix::M_VERSION | QRMatrix::IS_DARK    => '🟩',
-			QRMatrix::M_VERSION                        => '🟢',
+			(QRMatrix::M_VERSION | QRMatrix::IS_DARK)    => '🟩',
+			QRMatrix::M_VERSION                          => '🟢',
 			// data
-			QRMatrix::M_DATA | QRMatrix::IS_DARK       => '🟦',
-			QRMatrix::M_DATA                           => '🔵',
+			(QRMatrix::M_DATA | QRMatrix::IS_DARK)       => '🟦',
+			QRMatrix::M_DATA                             => '🔵',
 			// darkmodule
-			QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK => '🟫',
+			(QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK) => '🟫',
 			// separator
-			QRMatrix::M_SEPARATOR                      => '⚪️',
+			QRMatrix::M_SEPARATOR                        => '⚪️',
 			// quietzone
-			QRMatrix::M_QUIETZONE                      => '⬜',
+			QRMatrix::M_QUIETZONE                        => '⬜',
 			// logo space
-			QRMatrix::M_LOGO                           => '⬜',
+			QRMatrix::M_LOGO                             => '⬜',
 			// empty
-			QRMatrix::M_NULL                           => '🟤',
+			QRMatrix::M_NULL                             => '🟤',
 			// data
-			QRMatrix::M_TEST | QRMatrix::IS_DARK       => '⬛',
-			QRMatrix::M_TEST                           => '⚫️',
+			(QRMatrix::M_TEST | QRMatrix::IS_DARK)       => '⬛',
+			QRMatrix::M_TEST                             => '⚫️',
 		];
 
 		$out = (new QRString($opt, $matrix))->dump();
@@ -152,7 +152,7 @@ final class QRMatrixTest extends TestCase{
 	 */
 	public function testGetSetCheck():void{
 		$this->matrix->set(10, 10, true, QRMatrix::M_TEST);
-		$this::assertSame(QRMatrix::M_TEST | QRMatrix::IS_DARK, $this->matrix->get(10, 10));
+		$this::assertSame((QRMatrix::M_TEST | QRMatrix::IS_DARK), $this->matrix->get(10, 10));
 		$this::assertTrue($this->matrix->check(10, 10));
 
 		$this->matrix->set(20, 20, false, QRMatrix::M_TEST);
@@ -186,7 +186,7 @@ final class QRMatrixTest extends TestCase{
 
 		$this->dm($matrix);
 
-		$this::assertSame(QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK, $matrix->get(8, $matrix->size() - 8));
+		$this::assertSame((QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK), $matrix->get(8, ($matrix->size() - 8)));
 	}
 
 	/**
@@ -199,9 +199,9 @@ final class QRMatrixTest extends TestCase{
 
 		$this->dm($matrix);
 
-		$this::assertSame(QRMatrix::M_FINDER | QRMatrix::IS_DARK, $matrix->get(0, 0));
-		$this::assertSame(QRMatrix::M_FINDER | QRMatrix::IS_DARK, $matrix->get(0, $matrix->size() - 1));
-		$this::assertSame(QRMatrix::M_FINDER | QRMatrix::IS_DARK, $matrix->get($matrix->size() - 1, 0));
+		$this::assertSame((QRMatrix::M_FINDER | QRMatrix::IS_DARK), $matrix->get(0, 0));
+		$this::assertSame((QRMatrix::M_FINDER | QRMatrix::IS_DARK), $matrix->get(0, ($matrix->size() - 1)));
+		$this::assertSame((QRMatrix::M_FINDER | QRMatrix::IS_DARK), $matrix->get(($matrix->size() - 1), 0));
 	}
 
 	/**
@@ -216,8 +216,8 @@ final class QRMatrixTest extends TestCase{
 
 		$this::assertSame(QRMatrix::M_SEPARATOR, $matrix->get(7, 0));
 		$this::assertSame(QRMatrix::M_SEPARATOR, $matrix->get(0, 7));
-		$this::assertSame(QRMatrix::M_SEPARATOR, $matrix->get(0, $matrix->size() - 8));
-		$this::assertSame(QRMatrix::M_SEPARATOR, $matrix->get($matrix->size() - 8, 0));
+		$this::assertSame(QRMatrix::M_SEPARATOR, $matrix->get(0, ($matrix->size() - 8)));
+		$this::assertSame(QRMatrix::M_SEPARATOR, $matrix->get(($matrix->size() - 8), 0));
 	}
 
 	/**
@@ -245,7 +245,7 @@ final class QRMatrixTest extends TestCase{
 			foreach($alignmentPattern as $px){
 				// skip finder pattern
 				if(!$matrix->checkTypeIn($px, $py, [QRMatrix::M_FINDER, QRMatrix::M_FINDER_DOT])){
-					$this::assertSame(QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK, $matrix->get($px, $py));
+					$this::assertSame((QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK), $matrix->get($px, $py));
 				}
 			}
 		}
@@ -269,12 +269,12 @@ final class QRMatrixTest extends TestCase{
 
 		$size = $matrix->size();
 
-		for($i = 7; $i < $size - 7; $i++){
-			if($i % 2 === 0){
+		for($i = 7; $i < ($size - 7); $i++){
+			if(($i % 2) === 0){
 				// skip alignment pattern
 				if(!$matrix->checkTypeIn(6, $i, [QRMatrix::M_ALIGNMENT])){
-					$this::assertSame(QRMatrix::M_TIMING | QRMatrix::IS_DARK, $matrix->get(6, $i));
-					$this::assertSame(QRMatrix::M_TIMING | QRMatrix::IS_DARK, $matrix->get($i, 6));
+					$this::assertSame((QRMatrix::M_TIMING | QRMatrix::IS_DARK), $matrix->get(6, $i));
+					$this::assertSame((QRMatrix::M_TIMING | QRMatrix::IS_DARK), $matrix->get($i, 6));
 				}
 			}
 		}
@@ -296,10 +296,10 @@ final class QRMatrixTest extends TestCase{
 
 		$this->dm($matrix);
 
-		$this::assertTrue($matrix->checkType($matrix->size() - 9, 0, QRMatrix::M_VERSION));
-		$this::assertTrue($matrix->checkType($matrix->size() - 11, 5, QRMatrix::M_VERSION));
-		$this::assertTrue($matrix->checkType(0, $matrix->size() - 9, QRMatrix::M_VERSION));
-		$this::assertTrue($matrix->checkType(5, $matrix->size() - 11, QRMatrix::M_VERSION));
+		$this::assertTrue($matrix->checkType(($matrix->size() - 9), 0, QRMatrix::M_VERSION));
+		$this::assertTrue($matrix->checkType(($matrix->size() - 11), 5, QRMatrix::M_VERSION));
+		$this::assertTrue($matrix->checkType(0, ($matrix->size() - 9), QRMatrix::M_VERSION));
+		$this::assertTrue($matrix->checkType(5, ($matrix->size() - 11), QRMatrix::M_VERSION));
 	}
 
 	/**
@@ -314,8 +314,8 @@ final class QRMatrixTest extends TestCase{
 
 		$this::assertTrue($matrix->checkType(8, 0, QRMatrix::M_FORMAT));
 		$this::assertTrue($matrix->checkType(0, 8, QRMatrix::M_FORMAT));
-		$this::assertTrue($matrix->checkType($matrix->size() - 1, 8, QRMatrix::M_FORMAT));
-		$this::assertTrue($matrix->checkType($matrix->size() - 8, 8, QRMatrix::M_FORMAT));
+		$this::assertTrue($matrix->checkType(($matrix->size() - 1), 8, QRMatrix::M_FORMAT));
+		$this::assertTrue($matrix->checkType(($matrix->size() - 8), 8, QRMatrix::M_FORMAT));
 	}
 
 	/**
@@ -324,26 +324,30 @@ final class QRMatrixTest extends TestCase{
 	 * @dataProvider matrixProvider
 	 */
 	public function testSetQuietZone(QRMatrix $matrix):void{
-		$size = $matrix->size();
-		$q    = 5;
+		$size          = $matrix->size();
+		$quietZoneSize = 5;
 
 		$matrix->set(0, 0, true, QRMatrix::M_TEST);
-		$matrix->set($size - 1, $size - 1, true, QRMatrix::M_TEST);
+		$matrix->set(($size - 1), ($size - 1), true, QRMatrix::M_TEST);
+
+		$matrix->setQuietZone($quietZoneSize);
 
-		$matrix->setQuietZone($q);
+		$s = ($size + 2 * $quietZoneSize);
 
-		$this::assertCount($size + 2 * $q, $matrix->matrix());
-		$this::assertCount($size + 2 * $q, $matrix->matrix()[$size - 1]);
+		$this::assertCount($s, $matrix->matrix());
+		$this::assertCount($s, $matrix->matrix()[($size - 1)]);
 
 		$size = $matrix->size();
 
 		$this->dm($matrix);
 
 		$this::assertTrue($matrix->checkType(0, 0, QRMatrix::M_QUIETZONE));
-		$this::assertTrue($matrix->checkType($size - 1, $size - 1, QRMatrix::M_QUIETZONE));
+		$this::assertTrue($matrix->checkType(($size - 1), ($size - 1), QRMatrix::M_QUIETZONE));
 
-		$this::assertSame(QRMatrix::M_TEST | QRMatrix::IS_DARK, $matrix->get($q, $q));
-		$this::assertSame(QRMatrix::M_TEST | QRMatrix::IS_DARK, $matrix->get($size - 1 - $q, $size - 1 - $q));
+		$s = ($size - 1 - $quietZoneSize);
+
+		$this::assertSame((QRMatrix::M_TEST | QRMatrix::IS_DARK), $matrix->get($quietZoneSize, $quietZoneSize));
+		$this::assertSame((QRMatrix::M_TEST | QRMatrix::IS_DARK), $matrix->get($s, $s));
 	}
 
 	/**
@@ -419,10 +423,10 @@ final class QRMatrixTest extends TestCase{
 		// logo space should not overwrite quiet zone & function patterns
 		$matrix->setLogoSpace(21, 21, -10, -10);
 		$this::assertSame(QRMatrix::M_QUIETZONE, $matrix->get(9, 9));
-		$this::assertSame(QRMatrix::M_FINDER | QRMatrix::IS_DARK, $matrix->get(10, 10));
-		$this::assertSame(QRMatrix::M_FINDER | QRMatrix::IS_DARK, $matrix->get(16, 16));
+		$this::assertSame((QRMatrix::M_FINDER | QRMatrix::IS_DARK), $matrix->get(10, 10));
+		$this::assertSame((QRMatrix::M_FINDER | QRMatrix::IS_DARK), $matrix->get(16, 16));
 		$this::assertSame(QRMatrix::M_SEPARATOR, $matrix->get(17, 17));
-		$this::assertSame(QRMatrix::M_FORMAT | QRMatrix::IS_DARK, $matrix->get(18, 18));
+		$this::assertSame((QRMatrix::M_FORMAT | QRMatrix::IS_DARK), $matrix->get(18, 18));
 		$this::assertSame(QRMatrix::M_LOGO, $matrix->get(19, 19));
 		$this::assertSame(QRMatrix::M_LOGO, $matrix->get(20, 20));
 		$this::assertNotSame(QRMatrix::M_LOGO, $matrix->get(21, 21));
@@ -480,12 +484,12 @@ final class QRMatrixTest extends TestCase{
 		// using the dark module here because i'm lazy
 		$this->matrix->setDarkModule();
 		$x = 8;
-		$y = $this->matrix->size() - 8;
+		$y = ($this->matrix->size() - 8);
 
 		// cover checkType()
 		$this::assertTrue($this->matrix->checkType($x, $y, QRMatrix::M_DARKMODULE));
 		// verify the current state (dark)
-		$this::assertSame(QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK, $this->matrix->get($x, $y));
+		$this::assertSame((QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK), $this->matrix->get($x, $y));
 		// flip
 		$this->matrix->flip($x, $y);
 		// verify flip
@@ -493,7 +497,7 @@ final class QRMatrixTest extends TestCase{
 		// flip again
 		$this->matrix->flip($x, $y);
 		// verify flip
-		$this::assertSame(QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK, $this->matrix->get($x, $y));
+		$this::assertSame((QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK), $this->matrix->get($x, $y));
 	}
 
 	/**
@@ -587,4 +591,5 @@ final class QRMatrixTest extends TestCase{
 		$this::assertSame(0b00000111, $this->matrix->checkNeighbours(3, 1, QRMatrix::M_FINDER));
 		$this::assertSame(0b01110000, $this->matrix->checkNeighbours(3, 1, QRMatrix::M_FINDER_DOT));
 	}
+
 }

+ 2 - 2
tests/Output/QRFpdfTest.php

@@ -43,8 +43,8 @@ final class QRFpdfTest extends QROutputTestAbstract{
 
 		$this->options->moduleValues = [
 			// data
-			QRMatrix::M_DATA | QRMatrix::IS_DARK => [0, 0, 0],
-			QRMatrix::M_DATA                     => [255, 255, 255],
+			(QRMatrix::M_DATA | QRMatrix::IS_DARK) => [0, 0, 0],
+			QRMatrix::M_DATA                       => [255, 255, 255],
 		];
 
 		$this->outputInterface = new $this->FQN($this->options, $this->matrix);

+ 2 - 2
tests/Output/QRGdImageTestAbstract.php

@@ -40,8 +40,8 @@ abstract class QRGdImageTestAbstract extends QROutputTestAbstract{
 
 		$this->options->moduleValues = [
 			// data
-			QRMatrix::M_DATA | QRMatrix::IS_DARK => [0, 0, 0],
-			QRMatrix::M_DATA                     => [255, 255, 255],
+			(QRMatrix::M_DATA | QRMatrix::IS_DARK) => [0, 0, 0],
+			QRMatrix::M_DATA                       => [255, 255, 255],
 		];
 
 		$this->outputInterface = new $this->FQN($this->options, $this->matrix);

+ 2 - 2
tests/Output/QRImagickTest.php

@@ -44,8 +44,8 @@ final class QRImagickTest extends QROutputTestAbstract{
 
 		$this->options->moduleValues = [
 			// data
-			QRMatrix::M_DATA | QRMatrix::IS_DARK => '#4A6000',
-			QRMatrix::M_DATA                     => '#ECF9BE',
+			(QRMatrix::M_DATA | QRMatrix::IS_DARK) => '#4A6000',
+			QRMatrix::M_DATA                       => '#ECF9BE',
 		];
 
 		$this->outputInterface = new $this->FQN($this->options, $this->matrix);

+ 2 - 2
tests/Output/QRMarkupTestAbstract.php

@@ -25,8 +25,8 @@ abstract class QRMarkupTestAbstract extends QROutputTestAbstract{
 		$this->options->drawLightModules = true;
 		$this->options->moduleValues     = [
 			// data
-			QRMatrix::M_DATA | QRMatrix::IS_DARK => '#4A6000',
-			QRMatrix::M_DATA                     => '#ECF9BE',
+			(QRMatrix::M_DATA | QRMatrix::IS_DARK) => '#4A6000',
+			QRMatrix::M_DATA                       => '#ECF9BE',
 		];
 
 		$this->outputInterface = new $this->FQN($this->options, $this->matrix);

+ 1 - 0
tests/Output/QRStringJSONTest.php

@@ -34,6 +34,7 @@ final class QRStringJSONTest extends QRStringTestAbstract{
 
 
 	public function testSetModuleValues():void{
+		/** @noinspection PhpUnitTestFailedLineInspection */
 		$this::markTestSkipped('N/A (JSON test)');
 	}
 

+ 2 - 2
tests/Output/QRStringTEXTTest.php

@@ -27,8 +27,8 @@ final class QRStringTEXTTest extends QRStringTestAbstract{
 
 		$this->options->moduleValues = [
 			// data
-			QRMatrix::M_DATA | QRMatrix::IS_DARK => 'A',
-			QRMatrix::M_DATA                     => 'B',
+			(QRMatrix::M_DATA | QRMatrix::IS_DARK) => 'A',
+			QRMatrix::M_DATA                       => 'B',
 		];
 
 		$this->outputInterface = new $this->FQN($this->options, $this->matrix);

+ 1 - 1
tests/QRCodeReaderTestAbstract.php

@@ -123,7 +123,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) ?? '')),
 				];
 			}
 		}

+ 2 - 2
tests/QRMaxLengthTrait.php

@@ -91,8 +91,8 @@ trait QRMaxLengthTrait{
 		if(!isset($dataModes[$mode])){
 			throw new QRCodeException('invalid $mode');
 		}
-
-		return self::$MAX_LENGTH[$version->getVersionNumber()][$dataModes[$mode]][$eccLevel->getOrdinal()] ?? null;
+		/** @SuppressWarnings(PHPMD.UndefinedVariable) */
+		return (static::$MAX_LENGTH[$version->getVersionNumber()][$dataModes[$mode]][$eccLevel->getOrdinal()] ?? null);
 	}
 
 }

+ 2 - 2
tests/QROptionsTest.php

@@ -96,8 +96,8 @@ final class QROptionsTest extends TestCase{
 	public function testInvalidRGBValueException():void{
 		$this->expectException(QRCodeException::class);
 		$this->expectExceptionMessage('Invalid RGB value.');
-
-		$o = new QROptions(['imageTransparencyBG' => ['r', 'g', 'b']]);
+		/** @phan-suppress-next-line PhanNoopNew */
+		new QROptions(['imageTransparencyBG' => ['r', 'g', 'b']]);
 	}
 
 	/**