Skip to content

Commit

Permalink
Merge pull request #270 from kohlerdominik/modernize/php81-rector
Browse files Browse the repository at this point in the history
Modernize: PHP81 with rector
  • Loading branch information
sprain authored Dec 7, 2024
2 parents d61a3a3 + fd5087a commit 5881f1c
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 34 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"cs:fix": "vendor/bin/php-cs-fixer fix --verbose",
"cs:diff": "vendor/bin/php-cs-fixer fix --dry-run --diff --verbose",
"phpstan": "vendor/bin/phpstan analyse",
"phpunit": "vendor/bin/phpunit --verbose"
"phpunit": "vendor/bin/phpunit --verbose",
"rector": "vendor/bin/rector"
},
"conflict": {
"khanamiryan/qrcode-detector-decoder": "1.0.6"
Expand Down
4 changes: 2 additions & 2 deletions example/FpdfOutput/fpdf-example.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php declare(strict_types=1);

use Fpdf\Fpdf;
use Sprain\SwissQrBill as QrBill;
use Sprain\SwissQrBill\PaymentPart\Output\DisplayOptions;
use Sprain\SwissQrBill\PaymentPart\Output\FpdfOutput\FpdfOutput;

require __DIR__ . '/../../vendor/autoload.php';

Expand All @@ -26,7 +26,7 @@
$fpdf->AddPage();

// 3. Create a full payment part for FPDF
$output = new QrBill\PaymentPart\Output\FpdfOutput\FpdfOutput($qrBill, 'en', $fpdf);
$output = new FpdfOutput($qrBill, 'en', $fpdf);

// 4. Optional, set layout options
$displayOptions = new DisplayOptions();
Expand Down
4 changes: 2 additions & 2 deletions example/HtmlOutput/html-example.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php declare(strict_types=1);

use Sprain\SwissQrBill as QrBill;
use Sprain\SwissQrBill\PaymentPart\Output\DisplayOptions;
use Sprain\SwissQrBill\PaymentPart\Output\HtmlOutput\HtmlOutput;

require __DIR__ . '/../../vendor/autoload.php';

// 1. Let's load the base example to define the qr bill contents
require __DIR__ . '/../example.php';

// 2. Create a full payment part in HTML
$output = new QrBill\PaymentPart\Output\HtmlOutput\HtmlOutput($qrBill, 'en');
$output = new HtmlOutput($qrBill, 'en');

// 3. Optional, set layout options
$displayOptions = new DisplayOptions();
Expand Down
4 changes: 2 additions & 2 deletions example/TcPdfOutput/tcpdf-example.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php declare(strict_types=1);

use Sprain\SwissQrBill as QrBill;
use Sprain\SwissQrBill\PaymentPart\Output\DisplayOptions;
use Sprain\SwissQrBill\PaymentPart\Output\TcPdfOutput\TcPdfOutput;

require __DIR__ . '/../../vendor/autoload.php';

Expand All @@ -16,7 +16,7 @@
$tcPdf->AddPage();

// 3. Create a full payment part for TcPDF
$output = new QrBill\PaymentPart\Output\TcPdfOutput\TcPdfOutput($qrBill, 'en', $tcPdf);
$output = new TcPdfOutput($qrBill, 'en', $tcPdf);

// 4. Optional, set layout options
$displayOptions = new DisplayOptions();
Expand Down
19 changes: 6 additions & 13 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
return RectorConfig::configure()
->withPaths([
__DIR__ . '/example',
__DIR__ . '/src',
__DIR__ . '/tests',
]);

$rectorConfig->importNames(true);
$rectorConfig->importShortClasses(false)

$rectorConfig->sets([SetList::PHP_81]);

$rectorConfig->rule(ClassPropertyAssignToConstructorPromotionRector::class);
};
])->withImportNames(importShortClasses: false, removeUnusedImports: true)
->withPhpSets() //checks composer.json for supported php versions
//->withAttributesSets(all: true)
;
1 change: 0 additions & 1 deletion src/DataGroup/Element/Abstracts/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Sprain\SwissQrBill\DataGroup\Element\Abstracts;

use Sprain\SwissQrBill\String\StringAnalyzer;
use Sprain\SwissQrBill\String\StringModifier;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/DataGroup/Element/CombinedAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private function __construct(
$this->name = self::normalizeString($name);
$this->addressLine1 = self::normalizeString($addressLine1);
$this->addressLine2 = self::normalizeString($addressLine2);
$this->country = strtoupper(self::normalizeString($country));
$this->country = strtoupper((string) self::normalizeString($country));
}

public static function create(
Expand Down
4 changes: 2 additions & 2 deletions src/DataGroup/Element/PaymentReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public function getReference(): ?string
public function getFormattedReference(): ?string
{
return match ($this->type) {
self::TYPE_QR => trim(strrev(chunk_split(strrev($this->reference), 5, ' '))),
self::TYPE_SCOR => trim(chunk_split($this->reference, 4, ' ')),
self::TYPE_QR => trim(strrev(chunk_split(strrev((string) $this->reference), 5, ' '))),
self::TYPE_SCOR => trim(chunk_split((string) $this->reference, 4, ' ')),
default => null,
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/DataGroup/Element/StructuredAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private function __construct(
$this->buildingNumber = self::normalizeString($buildingNumber);
$this->postalCode = self::normalizeString($postalCode);
$this->city = self::normalizeString($city);
$this->country = strtoupper(self::normalizeString($country));
$this->country = strtoupper((string) self::normalizeString($country));
}

public static function createWithoutStreet(
Expand Down
6 changes: 3 additions & 3 deletions src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ final class TcPdfOutput extends AbstractOutput
public function __construct(
QrBill $qrBill,
string $language,
private TCPDF|Fpdi $tcPdf,
private float $offsetX = 0,
private float $offsetY = 0
private readonly TCPDF|Fpdi $tcPdf,
private readonly float $offsetX = 0,
private readonly float $offsetY = 0
) {
parent::__construct($qrBill, $language);
$this->setQrCodeImageFormat(QrCode::FILE_FORMAT_SVG);
Expand Down
2 changes: 1 addition & 1 deletion src/Reference/QrPaymentReferenceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function doGenerate(): string
$completeReferenceNumber = $this->getCustomerIdentificationNumber();

$strlen = $completeReferenceNumber ? strlen($completeReferenceNumber) : 0;
$completeReferenceNumber .= str_pad($this->getReferenceNumber(), 26 - $strlen, '0', STR_PAD_LEFT);
$completeReferenceNumber .= str_pad((string) $this->getReferenceNumber(), 26 - $strlen, '0', STR_PAD_LEFT);
$completeReferenceNumber .= $this->modulo10($completeReferenceNumber);

return $completeReferenceNumber;
Expand Down
1 change: 0 additions & 1 deletion tests/PaymentPart/Output/FpdfOutput/FpdfOutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Sprain\SwissQrBill\PaymentPart\Output\FpdfOutput\FpdfOutput;
use Sprain\SwissQrBill\PaymentPart\Output\FpdfOutput\UnsupportedEnvironmentException;
use Sprain\SwissQrBill\PaymentPart\Output\DisplayOptions;
use Sprain\SwissQrBill\PaymentPart\Output\VerticalSeparatorSymbolPosition;
use Sprain\SwissQrBill\QrBill;
use Sprain\SwissQrBill\QrCode\QrCode;
use Sprain\Tests\SwissQrBill\TestQrBillCreatorTrait;
Expand Down
1 change: 0 additions & 1 deletion tests/PaymentPart/Output/FpdfOutput/FpdiOutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Sprain\SwissQrBill\Exception\InvalidFpdfImageFormat;
use Sprain\SwissQrBill\PaymentPart\Output\FpdfOutput\FpdfOutput;
use Sprain\SwissQrBill\PaymentPart\Output\DisplayOptions;
use Sprain\SwissQrBill\PaymentPart\Output\VerticalSeparatorSymbolPosition;
use Sprain\SwissQrBill\QrBill;
use Sprain\SwissQrBill\QrCode\QrCode;
use Sprain\Tests\SwissQrBill\TestQrBillCreatorTrait;
Expand Down
1 change: 0 additions & 1 deletion tests/PaymentPart/Output/HtmlOutput/HtmlOutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use PHPUnit\Framework\TestCase;
use Sprain\SwissQrBill\PaymentPart\Output\HtmlOutput\HtmlOutput;
use Sprain\SwissQrBill\PaymentPart\Output\DisplayOptions;
use Sprain\SwissQrBill\PaymentPart\Output\VerticalSeparatorSymbolPosition;
use Sprain\SwissQrBill\QrBill;
use Sprain\SwissQrBill\QrCode\QrCode;
use Sprain\Tests\SwissQrBill\TestCompactSvgQrCodeTrait;
Expand Down
1 change: 0 additions & 1 deletion tests/PaymentPart/Output/TcPdfOutput/FpdiOutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use PHPUnit\Framework\TestCase;
use setasign\Fpdi\Tcpdf\Fpdi;
use Sprain\SwissQrBill\PaymentPart\Output\DisplayOptions;
use Sprain\SwissQrBill\PaymentPart\Output\VerticalSeparatorSymbolPosition;
use Sprain\SwissQrBill\PaymentPart\Output\TcPdfOutput\TcPdfOutput;
use Sprain\SwissQrBill\QrBill;
use Sprain\SwissQrBill\QrCode\QrCode;
Expand Down
1 change: 0 additions & 1 deletion tests/PaymentPart/Output/TcPdfOutput/TcPdfOutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PHPUnit\Framework\TestCase;
use Sprain\SwissQrBill\PaymentPart\Output\DisplayOptions;
use Sprain\SwissQrBill\PaymentPart\Output\VerticalSeparatorSymbolPosition;
use Sprain\SwissQrBill\PaymentPart\Output\TcPdfOutput\TcPdfOutput;
use Sprain\SwissQrBill\QrBill;
use Sprain\SwissQrBill\QrCode\QrCode;
Expand Down

0 comments on commit 5881f1c

Please sign in to comment.