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 f5e243f commit f6c4da9
Show file tree
Hide file tree
Showing 17 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_output.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected function setModuleValues():void{
// TODO: Implement setModuleValues() method.
}

public function dump(string $file = null){
public function dump(?string $file = null){

$output = '';

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions src/Data/QRDataAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -100,7 +100,7 @@ public function setData(string $data):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)
Expand Down
2 changes: 1 addition & 1 deletion src/Data/QRDataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,6 @@ public function setData(string $data):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;

}
10 changes: 5 additions & 5 deletions src/Data/QRMatrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public function __construct(int $version, int $eclevel){
/**
* 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()
Expand Down Expand Up @@ -516,7 +516,7 @@ public function setTimingPattern():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){
Expand All @@ -540,7 +540,7 @@ public function setVersionNumber(bool $test = null):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++){
Expand Down Expand Up @@ -580,7 +580,7 @@ public function setFormatInfo(int $maskPattern, bool $test = null):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');
Expand Down Expand Up @@ -627,7 +627,7 @@ public function setQuietZone(int $size = null):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){
Expand Down
4 changes: 2 additions & 2 deletions src/Helpers/Polynomial.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -86,7 +86,7 @@ public function getNum():array{
*
* @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);

Expand Down
2 changes: 1 addition & 1 deletion src/Output/QRFpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function setModuleValues():void{
*
* @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]);
Expand Down
2 changes: 1 addition & 1 deletion src/Output/QRImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected function setModuleValues():void{
*
* @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);
Expand Down
2 changes: 1 addition & 1 deletion src/Output/QRImagick.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected function setModuleValues():void{
*
* @return string|\Imagick
*/
public function dump(string $file = null){
public function dump(?string $file = null){
$file ??= $this->options->cachefile;
$this->imagick = new Imagick;

Expand Down
4 changes: 2 additions & 2 deletions src/Output/QRMarkup.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function setModuleValues():void{
/**
* HTML output
*/
protected function html(string $file = null):string{
protected function html(?string $file = null):string{

$html = empty($this->options->cssClass)
? '<div>'
Expand Down Expand Up @@ -89,7 +89,7 @@ protected function html(string $file = null):string{
*
* @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)
Expand Down
2 changes: 1 addition & 1 deletion src/Output/QROutputAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected function saveToFile(string $data, string $file):bool{
/**
* @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
Expand Down
2 changes: 1 addition & 1 deletion src/Output/QROutputInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ interface QROutputInterface{
*
* @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 @@ -50,7 +50,7 @@ protected function setModuleValues():void{
/**
* string output
*/
protected function text(string $file = null):string{
protected function text(?string $file = null):string{
$str = [];

foreach($this->matrix->matrix() as $row){
Expand All @@ -69,7 +69,7 @@ protected function text(string $file = null):string{
/**
* JSON output
*/
protected function json(string $file = null):string{
protected function json(?string $file = null):string{
return json_encode($this->matrix->matrix());
}

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

Expand All @@ -176,7 +176,7 @@ public function __construct(SettingsContainerInterface $options = null){
*
* @return mixed
*/
public function render(string $data, string $file = null){
public function render(string $data, ?string $file = null){
return $this->initOutputInterface($data)->dump($file);
}

Expand Down

0 comments on commit f6c4da9

Please sign in to comment.