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

This commit is contained in:
smiley
2024-07-17 10:19:31 +02:00
parent a702ac3193
commit 1a8e1ffd2b
31 changed files with 70 additions and 70 deletions
+3 -3
View File
@@ -49,17 +49,17 @@
"require": {
"php": "^8.2",
"ext-mbstring": "*",
"chillerlan/php-settings-container": "^3.2"
"chillerlan/php-settings-container": "^3.2.1"
},
"require-dev": {
"chillerlan/php-authenticator": "^5.1",
"chillerlan/php-authenticator": "^5.2.1",
"intervention/image": "^3.7",
"phpbench/phpbench": "^1.2.15",
"phan/phan": "^5.4",
"phpunit/phpunit": "^11.2",
"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
View File
@@ -48,7 +48,7 @@ class MyCustomOutput extends QROutputAbstract{
/**
* @inheritDoc
*/
public function dump(string $file = null):string{
public function dump(string|null $file = null):string{
$output = '';
for($y = 0; $y < $this->moduleCount; $y++){
+1 -1
View File
@@ -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|null $file = null, string|null $logo = null):string{
// set returnResource to true to skip further processing for now
$this->options->returnResource = true;
+1 -1
View File
@@ -26,7 +26,7 @@ class QRImageWithText extends QRGdImagePNG{
/**
* @inheritDoc
*/
public function dump(string $file = null, string $text = null):string{
public function dump(string|null $file = null, string|null $text = null):string{
// set returnResource to true to skip further processing for now
$this->options->returnResource = true;
+1 -1
View File
@@ -47,7 +47,7 @@ class SVGConvert extends QRMarkupSVG{
}
/** @inheritDoc */
public function dump(string $file = null):string{
public function dump(string|null $file = null):string{
$base64 = $this->options->outputBase64;
// we don't want the SVG in base64
$this->options->outputBase64 = false;
+1 -1
View File
@@ -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|null $file = null):string{
// set returnResource to true to skip further processing for now
$this->options->returnResource = true;
+1 -1
View File
@@ -118,7 +118,7 @@ final class ECICharset{
* @see \mb_convert_encoding()
* @see \iconv()
*/
public function getName():?string{
public function getName():string|null{
return (self::MB_ENCODINGS[$this->charsetID] ?? null);
}
+1 -1
View File
@@ -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|null $degree = null){
$degree ??= 0;
if(empty($coefficients)){
+1 -1
View File
@@ -257,7 +257,7 @@ final class Version{
/**
* the version pattern for the given version
*/
public function getVersionPattern():?int{
public function getVersionPattern():int|null{
return (self::VERSION_PATTERN[$this->version] ?? null);
}
+10 -10
View File
@@ -110,12 +110,12 @@ class QRMatrix{
/**
* the matrix version - always set in QRMatrix, may be null in BitMatrix
*/
protected ?Version $version = null;
protected Version|null $version = null;
/**
* the current ECC level - always set in QRMatrix, may be null in BitMatrix
*/
protected ?EccLevel $eccLevel = null;
protected EccLevel|null $eccLevel = null;
/**
* the mask pattern that was used in the most recent operation, set via:
@@ -124,7 +124,7 @@ class QRMatrix{
* - QRMatrix::mask()
* - BitMatrix::readFormatInformation()
*/
protected ?MaskPattern $maskPattern = null;
protected MaskPattern|null $maskPattern = null;
/**
* the size (side length) of the matrix, including quiet zone (if created)
@@ -175,7 +175,7 @@ class QRMatrix{
*
* @return int[][]|bool[][]
*/
public function getMatrix(bool $boolean = null):array{
public function getMatrix(bool|null $boolean = null):array{
if($boolean !== true){
return $this->matrix;
@@ -193,21 +193,21 @@ class QRMatrix{
/**
* Returns the current version number
*/
public function getVersion():?Version{
public function getVersion():Version|null{
return $this->version;
}
/**
* Returns the current ECC level
*/
public function getEccLevel():?EccLevel{
public function getEccLevel():EccLevel|null{
return $this->eccLevel;
}
/**
* Returns the current mask pattern
*/
public function getMaskPattern():?MaskPattern{
public function getMaskPattern():MaskPattern|null{
return $this->maskPattern;
}
@@ -342,7 +342,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|null $M_TYPE = null):int{
$bits = 0;
foreach($this::neighbours as $bit => [$ix, $iy]){
@@ -507,7 +507,7 @@ class QRMatrix{
*
* ISO/IEC 18004:2000 Section 8.9
*/
public function setFormatInfo(MaskPattern $maskPattern = null):static{
public function setFormatInfo(MaskPattern|null $maskPattern = null):static{
$this->maskPattern = $maskPattern;
$bits = 0; // sets all format fields to false (test mode)
@@ -633,7 +633,7 @@ class QRMatrix{
*
* @throws \chillerlan\QRCode\Data\QRCodeDataException
*/
public function setLogoSpace(int $width, int $height = null, int $startX = null, int $startY = null):static{
public function setLogoSpace(int $width, int|null $height = null, int|null $startX = null, int|null $startY = null):static{
$height ??= $width;
// if width and height happen to be negative or 0 (default value), just return - nothing to do
+4 -4
View File
@@ -251,7 +251,7 @@ final class BitMatrix extends QRMatrix{
/**
* Returns information about the format it specifies, or null if it doesn't seem to match any known pattern
*/
private function doDecodeFormatInformation(int $maskedFormatInfo1, int $maskedFormatInfo2):?int{
private function doDecodeFormatInformation(int $maskedFormatInfo1, int $maskedFormatInfo2):int|null{
$bestDifference = PHP_INT_MAX;
$bestFormatInfo = 0;
@@ -347,7 +347,7 @@ final class BitMatrix extends QRMatrix{
/**
* Decodes the version information from the given bit sequence, returns null if no valid match is found.
*/
private function decodeVersionInformation(int $versionBits):?Version{
private function decodeVersionInformation(int $versionBits):Version|null{
$bestDifference = PHP_INT_MAX;
$bestVersion = 0;
@@ -414,7 +414,7 @@ final class BitMatrix extends QRMatrix{
* @codeCoverageIgnore
* @throws \chillerlan\QRCode\Data\QRCodeDataException
*/
public function setQuietZone(int $quietZoneSize = null):static{
public function setQuietZone(int|null $quietZoneSize = null):static{
throw new QRCodeDataException('not supported');
}
@@ -422,7 +422,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):static{
public function setLogoSpace(int $width, int|null $height = null, int|null $startX = null, int|null $startY = null):static{
throw new QRCodeDataException('not supported');
}
+3 -3
View File
@@ -31,9 +31,9 @@ final class Decoder{
* @var \chillerlan\QRCode\QROptions|\chillerlan\Settings\SettingsContainerInterface
*/
private SettingsContainerInterface|QROptions $options;
private ?Version $version = null;
private ?EccLevel $eccLevel = null;
private ?MaskPattern $maskPattern = null;
private Version|null $version = null;
private EccLevel|null $eccLevel = null;
private MaskPattern|null $maskPattern = null;
private BitBuffer $bitBuffer;
public function __construct(SettingsContainerInterface|QROptions $options = new QROptions){
+1 -1
View File
@@ -41,7 +41,7 @@ final class DecoderResult{
/**
* DecoderResult constructor.
*/
public function __construct(iterable $properties = null){
public function __construct(iterable|null $properties = null){
if(!empty($properties)){
+3 -3
View File
@@ -58,7 +58,7 @@ final class AlignmentPatternFinder{
*
* @return \chillerlan\QRCode\Detector\AlignmentPattern|null
*/
public function find(int $startX, int $startY, int $width, int $height):?AlignmentPattern{
public function find(int $startX, int $startY, int $width, int $height):AlignmentPattern|null{
$maxJ = ($startX + $width);
$middleI = ($startY + ($height / 2));
$stateCount = [];
@@ -173,7 +173,7 @@ final class AlignmentPatternFinder{
*
* @return \chillerlan\QRCode\Detector\AlignmentPattern|null if we have found the same pattern twice, or null if not
*/
private function handlePossibleCenter(array $stateCount, int $i, int $j):?AlignmentPattern{
private function handlePossibleCenter(array $stateCount, int $i, int $j):AlignmentPattern|null{
$stateCountTotal = ($stateCount[0] + $stateCount[1] + $stateCount[2]);
$centerJ = $this->centerFromEnd($stateCount, $j);
$centerI = $this->crossCheckVertical($i, (int)$centerJ, (2 * $stateCount[1]), $stateCountTotal);
@@ -222,7 +222,7 @@ final class AlignmentPatternFinder{
*
* @return float|null vertical center of alignment pattern, or null if not found
*/
private function crossCheckVertical(int $startI, int $centerJ, int $maxCount, int $originalStateCountTotal):?float{
private function crossCheckVertical(int $startI, int $centerJ, int $maxCount, int $originalStateCountTotal):float|null{
$maxI = $this->matrix->getSize();
$stateCount = [];
$stateCount[0] = 0;
+6 -6
View File
@@ -275,7 +275,7 @@ final class Detector{
int $estAlignmentX,
int $estAlignmentY,
float $allowanceFactor
):?AlignmentPattern{
):AlignmentPattern|null{
// Look for an alignment pattern (3 modules in size) around where it should be
$dimension = $this->matrix->getSize();
$allowance = (int)($allowanceFactor * $overallEstModuleSize);
@@ -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|null $ap = null
):PerspectiveTransform{
$dimMinusThree = ($size - 3.5);
+1 -1
View File
@@ -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|null $count = null){
parent::__construct($posX, $posY, $estimatedModuleSize);
$this->count = ($count ?? 1);
+2 -2
View File
@@ -330,7 +330,7 @@ final class FinderPatternFinder{
* @return float|null vertical center of finder pattern, or null if not found
* @noinspection DuplicatedCode
*/
private function crossCheckVertical(int $startI, int $centerJ, int $maxCount, int $originalStateCountTotal):?float{
private function crossCheckVertical(int $startI, int $centerJ, int $maxCount, int $originalStateCountTotal):float|null{
$maxI = $this->matrix->getSize();
$stateCount = $this->getCrossCheckStateCount();
@@ -414,7 +414,7 @@ final class FinderPatternFinder{
* check a vertical cross-check and locate the real center of the alignment pattern.
* @noinspection DuplicatedCode
*/
private function crossCheckHorizontal(int $startJ, int $centerI, int $maxCount, int $originalStateCountTotal):?float{
private function crossCheckHorizontal(int $startJ, int $centerI, int $maxCount, int $originalStateCountTotal):float|null{
$maxJ = $this->matrix->getSize();
$stateCount = $this->getCrossCheckStateCount();
+1 -1
View File
@@ -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|null $yValues = null):array{
$max = count($xValues);
if($yValues !== null){ // unused
+1 -1
View File
@@ -101,7 +101,7 @@ class QREps extends QROutputAbstract{
/**
* @inheritDoc
*/
public function dump(string $file = null):string{
public function dump(string|null $file = null):string{
[$width, $height] = $this->getOutputDimensions();
$eps = [
+3 -3
View File
@@ -29,8 +29,8 @@ class QRFpdf extends QROutputAbstract{
final public const MIME_TYPE = 'application/pdf';
protected FPDF $fpdf;
protected ?array $prevColor = null;
protected FPDF $fpdf;
protected array|null $prevColor = null;
/**
* QRFpdf constructor.
@@ -64,7 +64,7 @@ class QRFpdf extends QROutputAbstract{
/**
* @inheritDoc
*/
public function dump(string $file = null, FPDF $fpdf = null):string|FPDF{
public function dump(string|null $file = null, FPDF|null $fpdf = null):string|FPDF{
$this->fpdf = ($fpdf ?? $this->initFPDF());
if($this::moduleValueIsValid($this->options->bgColor)){
+1 -1
View File
@@ -144,7 +144,7 @@ abstract class QRGdImage extends QROutputAbstract{
*
* @throws \ErrorException
*/
public function dump(string $file = null):string|GdImage{
public function dump(string|null $file = null):string|GdImage{
set_error_handler(function(int $errno, string $errstr):bool{
throw new ErrorException($errstr, $errno);
+1 -1
View File
@@ -111,7 +111,7 @@ class QRImagick extends QROutputAbstract{
/**
* @inheritDoc
*/
public function dump(string $file = null):string|Imagick{
public function dump(string|null $file = null):string|Imagick{
$this->setBgColor();
$this->imagick = $this->createImage();
+1 -1
View File
@@ -85,7 +85,7 @@ class QRInterventionImage extends QROutputAbstract{
/**
* @inheritDoc
*/
public function dump(string $file = null):string|ImageInterface{
public function dump(string|null $file = null):string|ImageInterface{
[$width, $height] = $this->getOutputDimensions();
$this->image = $this->manager->create($width, $height);
+1 -1
View File
@@ -19,7 +19,7 @@ abstract class QRMarkup extends QROutputAbstract{
/**
* @inheritDoc
*/
public function dump(string $file = null):string{
public function dump(string|null $file = null):string{
$saveToFile = $file !== null;
$data = $this->createMarkup($saveToFile);
+2 -2
View File
@@ -180,7 +180,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|null $mime = null):string{
return sprintf('data:%s;base64,%s', ($mime ?? static::MIME_TYPE), base64_encode($data));
}
@@ -192,7 +192,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|null $file = null):void{
if($file === null){
return;
+1 -1
View File
@@ -129,6 +129,6 @@ interface QROutputInterface{
*
* @see \chillerlan\QRCode\QRCode::renderMatrix()
*/
public function dump(string $file = null):mixed;
public function dump(string|null $file = null):mixed;
}
+1 -1
View File
@@ -34,7 +34,7 @@ class QRStringJSON extends QROutputAbstract{
* @inheritDoc
* @throws \JsonException
*/
public function dump(string $file = null):string{
public function dump(string|null $file = null):string{
[$width, $height] = $this->getOutputDimensions();
$version = $this->matrix->getVersion();
$dimension = $version->getDimension();
+2 -2
View File
@@ -43,7 +43,7 @@ class QRStringText extends QROutputAbstract{
/**
* @inheritDoc
*/
public function dump(string $file = null):string{
public function dump(string|null $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|null $background = null):string{
$color = max(0, min($color, 255));
$background = ($background === true) ? 48 : 38;
+2 -2
View File
@@ -77,7 +77,7 @@ class QRCode{
/**
* Renders a QR Code for the given $data and QROptions, saves $file optionally
*/
public function render(string $data = null, string $file = null):mixed{
public function render(string|null $data = null, string|null $file = null):mixed{
if($data !== null){
/** @var \chillerlan\QRCode\Data\QRDataModeInterface $dataInterface */
@@ -97,7 +97,7 @@ class QRCode{
/**
* Renders a QR Code for the given QRMatrix and QROptions, saves $file optionally
*/
public function renderMatrix(QRMatrix $matrix, string $file = null):mixed{
public function renderMatrix(QRMatrix $matrix, string|null $file = null):mixed{
return $this->initOutputInterface($matrix)->dump($file ?? $this->options->cachefile);
}
+11 -11
View File
@@ -125,7 +125,7 @@ trait QROptionsTrait{
* @see \chillerlan\QRCode\QRCode::render()
* @see \chillerlan\QRCode\QRCode::renderMatrix()
*/
protected ?string $cachefile = null;
protected string|null $cachefile = null;
/**
* Toggle base64 data URI or raw data output (if applicable)
@@ -249,24 +249,24 @@ trait QROptionsTrait{
*
* if only `QROptions::$logoSpaceWidth` is given, the logo space is assumed a square of that size
*/
protected ?int $logoSpaceWidth = null;
protected int|null $logoSpaceWidth = null;
/**
* Height of the logo space
*
* if only `QROptions::$logoSpaceHeight` is given, the logo space is assumed a square of that size
*/
protected ?int $logoSpaceHeight = null;
protected int|null $logoSpaceHeight = null;
/**
* Optional horizontal start position of the logo space (top left corner)
*/
protected ?int $logoSpaceStartX = null;
protected int|null $logoSpaceStartX = null;
/**
* Optional vertical start position of the logo space (top left corner)
*/
protected ?int $logoSpaceStartY = null;
protected int|null $logoSpaceStartY = null;
/*
@@ -431,7 +431,7 @@ trait QROptionsTrait{
*
* @see https://developer.mozilla.org/en-US/docs/Web/XSLT
*/
protected ?string $xmlStylesheet = null;
protected string|null $xmlStylesheet = null;
/**
@@ -517,7 +517,7 @@ trait QROptionsTrait{
/**
* clamp the logo space values between 0 and maximum length (177 modules at version 40)
*/
protected function clampLogoSpaceValue(?int $value):?int{
protected function clampLogoSpaceValue(int|null $value):int|null{
if($value === null){
return null;
@@ -529,28 +529,28 @@ trait QROptionsTrait{
/**
* clamp/set logo space width
*/
protected function set_logoSpaceWidth(?int $value):void{
protected function set_logoSpaceWidth(int|null $value):void{
$this->logoSpaceWidth = $this->clampLogoSpaceValue($value);
}
/**
* clamp/set logo space height
*/
protected function set_logoSpaceHeight(?int $value):void{
protected function set_logoSpaceHeight(int|null $value):void{
$this->logoSpaceHeight = $this->clampLogoSpaceValue($value);
}
/**
* clamp/set horizontal logo space start
*/
protected function set_logoSpaceStartX(?int $value):void{
protected function set_logoSpaceStartX(int|null $value):void{
$this->logoSpaceStartX = $this->clampLogoSpaceValue($value);
}
/**
* clamp/set vertical logo space start
*/
protected function set_logoSpaceStartY(?int $value):void{
protected function set_logoSpaceStartY(int|null $value):void{
$this->logoSpaceStartY = $this->clampLogoSpaceValue($value);
}
+1 -1
View File
@@ -40,7 +40,7 @@ final class ECICharsetTest extends TestCase{
}
#[DataProvider('encodingProvider')]
public function testGetName(int $id, string $name = null):void{
public function testGetName(int $id, string|null $name = null):void{
$eciCharset = new ECICharset($id);
$this::assertSame($id, $eciCharset->getID());