From f6c4da9ce405b5a7815c8d882b3d85c5514f6f1d Mon Sep 17 00:00:00 2001 From: smiley Date: Wed, 17 Jul 2024 11:43:55 +0200 Subject: [PATCH] :octocat: mark nullable types explicitly (https://github.com/chillerlan/php-qrcode/issues/276) --- composer.json | 4 ++-- examples/custom_output.php | 2 +- examples/imageWithLogo.php | 2 +- examples/imageWithText.php | 2 +- examples/text.php | 2 +- src/Data/QRDataAbstract.php | 4 ++-- src/Data/QRDataInterface.php | 2 +- src/Data/QRMatrix.php | 10 +++++----- src/Helpers/Polynomial.php | 4 ++-- src/Output/QRFpdf.php | 2 +- src/Output/QRImage.php | 2 +- src/Output/QRImagick.php | 2 +- src/Output/QRMarkup.php | 4 ++-- src/Output/QROutputAbstract.php | 2 +- src/Output/QROutputInterface.php | 2 +- src/Output/QRString.php | 4 ++-- src/QRCode.php | 4 ++-- 17 files changed, 27 insertions(+), 27 deletions(-) diff --git a/composer.json b/composer.json index 97d8bbe84..d0a0672d3 100644 --- a/composer.json +++ b/composer.json @@ -26,14 +26,14 @@ "require": { "php": "^7.4 || ^8.0", "ext-mbstring": "*", - "chillerlan/php-settings-container": "^2.1.4 || ^3.1" + "chillerlan/php-settings-container": "^2.1.6 || ^3.2.1" }, "require-dev": { "phan/phan": "^5.4", "phpmd/phpmd": "^2.15", "phpunit/phpunit": "^9.6", "setasign/fpdf": "^1.8.2", - "squizlabs/php_codesniffer": "^3.8" + "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 6804fa508..53ada2148 100644 --- a/examples/custom_output.php +++ b/examples/custom_output.php @@ -19,7 +19,7 @@ class MyCustomOutput extends QROutputAbstract{ // TODO: Implement setModuleValues() method. } - public function dump(string $file = null){ + public function dump(?string $file = null){ $output = ''; diff --git a/examples/imageWithLogo.php b/examples/imageWithLogo.php index b178d5077..5c1c17e89 100644 --- a/examples/imageWithLogo.php +++ b/examples/imageWithLogo.php @@ -22,7 +22,7 @@ class QRImageWithLogo extends QRImage{ * @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 c23fed8dc..ce7340333 100644 --- a/examples/imageWithText.php +++ b/examples/imageWithText.php @@ -24,7 +24,7 @@ class QRImageWithText extends QRImage{ * * @return string */ - 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/text.php b/examples/text.php index ab4c81f21..d6ab1e664 100644 --- a/examples/text.php +++ b/examples/text.php @@ -19,7 +19,7 @@ require_once __DIR__.'/../vendor/autoload.php'; * * @codeCoverageIgnore */ -function ansi8(string $str, int $color, bool $background = null):string{ +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/Data/QRDataAbstract.php b/src/Data/QRDataAbstract.php index 72b67b7b9..5d5b3aaf2 100644 --- a/src/Data/QRDataAbstract.php +++ b/src/Data/QRDataAbstract.php @@ -70,7 +70,7 @@ abstract class QRDataAbstract implements QRDataInterface{ /** * QRDataInterface constructor. */ - public function __construct(SettingsContainerInterface $options, string $data = null){ + public function __construct(SettingsContainerInterface $options, ?string $data = null){ $this->options = $options; if($data !== null){ @@ -100,7 +100,7 @@ abstract class QRDataAbstract implements QRDataInterface{ /** * @inheritDoc */ - public function initMatrix(int $maskPattern, bool $test = null):QRMatrix{ + public function initMatrix(int $maskPattern, ?bool $test = null):QRMatrix{ return (new QRMatrix($this->version, $this->options->eccLevel)) ->init($maskPattern, $test) ->mapData($this->maskECC(), $maskPattern) diff --git a/src/Data/QRDataInterface.php b/src/Data/QRDataInterface.php index c6cd92372..4e8aa9406 100644 --- a/src/Data/QRDataInterface.php +++ b/src/Data/QRDataInterface.php @@ -195,6 +195,6 @@ interface QRDataInterface{ /** * returns a fresh matrix object with the data written for the given $maskPattern */ - public function initMatrix(int $maskPattern, bool $test = null):QRMatrix; + public function initMatrix(int $maskPattern, ?bool $test = null):QRMatrix; } diff --git a/src/Data/QRMatrix.php b/src/Data/QRMatrix.php index 9212a609f..3bdae926a 100755 --- a/src/Data/QRMatrix.php +++ b/src/Data/QRMatrix.php @@ -286,7 +286,7 @@ final class QRMatrix{ /** * shortcut to initialize the matrix */ - public function init(int $maskPattern, bool $test = null):QRMatrix{ + public function init(int $maskPattern, ?bool $test = null):QRMatrix{ return $this ->setFinderPattern() ->setSeparators() @@ -516,7 +516,7 @@ final class QRMatrix{ * * ISO/IEC 18004:2000 Section 8.10 */ - public function setVersionNumber(bool $test = null):QRMatrix{ + public function setVersionNumber(?bool $test = null):QRMatrix{ $bits = $this::versionPattern[$this->version] ?? false; if($bits !== false){ @@ -540,7 +540,7 @@ final class QRMatrix{ * * ISO/IEC 18004:2000 Section 8.9 */ - public function setFormatInfo(int $maskPattern, bool $test = null):QRMatrix{ + public function setFormatInfo(int $maskPattern, ?bool $test = null):QRMatrix{ $bits = $this::formatPattern[QRCode::ECC_MODES[$this->eclevel]][$maskPattern] ?? 0; for($i = 0; $i < 15; $i++){ @@ -580,7 +580,7 @@ final class QRMatrix{ * * @throws \chillerlan\QRCode\Data\QRCodeDataException */ - public function setQuietZone(int $size = null):QRMatrix{ + public function setQuietZone(?int $size = null):QRMatrix{ if($this->matrix[$this->moduleCount - 1][$this->moduleCount - 1] === $this::M_NULL){ throw new QRCodeDataException('use only after writing data'); @@ -627,7 +627,7 @@ final class QRMatrix{ * * @throws \chillerlan\QRCode\Data\QRCodeDataException */ - public function setLogoSpace(int $width, int $height, int $startX = null, int $startY = null):QRMatrix{ + public function setLogoSpace(int $width, int $height, ?int $startX = null, ?int $startY = null):QRMatrix{ // for logos we operate in ECC H (30%) only if($this->eclevel !== QRCode::ECC_H){ diff --git a/src/Helpers/Polynomial.php b/src/Helpers/Polynomial.php index 1385422fd..fa4046086 100644 --- a/src/Helpers/Polynomial.php +++ b/src/Helpers/Polynomial.php @@ -69,7 +69,7 @@ final class Polynomial{ /** * Polynomial constructor. */ - public function __construct(array $num = null, int $shift = null){ + public function __construct(?array $num = null, ?int $shift = null){ $this->setNum($num ?? [1], $shift); } @@ -86,7 +86,7 @@ final class Polynomial{ * * @return \chillerlan\QRCode\Helpers\Polynomial */ - public function setNum(array $num, int $shift = null):Polynomial{ + public function setNum(array $num, ?int $shift = null):Polynomial{ $offset = 0; $numCount = count($num); diff --git a/src/Output/QRFpdf.php b/src/Output/QRFpdf.php index a15ae9ff3..b8e6694e8 100644 --- a/src/Output/QRFpdf.php +++ b/src/Output/QRFpdf.php @@ -68,7 +68,7 @@ class QRFpdf extends QROutputAbstract{ * * @return string|\FPDF */ - public function dump(string $file = null){ + public function dump(?string $file = null){ $file ??= $this->options->cachefile; $fpdf = new FPDF('P', $this->options->fpdfMeasureUnit, [$this->length, $this->length]); diff --git a/src/Output/QRImage.php b/src/Output/QRImage.php index 8f533d341..c67c625b2 100644 --- a/src/Output/QRImage.php +++ b/src/Output/QRImage.php @@ -94,7 +94,7 @@ class QRImage extends QROutputAbstract{ * * @phan-suppress PhanUndeclaredTypeReturnType, PhanTypeMismatchReturn */ - public function dump(string $file = null){ + public function dump(?string $file = null){ $file ??= $this->options->cachefile; $this->image = imagecreatetruecolor($this->length, $this->length); diff --git a/src/Output/QRImagick.php b/src/Output/QRImagick.php index 49516d30e..ec0f6d5b0 100644 --- a/src/Output/QRImagick.php +++ b/src/Output/QRImagick.php @@ -67,7 +67,7 @@ class QRImagick extends QROutputAbstract{ * * @return string|\Imagick */ - public function dump(string $file = null){ + public function dump(?string $file = null){ $file ??= $this->options->cachefile; $this->imagick = new Imagick; diff --git a/src/Output/QRMarkup.php b/src/Output/QRMarkup.php index 53120ec6f..1f7843182 100644 --- a/src/Output/QRMarkup.php +++ b/src/Output/QRMarkup.php @@ -53,7 +53,7 @@ class QRMarkup extends QROutputAbstract{ /** * HTML output */ - protected function html(string $file = null):string{ + protected function html(?string $file = null):string{ $html = empty($this->options->cssClass) ? '
' @@ -89,7 +89,7 @@ class QRMarkup extends QROutputAbstract{ * * @see https://github.com/codemasher/php-qrcode/pull/5 */ - protected function svg(string $file = null):string{ + protected function svg(?string $file = null):string{ $matrix = $this->matrix->matrix(); $svg = sprintf($this->svgHeader, $this->options->cssClass, $this->options->svgViewBoxSize ?? $this->moduleCount) diff --git a/src/Output/QROutputAbstract.php b/src/Output/QROutputAbstract.php index 6165e1cc7..78e761093 100644 --- a/src/Output/QROutputAbstract.php +++ b/src/Output/QROutputAbstract.php @@ -113,7 +113,7 @@ abstract class QROutputAbstract implements QROutputInterface{ /** * @inheritDoc */ - public function dump(string $file = null){ + public function dump(?string $file = null){ $file ??= $this->options->cachefile; // call the built-in output method with the optional file path as parameter diff --git a/src/Output/QROutputInterface.php b/src/Output/QROutputInterface.php index b492c27a1..7052701b9 100644 --- a/src/Output/QROutputInterface.php +++ b/src/Output/QROutputInterface.php @@ -52,6 +52,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 3ed5153e1..441ef99fd 100644 --- a/src/Output/QRString.php +++ b/src/Output/QRString.php @@ -50,7 +50,7 @@ class QRString extends QROutputAbstract{ /** * string output */ - protected function text(string $file = null):string{ + protected function text(?string $file = null):string{ $str = []; foreach($this->matrix->matrix() as $row){ @@ -69,7 +69,7 @@ class QRString extends QROutputAbstract{ /** * JSON output */ - protected function json(string $file = null):string{ + protected function json(?string $file = null):string{ return json_encode($this->matrix->matrix()); } diff --git a/src/QRCode.php b/src/QRCode.php index c45b8b573..1dad921e4 100755 --- a/src/QRCode.php +++ b/src/QRCode.php @@ -167,7 +167,7 @@ class QRCode{ * * Sets the options instance, determines the current mb-encoding and sets it to UTF-8 */ - public function __construct(SettingsContainerInterface $options = null){ + public function __construct(?SettingsContainerInterface $options = null){ $this->options = $options ?? new QROptions; } @@ -176,7 +176,7 @@ class QRCode{ * * @return mixed */ - public function render(string $data, string $file = null){ + public function render(string $data, ?string $file = null){ return $this->initOutputInterface($data)->dump($file); }