diff --git a/examples/authenticator.php b/examples/authenticator.php index 27fda392f..a14ecf42e 100644 --- a/examples/authenticator.php +++ b/examples/authenticator.php @@ -10,9 +10,10 @@ use chillerlan\Authenticator\{Authenticator, AuthenticatorOptionsTrait}; use chillerlan\Authenticator\Authenticators\AuthenticatorInterface; -use chillerlan\Settings\SettingsContainerAbstract; use chillerlan\QRCode\{QRCode, QROptionsTrait}; use chillerlan\QRCode\Data\QRMatrix; +use chillerlan\QRCode\Output\QRMarkupSVG; +use chillerlan\Settings\SettingsContainerAbstract; require_once __DIR__.'/../vendor/autoload.php'; @@ -35,6 +36,7 @@ $options->algorithm = AuthenticatorInterface::ALGO_SHA512; */ $options->version = 7; $options->addQuietzone = false; +$options->outputInterface = QRMarkupSVG::class; $options->outputBase64 = false; $options->svgAddXmlHeader = false; $options->cssClass = 'my-qrcode'; diff --git a/examples/custom_output.php b/examples/custom_output.php index a6e581417..ead973a32 100644 --- a/examples/custom_output.php +++ b/examples/custom_output.php @@ -40,7 +40,7 @@ class MyCustomOutput extends QROutputAbstract{ /** * @inheritDoc */ - protected function getDefaultModuleValue(bool $isDark){ + protected function getDefaultModuleValue(bool $isDark):mixed{ // TODO: Implement getDefaultModuleValue() method. (abstract) return null; } diff --git a/examples/imageWithRoundedShapes.php b/examples/imageWithRoundedShapes.php index f387d870c..bfaebebfc 100644 --- a/examples/imageWithRoundedShapes.php +++ b/examples/imageWithRoundedShapes.php @@ -13,11 +13,10 @@ * @noinspection PhpComposerExtensionStubsInspection */ +use chillerlan\QRCode\{QRCode, QROptions}; use chillerlan\QRCode\Common\EccLevel; use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Output\QRGdImagePNG; -use chillerlan\QRCode\QRCode; -use chillerlan\QRCode\QROptions; use chillerlan\Settings\SettingsContainerInterface; require_once __DIR__ . '/../vendor/autoload.php'; diff --git a/examples/imagickConvertSVGtoPNG.php b/examples/imagickConvertSVGtoPNG.php index ba2e036db..11734d82a 100644 --- a/examples/imagickConvertSVGtoPNG.php +++ b/examples/imagickConvertSVGtoPNG.php @@ -16,10 +16,9 @@ * @license MIT */ +use chillerlan\QRCode\{QRCode, QROptions}; use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Output\QRMarkupSVG; -use chillerlan\QRCode\QRCode; -use chillerlan\QRCode\QROptions; require_once __DIR__.'/../vendor/autoload.php'; diff --git a/examples/imagickImageAsBackground.php b/examples/imagickImageAsBackground.php index 951e93f21..1807e1c2d 100644 --- a/examples/imagickImageAsBackground.php +++ b/examples/imagickImageAsBackground.php @@ -8,11 +8,9 @@ * @license MIT */ +use chillerlan\QRCode\{QRCode, QRCodeException, QROptions}; use chillerlan\QRCode\Common\EccLevel; use chillerlan\QRCode\Output\QRImagick; -use chillerlan\QRCode\QRCode; -use chillerlan\QRCode\QRCodeException; -use chillerlan\QRCode\QROptions; require_once __DIR__.'/../vendor/autoload.php'; diff --git a/examples/multimode.php b/examples/multimode.php index a7963d011..f7e9d1d38 100644 --- a/examples/multimode.php +++ b/examples/multimode.php @@ -8,8 +8,7 @@ * @license MIT */ -use chillerlan\QRCode\QRCode; -use chillerlan\QRCode\QROptions; +use chillerlan\QRCode\{QRCode, QROptions}; require_once __DIR__.'/../vendor/autoload.php'; diff --git a/examples/qrcode-interactive.php b/examples/qrcode-interactive.php index 2127e1a5f..f0227a002 100644 --- a/examples/qrcode-interactive.php +++ b/examples/qrcode-interactive.php @@ -8,9 +8,8 @@ * @noinspection PhpComposerExtensionStubsInspection */ +use chillerlan\QRCode\{QRCode, QROptions}; use chillerlan\QRCode\Data\QRMatrix; -use chillerlan\QRCode\QRCode; -use chillerlan\QRCode\QROptions; require_once '../vendor/autoload.php'; diff --git a/examples/reflectance.php b/examples/reflectance.php index 95ba2f8a1..fe7878258 100644 --- a/examples/reflectance.php +++ b/examples/reflectance.php @@ -8,11 +8,10 @@ * @license MIT */ +use chillerlan\QRCode\{QRCode, QROptions}; use chillerlan\QRCode\Common\EccLevel; use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Output\QRMarkupSVG; -use chillerlan\QRCode\QRCode; -use chillerlan\QRCode\QROptions; require_once __DIR__.'/../vendor/autoload.php'; diff --git a/examples/svgConvertViaCanvas.php b/examples/svgConvertViaCanvas.php index 78fc8de46..ac9bf1f04 100644 --- a/examples/svgConvertViaCanvas.php +++ b/examples/svgConvertViaCanvas.php @@ -8,11 +8,9 @@ * @license MIT */ - +use chillerlan\QRCode\{QRCode, QROptions}; use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Output\QRMarkupSVG; -use chillerlan\QRCode\QRCode; -use chillerlan\QRCode\QROptions; require_once __DIR__.'/../vendor/autoload.php'; diff --git a/examples/svgRoundQuietzone.php b/examples/svgRoundQuietzone.php index aa0597f02..11ed47a2a 100644 --- a/examples/svgRoundQuietzone.php +++ b/examples/svgRoundQuietzone.php @@ -12,10 +12,10 @@ * @noinspection PhpIllegalPsrClassPathInspection */ +use chillerlan\QRCode\{QRCode, QRCodeException, QROptions}; use chillerlan\QRCode\Common\EccLevel; use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Output\QRMarkupSVG; -use chillerlan\QRCode\{QRCode, QRCodeException, QROptions}; require_once __DIR__.'/../vendor/autoload.php'; diff --git a/src/Common/BitBuffer.php b/src/Common/BitBuffer.php index 9d4d1f221..91c04052e 100644 --- a/src/Common/BitBuffer.php +++ b/src/Common/BitBuffer.php @@ -42,11 +42,9 @@ final class BitBuffer{ /** * BitBuffer constructor. - * - * @param int[]|null $bytes */ - public function __construct(array $bytes = null){ - $this->buffer = ($bytes ?? []); + public function __construct(array $bytes = []){ + $this->buffer = $bytes; $this->length = count($this->buffer); } diff --git a/src/Common/EccLevel.php b/src/Common/EccLevel.php index ecba012c0..9aa349f33 100644 --- a/src/Common/EccLevel.php +++ b/src/Common/EccLevel.php @@ -11,7 +11,6 @@ namespace chillerlan\QRCode\Common; use chillerlan\QRCode\QRCodeException; - use function array_column; /** diff --git a/src/Common/GDLuminanceSource.php b/src/Common/GDLuminanceSource.php index d669ed176..60402683d 100644 --- a/src/Common/GDLuminanceSource.php +++ b/src/Common/GDLuminanceSource.php @@ -33,7 +33,7 @@ final class GDLuminanceSource extends LuminanceSourceAbstract{ * * @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException */ - public function __construct(GdImage $gdImage, SettingsContainerInterface|QROptions $options = null){ + public function __construct(GdImage $gdImage, SettingsContainerInterface|QROptions $options = new QROptions){ parent::__construct(imagesx($gdImage), imagesy($gdImage), $options); $this->gdImage = $gdImage; @@ -71,12 +71,12 @@ final class GDLuminanceSource extends LuminanceSourceAbstract{ } /** @inheritDoc */ - public static function fromFile(string $path, SettingsContainerInterface $options = null):static{ + public static function fromFile(string $path, SettingsContainerInterface|QROptions $options = new QROptions):static{ return new self(imagecreatefromstring(file_get_contents(self::checkFile($path))), $options); } /** @inheritDoc */ - public static function fromBlob(string $blob, SettingsContainerInterface $options = null):static{ + public static function fromBlob(string $blob, SettingsContainerInterface|QROptions $options = new QROptions):static{ return new self(imagecreatefromstring($blob), $options); } diff --git a/src/Common/GenericGFPoly.php b/src/Common/GenericGFPoly.php index 362853d61..ae361b9d0 100644 --- a/src/Common/GenericGFPoly.php +++ b/src/Common/GenericGFPoly.php @@ -12,7 +12,6 @@ namespace chillerlan\QRCode\Common; use chillerlan\QRCode\QRCodeException; - use function array_fill, array_slice, array_splice, count; /** diff --git a/src/Common/IMagickLuminanceSource.php b/src/Common/IMagickLuminanceSource.php index d9518280e..0ed37a62d 100644 --- a/src/Common/IMagickLuminanceSource.php +++ b/src/Common/IMagickLuminanceSource.php @@ -29,7 +29,7 @@ final class IMagickLuminanceSource extends LuminanceSourceAbstract{ /** * IMagickLuminanceSource constructor. */ - public function __construct(Imagick $imagick, SettingsContainerInterface|QROptions $options = null){ + public function __construct(Imagick $imagick, SettingsContainerInterface|QROptions $options = new QROptions){ parent::__construct($imagick->getImageWidth(), $imagick->getImageHeight(), $options); $this->imagick = $imagick; @@ -64,12 +64,12 @@ final class IMagickLuminanceSource extends LuminanceSourceAbstract{ } /** @inheritDoc */ - public static function fromFile(string $path, SettingsContainerInterface $options = null):static{ + public static function fromFile(string $path, SettingsContainerInterface|QROptions $options = new QROptions):static{ return new self(new Imagick(self::checkFile($path)), $options); } /** @inheritDoc */ - public static function fromBlob(string $blob, SettingsContainerInterface $options = null):static{ + public static function fromBlob(string $blob, SettingsContainerInterface|QROptions $options = new QROptions):static{ $im = new Imagick; $im->readImageBlob($blob); diff --git a/src/Common/LuminanceSourceAbstract.php b/src/Common/LuminanceSourceAbstract.php index e74c8f7b1..de04801f8 100644 --- a/src/Common/LuminanceSourceAbstract.php +++ b/src/Common/LuminanceSourceAbstract.php @@ -12,8 +12,8 @@ namespace chillerlan\QRCode\Common; -use chillerlan\QRCode\Decoder\QRCodeDecoderException; use chillerlan\QRCode\QROptions; +use chillerlan\QRCode\Decoder\QRCodeDecoderException; use chillerlan\Settings\SettingsContainerInterface; use function array_slice, array_splice, file_exists, is_file, is_readable, realpath; @@ -33,10 +33,10 @@ abstract class LuminanceSourceAbstract implements LuminanceSourceInterface{ /** * */ - public function __construct(int $width, int $height, SettingsContainerInterface|QROptions $options = null){ + public function __construct(int $width, int $height, SettingsContainerInterface|QROptions $options = new QROptions){ $this->width = $width; $this->height = $height; - $this->options = ($options ?? new QROptions); + $this->options = $options; $this->luminances = []; } diff --git a/src/Common/LuminanceSourceInterface.php b/src/Common/LuminanceSourceInterface.php index 05e9ae596..bb691148a 100644 --- a/src/Common/LuminanceSourceInterface.php +++ b/src/Common/LuminanceSourceInterface.php @@ -10,6 +10,9 @@ namespace chillerlan\QRCode\Common; +use chillerlan\QRCode\QROptions; +use chillerlan\Settings\SettingsContainerInterface; + /** */ interface LuminanceSourceInterface{ @@ -51,11 +54,11 @@ interface LuminanceSourceInterface{ /** * Creates a LuminanceSource instance from the given file */ - public static function fromFile(string $path):static; + public static function fromFile(string $path, SettingsContainerInterface|QROptions $options = new QROptions):static; /** * Creates a LuminanceSource instance from the given data blob */ - public static function fromBlob(string $blob):static; + public static function fromBlob(string $blob, SettingsContainerInterface|QROptions $options = new QROptions):static; } diff --git a/src/Common/MaskPattern.php b/src/Common/MaskPattern.php index 177d25648..cb83a8d81 100644 --- a/src/Common/MaskPattern.php +++ b/src/Common/MaskPattern.php @@ -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; diff --git a/src/Data/AlphaNum.php b/src/Data/AlphaNum.php index c1c8cb36b..be9df2d25 100644 --- a/src/Data/AlphaNum.php +++ b/src/Data/AlphaNum.php @@ -11,7 +11,6 @@ namespace chillerlan\QRCode\Data; use chillerlan\QRCode\Common\{BitBuffer, Mode}; - use function array_flip, ceil, intdiv, str_split; /** diff --git a/src/Data/Byte.php b/src/Data/Byte.php index b51ac254b..77d090dea 100644 --- a/src/Data/Byte.php +++ b/src/Data/Byte.php @@ -11,7 +11,6 @@ namespace chillerlan\QRCode\Data; use chillerlan\QRCode\Common\{BitBuffer, Mode}; - use function chr, ord; /** diff --git a/src/Data/Hanzi.php b/src/Data/Hanzi.php index a40c97154..ec96793ce 100644 --- a/src/Data/Hanzi.php +++ b/src/Data/Hanzi.php @@ -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; @@ -96,7 +95,7 @@ final class Hanzi extends QRDataModeAbstract{ try{ $string = self::convertEncoding($string); } - catch(Throwable $e){ + catch(Throwable){ return false; } diff --git a/src/Data/Kanji.php b/src/Data/Kanji.php index fb6e27aab..8c95cc71b 100644 --- a/src/Data/Kanji.php +++ b/src/Data/Kanji.php @@ -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; @@ -89,7 +88,7 @@ final class Kanji extends QRDataModeAbstract{ try{ $string = self::convertEncoding($string); } - catch(Throwable $e){ + catch(Throwable){ return false; } diff --git a/src/Data/Number.php b/src/Data/Number.php index 3fe564571..71f2b1fbd 100644 --- a/src/Data/Number.php +++ b/src/Data/Number.php @@ -11,7 +11,6 @@ namespace chillerlan\QRCode\Data; use chillerlan\QRCode\Common\{BitBuffer, Mode}; - use function array_flip, ceil, intdiv, str_split, substr, unpack; /** diff --git a/src/Data/QRData.php b/src/Data/QRData.php index 7b7996c32..bfccc1ffa 100644 --- a/src/Data/QRData.php +++ b/src/Data/QRData.php @@ -10,12 +10,10 @@ namespace chillerlan\QRCode\Data; -use chillerlan\QRCode\Common\{BitBuffer, EccLevel, Mode, Version}; use chillerlan\QRCode\QROptions; +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 diff --git a/src/Data/QRDataModeInterface.php b/src/Data/QRDataModeInterface.php index 2cc346896..fcd333628 100644 --- a/src/Data/QRDataModeInterface.php +++ b/src/Data/QRDataModeInterface.php @@ -20,14 +20,10 @@ interface QRDataModeInterface{ /** * the current data mode: Number, Alphanum, Kanji, Hanzi, Byte, ECI * - * tbh I hate this constant here, but it's part of the interface, so I can't just declare it in the abstract class. - * (phan will complain about a PhanAccessOverridesFinalConstant) - * - * @see https://wiki.php.net/rfc/final_class_const + * Note: do not call this constant from the interface, but rather from one of the child classes * * @var int * @see \chillerlan\QRCode\Common\Mode - * @internal do not call this constant from the interface, but rather from one of the child classes */ public const DATAMODE = -1; diff --git a/src/Data/ReedSolomonEncoder.php b/src/Data/ReedSolomonEncoder.php index 30cbd22a8..60444378c 100644 --- a/src/Data/ReedSolomonEncoder.php +++ b/src/Data/ReedSolomonEncoder.php @@ -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 */ diff --git a/src/Decoder/BitMatrix.php b/src/Decoder/BitMatrix.php index 3fc55e8d7..1aec32ac6 100644 --- a/src/Decoder/BitMatrix.php +++ b/src/Decoder/BitMatrix.php @@ -97,7 +97,6 @@ final class BitMatrix extends QRMatrix{ // mirror vertically $this->matrix = array_reverse($this->matrix); // rotate by 90 degrees clockwise - /** @phan-suppress-next-line PhanTypeMismatchReturnSuperType */ return $this->rotate90(); } diff --git a/src/Decoder/Decoder.php b/src/Decoder/Decoder.php index 6f369a6df..3d8dc39a7 100644 --- a/src/Decoder/Decoder.php +++ b/src/Decoder/Decoder.php @@ -11,9 +11,11 @@ namespace chillerlan\QRCode\Decoder; +use chillerlan\QRCode\QROptions; use chillerlan\QRCode\Common\{BitBuffer, EccLevel, LuminanceSourceInterface, MaskPattern, Mode, Version}; use chillerlan\QRCode\Data\{AlphaNum, Byte, ECI, Hanzi, Kanji, Number}; use chillerlan\QRCode\Detector\Detector; +use chillerlan\Settings\SettingsContainerInterface; use Throwable; use function chr, str_replace; @@ -25,10 +27,18 @@ use function chr, str_replace; */ final class Decoder{ - private ?Version $version = null; - private ?EccLevel $eccLevel = null; - private ?MaskPattern $maskPattern = null; - private BitBuffer $bitBuffer; + /** + * @var \chillerlan\QRCode\QROptions|\chillerlan\Settings\SettingsContainerInterface + */ + private SettingsContainerInterface|QROptions $options; + private ?Version $version = null; + private ?EccLevel $eccLevel = null; + private ?MaskPattern $maskPattern = null; + private BitBuffer $bitBuffer; + + public function __construct(SettingsContainerInterface|QROptions $options = new QROptions){ + $this->options = $options; + } /** * Decodes a QR Code represented as a BitMatrix. @@ -56,7 +66,7 @@ final class Decoder{ */ return $this->decodeMatrix($matrix->resetVersionInfo()->mirrorDiagonal()); } - catch(Throwable $f){ + catch(Throwable){ // Throw the exception from the original reading throw $e; } diff --git a/src/Decoder/DecoderResult.php b/src/Decoder/DecoderResult.php index 79486f13b..02b4d7931 100644 --- a/src/Decoder/DecoderResult.php +++ b/src/Decoder/DecoderResult.php @@ -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)) diff --git a/src/Decoder/ReedSolomonDecoder.php b/src/Decoder/ReedSolomonDecoder.php index ec6ac9dd7..2bd539aad 100644 --- a/src/Decoder/ReedSolomonDecoder.php +++ b/src/Decoder/ReedSolomonDecoder.php @@ -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; diff --git a/src/Detector/Detector.php b/src/Detector/Detector.php index 949aebd53..e43798b9f 100644 --- a/src/Detector/Detector.php +++ b/src/Detector/Detector.php @@ -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; diff --git a/src/Output/QRFpdf.php b/src/Output/QRFpdf.php index 9e03287a0..cde7a2230 100644 --- a/src/Output/QRFpdf.php +++ b/src/Output/QRFpdf.php @@ -11,8 +11,8 @@ namespace chillerlan\QRCode\Output; -use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\QROptions; +use chillerlan\QRCode\Data\QRMatrix; use chillerlan\Settings\SettingsContainerInterface; use FPDF; diff --git a/src/Output/QRGdImage.php b/src/Output/QRGdImage.php index 2bb9c18c6..4bc886d76 100644 --- a/src/Output/QRGdImage.php +++ b/src/Output/QRGdImage.php @@ -12,8 +12,8 @@ namespace chillerlan\QRCode\Output; -use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\QROptions; +use chillerlan\QRCode\Data\QRMatrix; use chillerlan\Settings\SettingsContainerInterface; use ErrorException, GdImage, Throwable; use function array_values, count, extension_loaded, gd_info, imagecolorallocate, imagecolortransparent, @@ -90,7 +90,7 @@ abstract class QRGdImage extends QROutputAbstract{ QRGdImageWEBP::class => 'WebP Support', ]; - // likely using default or custom output + // likely using custom output if(!isset($modes[$this->options->outputInterface])){ return; } @@ -217,10 +217,8 @@ abstract 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 * * @see https://github.com/chillerlan/php-qrcode/issues/23 - * - * @return \GdImage|resource */ - protected function createImage(){ + protected function createImage():GdImage{ if($this->drawCircularModules && $this->options->gdImageUseUpscale && $this->options->scale < 20){ // increase the initial image size by 10 diff --git a/src/Output/QRGdImageJPEG.php b/src/Output/QRGdImageJPEG.php index c2b301e5b..3fb95cc91 100644 --- a/src/Output/QRGdImageJPEG.php +++ b/src/Output/QRGdImageJPEG.php @@ -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 diff --git a/src/Output/QRGdImagePNG.php b/src/Output/QRGdImagePNG.php index 4fa62dd82..17b249182 100644 --- a/src/Output/QRGdImagePNG.php +++ b/src/Output/QRGdImagePNG.php @@ -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 diff --git a/src/Output/QRGdImageWEBP.php b/src/Output/QRGdImageWEBP.php index 6c305cf4b..0f2d32dc9 100644 --- a/src/Output/QRGdImageWEBP.php +++ b/src/Output/QRGdImageWEBP.php @@ -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 diff --git a/src/Output/QRImagick.php b/src/Output/QRImagick.php index 294408bd0..4ba43e4eb 100644 --- a/src/Output/QRImagick.php +++ b/src/Output/QRImagick.php @@ -12,11 +12,11 @@ namespace chillerlan\QRCode\Output; -use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\QROptions; +use chillerlan\QRCode\Data\QRMatrix; use chillerlan\Settings\SettingsContainerInterface; use finfo, Imagick, ImagickDraw, ImagickPixel; -use function extension_loaded, in_array, is_string, max, min, preg_match, strlen; +use function extension_loaded, in_array, is_string, max, min, preg_match, sprintf, strlen; use const FILEINFO_MIME_TYPE; /** @@ -49,12 +49,10 @@ class QRImagick extends QROutputAbstract{ */ public function __construct(SettingsContainerInterface|QROptions $options, QRMatrix $matrix){ - if(!extension_loaded('imagick')){ - throw new QRCodeOutputException('ext-imagick not loaded'); // @codeCoverageIgnore - } - - if(!extension_loaded('fileinfo')){ - throw new QRCodeOutputException('ext-fileinfo not loaded'); // @codeCoverageIgnore + foreach(['fileinfo', 'imagick'] as $ext){ + if(!extension_loaded($ext)){ + throw new QRCodeOutputException(sprintf('ext-%s not loaded', $ext)); // @codeCoverageIgnore + } } parent::__construct($options, $matrix); diff --git a/src/Output/QROutputAbstract.php b/src/Output/QROutputAbstract.php index 168d957da..baf3bc9f2 100644 --- a/src/Output/QROutputAbstract.php +++ b/src/Output/QROutputAbstract.php @@ -10,8 +10,8 @@ namespace chillerlan\QRCode\Output; -use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\QROptions; +use chillerlan\QRCode\Data\QRMatrix; use chillerlan\Settings\SettingsContainerInterface; use Closure; use function base64_encode, dirname, file_put_contents, is_writable, ksort, sprintf; diff --git a/src/Output/QROutputInterface.php b/src/Output/QROutputInterface.php index 792e22678..ae0f0211b 100644 --- a/src/Output/QROutputInterface.php +++ b/src/Output/QROutputInterface.php @@ -105,9 +105,10 @@ interface QROutputInterface{ ]; /** - * @var string - * @see \chillerlan\QRCode\Output\QROutputAbstract::toBase64DataURI() - * @internal do not call this constant from the interface, but rather from one of the child classes + * Note: do not call this constant from the interface, but rather from one of the child classes + * + * @var string + * @see \chillerlan\QRCode\Output\QROutputAbstract::toBase64DataURI() */ public const MIME_TYPE = ''; diff --git a/src/Output/QRStringJSON.php b/src/Output/QRStringJSON.php index 361aead62..a4acc9c08 100644 --- a/src/Output/QRStringJSON.php +++ b/src/Output/QRStringJSON.php @@ -38,6 +38,7 @@ class QRStringJSON extends QROutputAbstract{ * unused - required by interface * * @inheritDoc + * @codeCoverageIgnore */ protected function prepareModuleValue(mixed $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(mixed $value):bool{ return true; diff --git a/src/Output/QRStringText.php b/src/Output/QRStringText.php index e4526a5d5..309f123fc 100644 --- a/src/Output/QRStringText.php +++ b/src/Output/QRStringText.php @@ -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; /** * diff --git a/src/QRCode.php b/src/QRCode.php index 4c427a29c..f5c25d686 100755 --- a/src/QRCode.php +++ b/src/QRCode.php @@ -54,8 +54,8 @@ class QRCode{ * * PHP8: accept iterable */ - public function __construct(SettingsContainerInterface|QROptions $options = null){ - $this->setOptions(($options ?? new QROptions)); + public function __construct(SettingsContainerInterface|QROptions $options = new QROptions){ + $this->setOptions($options); } /** @@ -292,7 +292,7 @@ class QRCode{ * Reads a QR Code from the given luminance source */ public function readFromSource(LuminanceSourceInterface $source):DecoderResult{ - return (new Decoder)->decode($source); + return (new Decoder($this->options))->decode($source); } } diff --git a/src/QROptionsTrait.php b/src/QROptionsTrait.php index f570bd9f0..87ea60628 100644 --- a/src/QROptionsTrait.php +++ b/src/QROptionsTrait.php @@ -14,8 +14,8 @@ namespace chillerlan\QRCode; -use chillerlan\QRCode\Output\QRMarkupSVG; use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Version}; +use chillerlan\QRCode\Output\QRMarkupSVG; use function constant, extension_loaded, in_array, is_string, max, min, sprintf, strtolower, strtoupper, trim; use const JSON_THROW_ON_ERROR, PHP_EOL; @@ -54,13 +54,15 @@ trait QROptionsTrait{ /** * Error correct level * - * `EccLevel::X` where `X` is: + * the constant `EccLevel::X` where `X` is: * * - `L` => 7% (default) * - `M` => 15% * - `Q` => 25% * - `H` => 30% * + * alternatively you can just pass the letters L/M/Q/H (case-insensitive) to the magic setter + * * @see \chillerlan\QRCode\Common\EccLevel * @see https://github.com/chillerlan/php-qrcode/discussions/160 */ diff --git a/tests/Output/QRStringTEXTTest.php b/tests/Output/QRStringTextTest.php similarity index 93% rename from tests/Output/QRStringTEXTTest.php rename to tests/Output/QRStringTextTest.php index 43c354cf3..9ce58455c 100644 --- a/tests/Output/QRStringTEXTTest.php +++ b/tests/Output/QRStringTextTest.php @@ -1,6 +1,6 @@ @@ -18,7 +18,7 @@ use chillerlan\Settings\SettingsContainerInterface; /** * */ -final class QRStringTEXTTest extends QROutputTestAbstract{ +final class QRStringTextTest extends QROutputTestAbstract{ protected function getOutputInterface( SettingsContainerInterface|QROptions $options,