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