Bläddra i källkod

:octocat: mark nullable types explicitly (https://github.com/chillerlan/php-qrcode/issues/276)

smiley 1 år sedan
förälder
incheckning
beecbe7ba5

+ 3 - 3
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.",

+ 1 - 1
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++){

+ 1 - 1
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;
 

+ 1 - 1
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;
 

+ 1 - 1
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;

+ 1 - 1
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;
 

+ 3 - 3
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);
 	}
 

+ 1 - 1
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)){

+ 3 - 3
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);
 

+ 1 - 1
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);

+ 5 - 5
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

+ 2 - 2
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');
 	}
 

+ 1 - 1
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)){
 

+ 5 - 5
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);
 

+ 1 - 1
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);

+ 1 - 1
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

+ 1 - 1
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 = [

+ 1 - 1
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)){

+ 1 - 1
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);

+ 1 - 1
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();

+ 1 - 1
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);

+ 2 - 2
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;

+ 1 - 1
src/Output/QROutputInterface.php

@@ -221,6 +221,6 @@ interface QROutputInterface{
 	 *
 	 * @return mixed
 	 */
-	public function dump(string $file = null);
+	public function dump(?string $file = null);
 
 }

+ 2 - 2
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;
 

+ 1 - 1
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);;
 

+ 2 - 2
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;
 

+ 3 - 3
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);
 	}
 

+ 1 - 1
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());