Skip to content

Commit

Permalink
:octocat: mark nullable types explicitly (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Jul 17, 2024
1 parent 0a897ca commit beecbe7
Show file tree
Hide file tree
Showing 28 changed files with 48 additions and 48 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_output.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function getDefaultModuleValue(bool $isDark){
/**
* @inheritDoc
*/
public function dump(string $file = null):string{
public function dump(?string $file = null):string{
$output = '';

for($y = 0; $y < $this->moduleCount; $y++){
Expand Down
2 changes: 1 addition & 1 deletion examples/imageWithLogo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion examples/imageWithText.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion examples/imagickConvertSVGtoPNG.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function header():string{
}

/** @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;
Expand Down
2 changes: 1 addition & 1 deletion examples/imagickWithLogo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/Common/GDLuminanceSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -85,12 +85,12 @@ protected function setLuminancePixels():void{
}

/** @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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Common/GenericGFPoly.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand Down
6 changes: 3 additions & 3 deletions src/Common/IMagickLuminanceSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,12 +63,12 @@ protected function setLuminancePixels():void{
}

/** @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);

Expand Down
2 changes: 1 addition & 1 deletion src/Common/LuminanceSourceAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/Data/QRMatrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function initFunctionalPatterns():self{
*
* @return int[][]|bool[][]
*/
public function getMatrix(bool $boolean = null):array{
public function getMatrix(?bool $boolean = null):array{

if($boolean !== true){
return $this->matrix;
Expand All @@ -195,7 +195,7 @@ public function getMatrix(bool $boolean = null):array{
* @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);
}

Expand Down Expand Up @@ -387,7 +387,7 @@ public function isDark(int $M_TYPE):bool{
* 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]){
Expand Down Expand Up @@ -552,7 +552,7 @@ public function setVersionNumber():self{
*
* 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)

Expand Down Expand Up @@ -678,7 +678,7 @@ public function invert():self{
*
* @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
Expand Down
4 changes: 2 additions & 2 deletions src/Decoder/BitMatrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,15 @@ private function numBitsDiffering(int $a, int $b):int{
* @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');
}

/**
* @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');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Decoder/DecoderResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final class DecoderResult{
/**
* DecoderResult constructor.
*/
public function __construct(iterable $properties = null){
public function __construct(?iterable $properties = null){

if(!empty($properties)){

Expand Down
10 changes: 5 additions & 5 deletions src/Detector/Detector.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,11 @@ private function findAlignmentInRegion(
*
*/
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);

Expand Down
2 changes: 1 addition & 1 deletion src/Detector/FinderPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Detector/PerspectiveTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private function times(PerspectiveTransform $other):self{
/**
* @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
Expand Down
2 changes: 1 addition & 1 deletion src/Output/QREps.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected function formatColor(array $values):string{
/**
* @inheritDoc
*/
public function dump(string $file = null):string{
public function dump(?string $file = null):string{
[$width, $height] = $this->getOutputDimensions();

$eps = [
Expand Down
2 changes: 1 addition & 1 deletion src/Output/QRFpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected function initFPDF():FPDF{
*
* @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)){
Expand Down
2 changes: 1 addition & 1 deletion src/Output/QRGdImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ protected function getDefaultModuleValue(bool $isDark):int{
* @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);
Expand Down
2 changes: 1 addition & 1 deletion src/Output/QRImagick.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected function getDefaultModuleValue(bool $isDark):ImagickPixel{
*
* @return string|\Imagick
*/
public function dump(string $file = null){
public function dump(?string $file = null){
$this->setBgColor();

$this->imagick = $this->createImage();
Expand Down
2 changes: 1 addition & 1 deletion src/Output/QRMarkup.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function getDefaultModuleValue(bool $isDark):string{
/**
* @inheritDoc
*/
public function dump(string $file = null):string{
public function dump(?string $file = null):string{
$data = $this->createMarkup($file !== null);

$this->saveToFile($data, $file);
Expand Down
4 changes: 2 additions & 2 deletions src/Output/QROutputAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ protected function getModuleValueAt(int $x, int $y){
/**
* 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));
}

Expand All @@ -200,7 +200,7 @@ protected function toBase64DataURI(string $data, string $mime = null):string{
*
* @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;
Expand Down
2 changes: 1 addition & 1 deletion src/Output/QROutputInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,6 @@ public static function moduleValueIsValid($value):bool;
*
* @return mixed
*/
public function dump(string $file = null);
public function dump(?string $file = null);

}
4 changes: 2 additions & 2 deletions src/Output/QRString.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function getDefaultModuleValue(bool $isDark):string{
/**
* @inheritDoc
*/
public function dump(string $file = null):string{
public function dump(?string $file = null):string{

switch($this->options->outputType){
case QROutputInterface::STRING_TEXT:
Expand Down Expand Up @@ -101,7 +101,7 @@ protected function json():string{
*
* @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;

Expand Down
2 changes: 1 addition & 1 deletion src/Output/QRStringJSON.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);;

Expand Down
4 changes: 2 additions & 2 deletions src/Output/QRStringText.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function getDefaultModuleValue(bool $isDark):string{
/**
* @inheritDoc
*/
public function dump(string $file = null):string{
public function dump(?string $file = null):string{
$lines = [];
$linestart = $this->options->textLineStart;

Expand All @@ -66,7 +66,7 @@ public function dump(string $file = null):string{
*
* @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;

Expand Down
6 changes: 3 additions & 3 deletions src/QRCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -209,7 +209,7 @@ public function setOptions(SettingsContainerInterface $options):self{
*
* @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 */
Expand All @@ -231,7 +231,7 @@ public function render(string $data = null, string $file = null){
*
* @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);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Common/ECICharsetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function encodingProvider():array{
/**
* @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());
Expand Down

0 comments on commit beecbe7

Please sign in to comment.