From beecbe7ba5f4776bd8bd7e69d84d0c7dc8a94983 Mon Sep 17 00:00:00 2001 From: smiley Date: Wed, 17 Jul 2024 11:05:32 +0200 Subject: [PATCH] :octocat: mark nullable types explicitly (https://github.com/chillerlan/php-qrcode/issues/276) --- composer.json | 6 +++--- examples/custom_output.php | 2 +- examples/imageWithLogo.php | 2 +- examples/imageWithText.php | 2 +- examples/imagickConvertSVGtoPNG.php | 2 +- examples/imagickWithLogo.php | 2 +- src/Common/GDLuminanceSource.php | 6 +++--- src/Common/GenericGFPoly.php | 2 +- src/Common/IMagickLuminanceSource.php | 6 +++--- src/Common/LuminanceSourceAbstract.php | 2 +- src/Data/QRMatrix.php | 10 +++++----- src/Decoder/BitMatrix.php | 4 ++-- src/Decoder/DecoderResult.php | 2 +- src/Detector/Detector.php | 10 +++++----- src/Detector/FinderPattern.php | 2 +- src/Detector/PerspectiveTransform.php | 2 +- src/Output/QREps.php | 2 +- src/Output/QRFpdf.php | 2 +- src/Output/QRGdImage.php | 2 +- src/Output/QRImagick.php | 2 +- src/Output/QRMarkup.php | 2 +- src/Output/QROutputAbstract.php | 4 ++-- src/Output/QROutputInterface.php | 2 +- src/Output/QRString.php | 4 ++-- src/Output/QRStringJSON.php | 2 +- src/Output/QRStringText.php | 4 ++-- src/QRCode.php | 6 +++--- tests/Common/ECICharsetTest.php | 2 +- 28 files changed, 48 insertions(+), 48 deletions(-) diff --git a/composer.json b/composer.json index f893f9f4f..13b47839c 100644 --- a/composer.json +++ b/composer.json @@ -42,15 +42,15 @@ "require": { "php": "^7.4 || ^8.0", "ext-mbstring": "*", - "chillerlan/php-settings-container": "^2.1.4 || ^3.2" + "chillerlan/php-settings-container": "^2.1.6 || ^3.2.1" }, "require-dev": { - "chillerlan/php-authenticator": "^4.1 || ^5.1", + "chillerlan/php-authenticator": "^4.3.1 || ^5.2.1", "phan/phan": "^5.4", "phpunit/phpunit": "^9.6", "phpmd/phpmd": "^2.15", "setasign/fpdf": "^1.8.2", - "squizlabs/php_codesniffer": "^3.9" + "squizlabs/php_codesniffer": "^3.10" }, "suggest": { "chillerlan/php-authenticator": "Yet another Google authenticator! Also creates URIs for mobile apps.", diff --git a/examples/custom_output.php b/examples/custom_output.php index 48f20aa37..b173289d4 100644 --- a/examples/custom_output.php +++ b/examples/custom_output.php @@ -49,7 +49,7 @@ class MyCustomOutput extends QROutputAbstract{ /** * @inheritDoc */ - public function dump(string $file = null):string{ + public function dump(?string $file = null):string{ $output = ''; for($y = 0; $y < $this->moduleCount; $y++){ diff --git a/examples/imageWithLogo.php b/examples/imageWithLogo.php index 2f159c773..5d54a9d90 100644 --- a/examples/imageWithLogo.php +++ b/examples/imageWithLogo.php @@ -30,7 +30,7 @@ class QRImageWithLogo extends QRGdImagePNG{ * @return string * @throws \chillerlan\QRCode\Output\QRCodeOutputException */ - public function dump(string $file = null, string $logo = null):string{ + public function dump(?string $file = null, ?string $logo = null):string{ // set returnResource to true to skip further processing for now $this->options->returnResource = true; diff --git a/examples/imageWithText.php b/examples/imageWithText.php index 79a3ed326..75ce07a1f 100644 --- a/examples/imageWithText.php +++ b/examples/imageWithText.php @@ -26,7 +26,7 @@ class QRImageWithText extends QRGdImagePNG{ /** * @inheritDoc */ - public function dump(string $file = null, string $text = null):string{ + public function dump(?string $file = null, ?string $text = null):string{ // set returnResource to true to skip further processing for now $this->options->returnResource = true; diff --git a/examples/imagickConvertSVGtoPNG.php b/examples/imagickConvertSVGtoPNG.php index c5759caed..9d0e30b17 100644 --- a/examples/imagickConvertSVGtoPNG.php +++ b/examples/imagickConvertSVGtoPNG.php @@ -49,7 +49,7 @@ class SVGConvert extends QRMarkupSVG{ } /** @inheritDoc */ - public function dump(string $file = null):string{ + public function dump(?string $file = null):string{ $base64 = $this->options->outputBase64; // we don't want the SVG in base64 $this->options->outputBase64 = false; diff --git a/examples/imagickWithLogo.php b/examples/imagickWithLogo.php index da894b36c..c4c506d8e 100644 --- a/examples/imagickWithLogo.php +++ b/examples/imagickWithLogo.php @@ -28,7 +28,7 @@ class QRImagickWithLogo extends QRImagick{ * @inheritDoc * @throws \chillerlan\QRCode\Output\QRCodeOutputException */ - public function dump(string $file = null):string{ + public function dump(?string $file = null):string{ // set returnResource to true to skip further processing for now $this->options->returnResource = true; diff --git a/src/Common/GDLuminanceSource.php b/src/Common/GDLuminanceSource.php index 027466f3e..0702a67bb 100644 --- a/src/Common/GDLuminanceSource.php +++ b/src/Common/GDLuminanceSource.php @@ -38,7 +38,7 @@ class GDLuminanceSource extends LuminanceSourceAbstract{ * * @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException */ - public function __construct($gdImage, SettingsContainerInterface $options = null){ + public function __construct($gdImage, ?SettingsContainerInterface $options = null){ /** @noinspection PhpFullyQualifiedNameUsageInspection */ if( @@ -85,12 +85,12 @@ class GDLuminanceSource extends LuminanceSourceAbstract{ } /** @inheritDoc */ - public static function fromFile(string $path, SettingsContainerInterface $options = null):self{ + public static function fromFile(string $path, ?SettingsContainerInterface $options = null):self{ return new self(imagecreatefromstring(file_get_contents(self::checkFile($path))), $options); } /** @inheritDoc */ - public static function fromBlob(string $blob, SettingsContainerInterface $options = null):self{ + public static function fromBlob(string $blob, ?SettingsContainerInterface $options = null):self{ return new self(imagecreatefromstring($blob), $options); } diff --git a/src/Common/GenericGFPoly.php b/src/Common/GenericGFPoly.php index ae361b9d0..4023e74d2 100644 --- a/src/Common/GenericGFPoly.php +++ b/src/Common/GenericGFPoly.php @@ -35,7 +35,7 @@ final class GenericGFPoly{ * @throws \chillerlan\QRCode\QRCodeException if argument is null or empty, or if leading coefficient is 0 and this * is not a constant polynomial (that is, it is not the monomial "0") */ - public function __construct(array $coefficients, int $degree = null){ + public function __construct(array $coefficients, ?int $degree = null){ $degree ??= 0; if(empty($coefficients)){ diff --git a/src/Common/IMagickLuminanceSource.php b/src/Common/IMagickLuminanceSource.php index d4f66c5c2..ade994a78 100644 --- a/src/Common/IMagickLuminanceSource.php +++ b/src/Common/IMagickLuminanceSource.php @@ -28,7 +28,7 @@ class IMagickLuminanceSource extends LuminanceSourceAbstract{ /** * IMagickLuminanceSource constructor. */ - public function __construct(Imagick $imagick, SettingsContainerInterface $options = null){ + public function __construct(Imagick $imagick, ?SettingsContainerInterface $options = null){ parent::__construct($imagick->getImageWidth(), $imagick->getImageHeight(), $options); $this->imagick = $imagick; @@ -63,12 +63,12 @@ class IMagickLuminanceSource extends LuminanceSourceAbstract{ } /** @inheritDoc */ - public static function fromFile(string $path, SettingsContainerInterface $options = null):self{ + public static function fromFile(string $path, ?SettingsContainerInterface $options = null):self{ return new self(new Imagick(self::checkFile($path)), $options); } /** @inheritDoc */ - public static function fromBlob(string $blob, SettingsContainerInterface $options = null):self{ + public static function fromBlob(string $blob, ?SettingsContainerInterface $options = null):self{ $im = new Imagick; $im->readImageBlob($blob); diff --git a/src/Common/LuminanceSourceAbstract.php b/src/Common/LuminanceSourceAbstract.php index 432a6e0d4..78e83366f 100644 --- a/src/Common/LuminanceSourceAbstract.php +++ b/src/Common/LuminanceSourceAbstract.php @@ -34,7 +34,7 @@ abstract class LuminanceSourceAbstract implements LuminanceSourceInterface{ /** * */ - public function __construct(int $width, int $height, SettingsContainerInterface $options = null){ + public function __construct(int $width, int $height, ?SettingsContainerInterface $options = null){ $this->width = $width; $this->height = $height; $this->options = ($options ?? new QROptions); diff --git a/src/Data/QRMatrix.php b/src/Data/QRMatrix.php index d92c1a784..aff79d6f8 100755 --- a/src/Data/QRMatrix.php +++ b/src/Data/QRMatrix.php @@ -175,7 +175,7 @@ class QRMatrix{ * * @return int[][]|bool[][] */ - public function getMatrix(bool $boolean = null):array{ + public function getMatrix(?bool $boolean = null):array{ if($boolean !== true){ return $this->matrix; @@ -195,7 +195,7 @@ class QRMatrix{ * @see \chillerlan\QRCode\Data\QRMatrix::getMatrix() * @codeCoverageIgnore */ - public function matrix(bool $boolean = null):array{ + public function matrix(?bool $boolean = null):array{ return $this->getMatrix($boolean); } @@ -387,7 +387,7 @@ class QRMatrix{ * 7 # 3 * 6 5 4 */ - public function checkNeighbours(int $x, int $y, int $M_TYPE = null):int{ + public function checkNeighbours(int $x, int $y, ?int $M_TYPE = null):int{ $bits = 0; foreach($this::neighbours as $bit => [$ix, $iy]){ @@ -552,7 +552,7 @@ class QRMatrix{ * * ISO/IEC 18004:2000 Section 8.9 */ - public function setFormatInfo(MaskPattern $maskPattern = null):self{ + public function setFormatInfo(?MaskPattern $maskPattern = null):self{ $this->maskPattern = $maskPattern; $bits = 0; // sets all format fields to false (test mode) @@ -678,7 +678,7 @@ class QRMatrix{ * * @throws \chillerlan\QRCode\Data\QRCodeDataException */ - public function setLogoSpace(int $width, int $height = null, int $startX = null, int $startY = null):self{ + public function setLogoSpace(int $width, ?int $height = null, ?int $startX = null, ?int $startY = null):self{ $height ??= $width; // if width and height happen to be negative or 0 (default value), just return - nothing to do diff --git a/src/Decoder/BitMatrix.php b/src/Decoder/BitMatrix.php index ea2e321b5..21f504e72 100644 --- a/src/Decoder/BitMatrix.php +++ b/src/Decoder/BitMatrix.php @@ -415,7 +415,7 @@ final class BitMatrix extends QRMatrix{ * @codeCoverageIgnore * @throws \chillerlan\QRCode\Data\QRCodeDataException */ - public function setQuietZone(int $quietZoneSize = null):self{ + public function setQuietZone(?int $quietZoneSize = null):self{ throw new QRCodeDataException('not supported'); } @@ -423,7 +423,7 @@ final class BitMatrix extends QRMatrix{ * @codeCoverageIgnore * @throws \chillerlan\QRCode\Data\QRCodeDataException */ - public function setLogoSpace(int $width, int $height = null, int $startX = null, int $startY = null):self{ + public function setLogoSpace(int $width, ?int $height = null, ?int $startX = null, ?int $startY = null):self{ throw new QRCodeDataException('not supported'); } diff --git a/src/Decoder/DecoderResult.php b/src/Decoder/DecoderResult.php index 02b4d7931..13fd24ba8 100644 --- a/src/Decoder/DecoderResult.php +++ b/src/Decoder/DecoderResult.php @@ -41,7 +41,7 @@ final class DecoderResult{ /** * DecoderResult constructor. */ - public function __construct(iterable $properties = null){ + public function __construct(?iterable $properties = null){ if(!empty($properties)){ diff --git a/src/Detector/Detector.php b/src/Detector/Detector.php index e43798b9f..123b685c6 100644 --- a/src/Detector/Detector.php +++ b/src/Detector/Detector.php @@ -305,11 +305,11 @@ final class Detector{ * */ private function createTransform( - FinderPattern $nw, - FinderPattern $ne, - FinderPattern $sw, - int $size, - AlignmentPattern $ap = null + FinderPattern $nw, + FinderPattern $ne, + FinderPattern $sw, + int $size, + ?AlignmentPattern $ap = null ):PerspectiveTransform{ $dimMinusThree = ($size - 3.5); diff --git a/src/Detector/FinderPattern.php b/src/Detector/FinderPattern.php index 1f799e87e..3ae4650ad 100644 --- a/src/Detector/FinderPattern.php +++ b/src/Detector/FinderPattern.php @@ -27,7 +27,7 @@ final class FinderPattern extends ResultPoint{ /** * */ - public function __construct(float $posX, float $posY, float $estimatedModuleSize, int $count = null){ + public function __construct(float $posX, float $posY, float $estimatedModuleSize, ?int $count = null){ parent::__construct($posX, $posY, $estimatedModuleSize); $this->count = ($count ?? 1); diff --git a/src/Detector/PerspectiveTransform.php b/src/Detector/PerspectiveTransform.php index 4f1f6547a..7964092e3 100644 --- a/src/Detector/PerspectiveTransform.php +++ b/src/Detector/PerspectiveTransform.php @@ -152,7 +152,7 @@ final class PerspectiveTransform{ /** * @return array[] [$xValues, $yValues] */ - public function transformPoints(array $xValues, array $yValues = null):array{ + public function transformPoints(array $xValues, ?array $yValues = null):array{ $max = count($xValues); if($yValues !== null){ // unused diff --git a/src/Output/QREps.php b/src/Output/QREps.php index a04f20d5b..8dba009aa 100644 --- a/src/Output/QREps.php +++ b/src/Output/QREps.php @@ -103,7 +103,7 @@ class QREps extends QROutputAbstract{ /** * @inheritDoc */ - public function dump(string $file = null):string{ + public function dump(?string $file = null):string{ [$width, $height] = $this->getOutputDimensions(); $eps = [ diff --git a/src/Output/QRFpdf.php b/src/Output/QRFpdf.php index 28084c4b0..53ed811ac 100644 --- a/src/Output/QRFpdf.php +++ b/src/Output/QRFpdf.php @@ -121,7 +121,7 @@ class QRFpdf extends QROutputAbstract{ * * @return string|\FPDF */ - public function dump(string $file = null, FPDF $fpdf = null){ + public function dump(?string $file = null, ?FPDF $fpdf = null){ $this->fpdf = ($fpdf ?? $this->initFPDF()); if($this::moduleValueIsValid($this->options->bgColor)){ diff --git a/src/Output/QRGdImage.php b/src/Output/QRGdImage.php index f3ed6ea9d..25db1c902 100644 --- a/src/Output/QRGdImage.php +++ b/src/Output/QRGdImage.php @@ -179,7 +179,7 @@ class QRGdImage extends QROutputAbstract{ * @phan-suppress PhanUndeclaredTypeReturnType, PhanTypeMismatchReturn * @throws \ErrorException */ - public function dump(string $file = null){ + public function dump(?string $file = null){ set_error_handler(function(int $errno, string $errstr):bool{ throw new ErrorException($errstr, $errno); diff --git a/src/Output/QRImagick.php b/src/Output/QRImagick.php index cfd3a581f..214311a93 100644 --- a/src/Output/QRImagick.php +++ b/src/Output/QRImagick.php @@ -112,7 +112,7 @@ class QRImagick extends QROutputAbstract{ * * @return string|\Imagick */ - public function dump(string $file = null){ + public function dump(?string $file = null){ $this->setBgColor(); $this->imagick = $this->createImage(); diff --git a/src/Output/QRMarkup.php b/src/Output/QRMarkup.php index 22551e3e6..240bd45ad 100644 --- a/src/Output/QRMarkup.php +++ b/src/Output/QRMarkup.php @@ -71,7 +71,7 @@ abstract class QRMarkup extends QROutputAbstract{ /** * @inheritDoc */ - public function dump(string $file = null):string{ + public function dump(?string $file = null):string{ $data = $this->createMarkup($file !== null); $this->saveToFile($data, $file); diff --git a/src/Output/QROutputAbstract.php b/src/Output/QROutputAbstract.php index 7ac64fffa..a2757ac8c 100644 --- a/src/Output/QROutputAbstract.php +++ b/src/Output/QROutputAbstract.php @@ -188,7 +188,7 @@ abstract class QROutputAbstract implements QROutputInterface{ /** * Returns a base64 data URI for the given string and mime type */ - protected function toBase64DataURI(string $data, string $mime = null):string{ + protected function toBase64DataURI(string $data, ?string $mime = null):string{ return sprintf('data:%s;base64,%s', ($mime ?? $this::MIME_TYPE), base64_encode($data)); } @@ -200,7 +200,7 @@ abstract class QROutputAbstract implements QROutputInterface{ * * @throws \chillerlan\QRCode\Output\QRCodeOutputException */ - protected function saveToFile(string $data, string $file = null):void{ + protected function saveToFile(string $data, ?string $file = null):void{ if($file === null){ return; diff --git a/src/Output/QROutputInterface.php b/src/Output/QROutputInterface.php index 919f1ba75..7d2315180 100644 --- a/src/Output/QROutputInterface.php +++ b/src/Output/QROutputInterface.php @@ -221,6 +221,6 @@ interface QROutputInterface{ * * @return mixed */ - public function dump(string $file = null); + public function dump(?string $file = null); } diff --git a/src/Output/QRString.php b/src/Output/QRString.php index cb70a6cce..2d6d052d6 100644 --- a/src/Output/QRString.php +++ b/src/Output/QRString.php @@ -46,7 +46,7 @@ class QRString extends QROutputAbstract{ /** * @inheritDoc */ - public function dump(string $file = null):string{ + public function dump(?string $file = null):string{ switch($this->options->outputType){ case QROutputInterface::STRING_TEXT: @@ -101,7 +101,7 @@ class QRString extends QROutputAbstract{ * * @codeCoverageIgnore */ - public static function ansi8(string $str, int $color, bool $background = null):string{ + public static function ansi8(string $str, int $color, ?bool $background = null):string{ $color = max(0, min($color, 255)); $background = ($background === true) ? 48 : 38; diff --git a/src/Output/QRStringJSON.php b/src/Output/QRStringJSON.php index 6f2e7d5e0..1a7447c46 100644 --- a/src/Output/QRStringJSON.php +++ b/src/Output/QRStringJSON.php @@ -25,7 +25,7 @@ class QRStringJSON extends QROutputAbstract{ * @inheritDoc * @throws \JsonException */ - public function dump(string $file = null):string{ + public function dump(?string $file = null):string{ $matrix = $this->matrix->getMatrix($this->options->jsonAsBooleans); $data = json_encode($matrix, $this->options->jsonFlags);; diff --git a/src/Output/QRStringText.php b/src/Output/QRStringText.php index f475a2a68..a91591da7 100644 --- a/src/Output/QRStringText.php +++ b/src/Output/QRStringText.php @@ -43,7 +43,7 @@ class QRStringText extends QROutputAbstract{ /** * @inheritDoc */ - public function dump(string $file = null):string{ + public function dump(?string $file = null):string{ $lines = []; $linestart = $this->options->textLineStart; @@ -66,7 +66,7 @@ class QRStringText extends QROutputAbstract{ * * @codeCoverageIgnore */ - public static function ansi8(string $str, int $color, bool $background = null):string{ + public static function ansi8(string $str, int $color, ?bool $background = null):string{ $color = max(0, min($color, 255)); $background = ($background === true) ? 48 : 38; diff --git a/src/QRCode.php b/src/QRCode.php index bca6ac584..9b9f5400f 100755 --- a/src/QRCode.php +++ b/src/QRCode.php @@ -182,7 +182,7 @@ class QRCode{ * * PHP8: accept iterable */ - public function __construct(SettingsContainerInterface $options = null){ + public function __construct(?SettingsContainerInterface $options = null){ $this->setOptions(($options ?? new QROptions)); } @@ -209,7 +209,7 @@ class QRCode{ * * @return mixed */ - public function render(string $data = null, string $file = null){ + public function render(?string $data = null, ?string $file = null){ if($data !== null){ /** @var \chillerlan\QRCode\Data\QRDataModeInterface $dataInterface */ @@ -231,7 +231,7 @@ class QRCode{ * * @return mixed */ - public function renderMatrix(QRMatrix $matrix, string $file = null){ + public function renderMatrix(QRMatrix $matrix, ?string $file = null){ return $this->initOutputInterface($matrix)->dump($file ?? $this->options->cachefile); } diff --git a/tests/Common/ECICharsetTest.php b/tests/Common/ECICharsetTest.php index 660f2cf17..95b6bd891 100644 --- a/tests/Common/ECICharsetTest.php +++ b/tests/Common/ECICharsetTest.php @@ -43,7 +43,7 @@ final class ECICharsetTest extends TestCase{ /** * @dataProvider encodingProvider */ - public function testGetName(int $id, string $name = null):void{ + public function testGetName(int $id, ?string $name = null):void{ $eciCharset = new ECICharset($id); $this::assertSame($id, $eciCharset->getID());