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

This commit is contained in:
smiley
2024-07-17 11:43:55 +02:00
parent f5e243f3b6
commit f6c4da9ce4
17 changed files with 27 additions and 27 deletions
+2 -2
View File
@@ -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.",
+1 -1
View File
@@ -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 = '';
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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;
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -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;
}
+5 -5
View File
@@ -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){
+2 -2
View File
@@ -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);
+1 -1
View File
@@ -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]);
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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;
+2 -2
View File
@@ -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)
? '<div>'
@@ -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)
+1 -1
View File
@@ -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
+1 -1
View File
@@ -52,6 +52,6 @@ interface QROutputInterface{
*
* @return mixed
*/
public function dump(string $file = null);
public function dump(?string $file = null);
}
+2 -2
View File
@@ -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());
}
+2 -2
View File
@@ -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);
}