diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9313b1e..b1ad4972 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: - php: ['8.0', '8.1', '8.2', '8.3'] + php: ['8.1', '8.2', '8.3', '8.4'] stability: ['prefer-lowest', 'prefer-stable'] name: PHP Tests ${{ matrix.php }} - ${{ matrix.stability }} @@ -58,7 +58,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.2' + php-version: '8.3' extensions: dom, curl, libxml, mbstring, zip, bcmath, gd tools: composer coverage: none diff --git a/README.md b/README.md index 8f22ddf9..410e39ed 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,15 @@ The beauty of open source software lies in the fact that everybody can benefit f In addition, a minor version will always be published if any visible change in the output of the qr code or the payment part takes place, even if it could be considered to be just a bugfix. +### PHP version support + +This library supports a PHP version as long as it accounts for at least approximately 10% [of current installations](https://packagist.org/packages/sprain/swiss-qr-bill/php-stats). + +### Depdendency support + +Older versions of dependencies are supported as long as they do not hinder further development or account for at least +approximately 10% of current installations of the corresponding dependency. + ## Support the project * Do you like this project? [Consider a Github sponsorship.](https://github.com/sponsors/sprain) diff --git a/composer.json b/composer.json index b71cd239..dce48b25 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "library", "license": "MIT", "require": { - "php": "~8.0.0|~8.1.0|~8.2.0|~8.3.0", + "php": "~8.1.0|~8.2.0|~8.3.0|~8.4.0", "ext-dom": "*", "ext-bcmath": "*", "symfony/validator": "^4.4|^5.0|^6.0|^7.0", @@ -24,7 +24,8 @@ "phpstan/phpstan": "^1.11-dev", "setasign/fpdi": "^2.3.5", "setasign/fpdf": "^1.8.2", - "tecnickcom/tcpdf": "^6.3.2" + "tecnickcom/tcpdf": "^6.3.2", + "rector/rector": "^1.2" }, "scripts": { "cs:fix": "vendor/bin/php-cs-fixer fix --verbose", diff --git a/example/FpdfOutput/fpdf-example.php b/example/FpdfOutput/fpdf-example.php index ebc3cb9a..f12447c2 100644 --- a/example/FpdfOutput/fpdf-example.php +++ b/example/FpdfOutput/fpdf-example.php @@ -1,5 +1,6 @@ getQrCode()->writeFile(__DIR__ . '/qr.png'); $qrBill->getQrCode()->writeFile(__DIR__ . '/qr.svg'); -} catch (Exception $e) { +} catch (Exception) { foreach ($qrBill->getViolations() as $violation) { print $violation->getMessage()."\n"; } diff --git a/example/example_minimal.php b/example/example_minimal.php index c65bea49..26adea26 100644 --- a/example/example_minimal.php +++ b/example/example_minimal.php @@ -51,7 +51,7 @@ try { $qrBill->getQrCode()->writeFile(__DIR__ . '/qr.png'); $qrBill->getQrCode()->writeFile(__DIR__ . '/qr.svg'); -} catch (Exception $e) { +} catch (Exception) { foreach ($qrBill->getViolations() as $violation) { print $violation->getMessage()."\n"; } diff --git a/example/example_scor.php b/example/example_scor.php index 72a7f547..36ea4129 100644 --- a/example/example_scor.php +++ b/example/example_scor.php @@ -73,7 +73,7 @@ try { $qrBill->getQrCode()->writeFile(__DIR__ . '/qr.png'); $qrBill->getQrCode()->writeFile(__DIR__ . '/qr.svg'); -} catch (Exception $e) { +} catch (Exception) { foreach ($qrBill->getViolations() as $violation) { print $violation->getMessage()."\n"; } diff --git a/example/example_zero_amount.php b/example/example_zero_amount.php index c8a9f670..3a560dce 100644 --- a/example/example_zero_amount.php +++ b/example/example_zero_amount.php @@ -62,7 +62,7 @@ try { $qrBill->getQrCode()->writeFile(__DIR__ . '/qr.png'); $qrBill->getQrCode()->writeFile(__DIR__ . '/qr.svg'); -} catch (Exception $e) { +} catch (Exception) { foreach ($qrBill->getViolations() as $violation) { print $violation->getMessage()."\n"; } diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..e23eb96f --- /dev/null +++ b/rector.php @@ -0,0 +1,22 @@ +paths([ + __DIR__ . '/example', + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + $rectorConfig->importNames(true); + $rectorConfig->importShortClasses(false) + + $rectorConfig->sets([SetList::PHP_81]); + + $rectorConfig->rule(ClassPropertyAssignToConstructorPromotionRector::class); +}; diff --git a/src/DataGroup/Element/AdditionalInformation.php b/src/DataGroup/Element/AdditionalInformation.php index ae95588c..ecf74a43 100644 --- a/src/DataGroup/Element/AdditionalInformation.php +++ b/src/DataGroup/Element/AdditionalInformation.php @@ -14,24 +14,18 @@ final class AdditionalInformation implements QrCodeableInterface, SelfValidatabl public const TRAILER_EPD = 'EPD'; - /** - * Unstructured information can be used to indicate the payment purpose - * or for additional textual information about payments with a structured reference. - */ - private ?string $message; - - /** - * Bill information contains coded information for automated booking of the payment. - * The data is not forwarded with the payment. - */ - private ?string $billInformation; - private function __construct( - ?string $message, - ?string $billInformation + /** + * Unstructured information can be used to indicate the payment purpose + * or for additional textual information about payments with a structured reference. + */ + private ?string $message, + /** + * Bill information contains coded information for automated booking of the payment. + * The data is not forwarded with the payment. + */ + private ?string $billInformation ) { - $this->message = $message; - $this->billInformation = $billInformation; } public static function create( diff --git a/src/DataGroup/Element/AlternativeScheme.php b/src/DataGroup/Element/AlternativeScheme.php index fd44435c..18791402 100644 --- a/src/DataGroup/Element/AlternativeScheme.php +++ b/src/DataGroup/Element/AlternativeScheme.php @@ -16,14 +16,12 @@ final class AlternativeScheme implements QrCodeableInterface, SelfValidatableInt { use SelfValidatableTrait; - /** - * Parameter character chain of the alternative scheme - */ - private string $parameter; - - private function __construct(string $parameter) - { - $this->parameter = $parameter; + private function __construct( + /** + * Parameter character chain of the alternative scheme + */ + private string $parameter + ) { } public static function create(string $parameter): self diff --git a/src/DataGroup/Element/CombinedAddress.php b/src/DataGroup/Element/CombinedAddress.php index e66d4970..dc4c7ba8 100644 --- a/src/DataGroup/Element/CombinedAddress.php +++ b/src/DataGroup/Element/CombinedAddress.php @@ -5,8 +5,6 @@ use Sprain\SwissQrBill\DataGroup\AddressInterface; use Sprain\SwissQrBill\DataGroup\Element\Abstracts\Address; use Sprain\SwissQrBill\DataGroup\QrCodeableInterface; -use Sprain\SwissQrBill\String\StringAnalyzer; -use Sprain\SwissQrBill\String\StringModifier; use Sprain\SwissQrBill\Validator\SelfValidatableInterface; use Sprain\SwissQrBill\Validator\SelfValidatableTrait; use Symfony\Component\Validator\Constraints as Assert; @@ -18,35 +16,30 @@ class CombinedAddress extends Address implements AddressInterface, SelfValidatab public const ADDRESS_TYPE = 'K'; - /** - * Name or company - */ - private string $name; - - /** - * Address line 1 - * - * Street and building number or P.O. Box - */ - private ?string $addressLine1; - - /** - * Address line 2 - * - * Postal code and town - */ - private string $addressLine2; - - /** - * Country (ISO 3166-1 alpha-2) - */ - private string $country; - private function __construct( - string $name, - ?string $addressLine1, - string $addressLine2, - string $country + /** + * Name or company + */ + private string $name, + + /** + * Address line 1 + * + * Street and building number or P.O. Box + */ + private ?string $addressLine1, + + /** + * Address line 2 + * + * Postal code and town + */ + private string $addressLine2, + + /** + * Country (ISO 3166-1 alpha-2) + */ + private string $country ) { $this->name = self::normalizeString($name); $this->addressLine1 = self::normalizeString($addressLine1); diff --git a/src/DataGroup/Element/CreditorInformation.php b/src/DataGroup/Element/CreditorInformation.php index b7b5d563..2ef5d35d 100644 --- a/src/DataGroup/Element/CreditorInformation.php +++ b/src/DataGroup/Element/CreditorInformation.php @@ -13,13 +13,12 @@ final class CreditorInformation implements QrCodeableInterface, SelfValidatableI { use SelfValidatableTrait; - /** - * IBAN or QR-IBAN of the creditor - */ - private string $iban; - - private function __construct(string $iban) - { + private function __construct( + /** + * IBAN or QR-IBAN of the creditor + */ + private string $iban + ) { $this->iban = StringModifier::stripWhitespace($iban); } diff --git a/src/DataGroup/Element/Header.php b/src/DataGroup/Element/Header.php index fb1b78f7..2c8ba22d 100644 --- a/src/DataGroup/Element/Header.php +++ b/src/DataGroup/Element/Header.php @@ -16,29 +16,25 @@ final class Header implements QrCodeableInterface, SelfValidatableInterface public const VERSION_0200 = '0200'; public const CODING_LATIN = 1; - /** - * Unambiguous indicator for the Swiss QR code. - */ - private string $qrType; - - /** - * Version of the specifications (Implementation Guidelines) in use on - * the date on which the Swiss QR code was created. - * The first two positions indicate the main version, the following the - * two positions the sub-version ("0200" for version 2.0). - */ - private string $version; - - /** - * Character set code - */ - private int $coding; - - private function __construct(string $qrType, string $version, int $coding) - { - $this->qrType = $qrType; - $this->version = $version; - $this->coding = $coding; + private function __construct( + /** + * Unambiguous indicator for the Swiss QR code. + */ + private readonly string $qrType, + + /** + * Version of the specifications (Implementation Guidelines) in use on + * the date on which the Swiss QR code was created. + * The first two positions indicate the main version, the following the + * two positions the sub-version ("0200" for version 2.0). + */ + private readonly string $version, + + /** + * Character set code + */ + private readonly int $coding + ) { } public static function create(string $qrType, string $version, int $coding): self diff --git a/src/DataGroup/Element/PaymentAmountInformation.php b/src/DataGroup/Element/PaymentAmountInformation.php index 2e98a883..91fea728 100644 --- a/src/DataGroup/Element/PaymentAmountInformation.php +++ b/src/DataGroup/Element/PaymentAmountInformation.php @@ -15,20 +15,18 @@ final class PaymentAmountInformation implements QrCodeableInterface, SelfValidat public const CURRENCY_CHF = 'CHF'; public const CURRENCY_EUR = 'EUR'; - /** - * The payment amount due - */ - private ?float $amount; - - /** - * Payment currency code (ISO 4217) - */ - private string $currency; - - private function __construct(string $currency, ?float $amount) - { + private function __construct( + /** + * Payment currency code (ISO 4217) + */ + private string $currency, + + /** + * The payment amount due + */ + private readonly ?float $amount + ) { $this->currency = strtoupper($currency); - $this->amount = $amount; } public static function create(string $currency, ?float $amount = null): self diff --git a/src/DataGroup/Element/PaymentReference.php b/src/DataGroup/Element/PaymentReference.php index 8cf287f1..25967be9 100644 --- a/src/DataGroup/Element/PaymentReference.php +++ b/src/DataGroup/Element/PaymentReference.php @@ -20,22 +20,18 @@ final class PaymentReference implements GroupSequenceProviderInterface, QrCodeab public const TYPE_SCOR = 'SCOR'; public const TYPE_NON = 'NON'; - /** - * Reference type - */ - private string $type; - - /** - * Structured reference number - * Either a QR reference or a Creditor Reference (ISO 11649) - */ - private ?string $reference; - - private function __construct(string $type, ?string $reference) - { - $this->type = $type; - $this->reference = $reference; - + private function __construct( + /** + * Reference type + */ + private readonly string $type, + + /** + * Structured reference number + * Either a QR reference or a Creditor Reference (ISO 11649) + */ + private ?string $reference + ) { $this->handleWhiteSpaceInReference(); } @@ -56,14 +52,11 @@ public function getReference(): ?string public function getFormattedReference(): ?string { - switch ($this->type) { - case self::TYPE_QR: - return trim(strrev(chunk_split(strrev($this->reference), 5, ' '))); - case self::TYPE_SCOR: - return trim(chunk_split($this->reference, 4, ' ')); - default: - return null; - } + return match ($this->type) { + self::TYPE_QR => trim(strrev(chunk_split(strrev($this->reference), 5, ' '))), + self::TYPE_SCOR => trim(chunk_split($this->reference, 4, ' ')), + default => null, + }; } public function getQrCodeData(): array diff --git a/src/DataGroup/Element/StructuredAddress.php b/src/DataGroup/Element/StructuredAddress.php index f329e195..fff6e3c1 100644 --- a/src/DataGroup/Element/StructuredAddress.php +++ b/src/DataGroup/Element/StructuredAddress.php @@ -5,7 +5,6 @@ use Sprain\SwissQrBill\DataGroup\AddressInterface; use Sprain\SwissQrBill\DataGroup\Element\Abstracts\Address; use Sprain\SwissQrBill\DataGroup\QrCodeableInterface; -use Sprain\SwissQrBill\String\StringModifier; use Sprain\SwissQrBill\Validator\SelfValidatableInterface; use Sprain\SwissQrBill\Validator\SelfValidatableTrait; use Symfony\Component\Validator\Constraints as Assert; @@ -17,45 +16,38 @@ final class StructuredAddress extends Address implements AddressInterface, SelfV public const ADDRESS_TYPE = 'S'; - /** - * Name or company - */ - private string $name; - - /** - * Street / P.O. box - * - * May not include building or house number. - */ - private ?string $street; - - /** - * Building number - */ - private ?string $buildingNumber; - - /** - * Postal code without country code - */ - private string $postalCode; - - /** - * City - */ - private string $city; - - /** - * Country (ISO 3166-1 alpha-2) - */ - private string $country; - private function __construct( - string $name, - ?string $street, - ?string $buildingNumber, - string $postalCode, - string $city, - string $country + /** + * Name or company + */ + private string $name, + + /** + * Street / P.O. box + * + * May not include building or house number. + */ + private ?string $street, + + /** + * Building number + */ + private ?string $buildingNumber, + + /** + * Postal code without country code + */ + private string $postalCode, + + /** + * City + */ + private string $city, + + /** + * Country (ISO 3166-1 alpha-2) + */ + private string $country ) { $this->name = self::normalizeString($name); $this->street = self::normalizeString($street); diff --git a/src/PaymentPart/Output/AbstractOutput.php b/src/PaymentPart/Output/AbstractOutput.php index 4a572866..321f0edb 100644 --- a/src/PaymentPart/Output/AbstractOutput.php +++ b/src/PaymentPart/Output/AbstractOutput.php @@ -12,15 +12,11 @@ abstract class AbstractOutput implements OutputInterface { - protected QrBill $qrBill; - protected string $language; protected string $qrCodeImageFormat; private DisplayOptions $displayOptions; - public function __construct(QrBill $qrBill, string $language) + public function __construct(protected QrBill $qrBill, protected string $language) { - $this->qrBill = $qrBill; - $this->language = $language; $this->displayOptions = new DisplayOptions(); $this->qrCodeImageFormat = QrCode::FILE_FORMAT_SVG; } diff --git a/src/PaymentPart/Output/DisplayOptions.php b/src/PaymentPart/Output/DisplayOptions.php index 7da043d2..39098044 100644 --- a/src/PaymentPart/Output/DisplayOptions.php +++ b/src/PaymentPart/Output/DisplayOptions.php @@ -9,7 +9,7 @@ final class DisplayOptions private bool $positionScissorsAtBottom = false; private bool $displayTextDownArrows = false; private bool $displayText = true; - private string $lineStyle = LineStyle::SOLID; + private LineStyle $lineStyle = LineStyle::SOLID; public function isPrintable(): bool { @@ -64,7 +64,7 @@ public function isDisplayText(): bool return $this->displayText; } - public function getLineStyle(): string + public function getLineStyle(): LineStyle { return $this->lineStyle; } @@ -90,9 +90,9 @@ public function consolidate(): void /** * @internal */ -final class LineStyle +enum LineStyle { - public const SOLID = 'SOLID'; - public const DASHED = 'DASHED'; - public const NONE = 'NONE'; + case SOLID; + case DASHED; + case NONE; } diff --git a/src/PaymentPart/Output/FpdfOutput/FpdfOutput.php b/src/PaymentPart/Output/FpdfOutput/FpdfOutput.php index 3d2379d8..356b16d4 100644 --- a/src/PaymentPart/Output/FpdfOutput/FpdfOutput.php +++ b/src/PaymentPart/Output/FpdfOutput/FpdfOutput.php @@ -53,21 +53,14 @@ final class FpdfOutput extends AbstractOutput private const LINE_SPACING_PAYMENT_PART = 4.8; private float $amountLS = 0; - private Fpdf|Fpdi $fpdf; - private float $offsetX; - private float $offsetY; - public function __construct( QrBill $qrBill, string $language, - Fpdf|Fpdi $fpdf, - float $offsetX = 0, - float $offsetY = 0 + private readonly Fpdf|Fpdi $fpdf, + private readonly float $offsetX = 0, + private readonly float $offsetY = 0 ) { parent::__construct($qrBill, $language); - $this->fpdf = $fpdf; - $this->offsetX = $offsetX; - $this->offsetY = $offsetY; $this->setQrCodeImageFormat(QrCode::FILE_FORMAT_PNG); } diff --git a/src/PaymentPart/Output/FpdfOutput/FpdfTrait.php b/src/PaymentPart/Output/FpdfOutput/FpdfTrait.php index a152f37b..2630c99a 100644 --- a/src/PaymentPart/Output/FpdfOutput/FpdfTrait.php +++ b/src/PaymentPart/Output/FpdfOutput/FpdfTrait.php @@ -14,7 +14,7 @@ trait FpdfTrait */ public function swissQrBillSetDash(float $black = 0, ?float $white = null): void { - $white = $white === null ? $black : $white; + $white ??= $black; $s = $black > 0 ? sprintf('[%.3F %.3F] 0 d', $black * $this->k, $white * $this->k) diff --git a/src/PaymentPart/Output/HtmlOutput/HtmlOutput.php b/src/PaymentPart/Output/HtmlOutput/HtmlOutput.php index 56c90f58..04a99096 100644 --- a/src/PaymentPart/Output/HtmlOutput/HtmlOutput.php +++ b/src/PaymentPart/Output/HtmlOutput/HtmlOutput.php @@ -155,7 +155,7 @@ private function hideSeparatorContentIfPrintable(string $paymentPart): string private function getContentElement(FurtherInformation|Title|Text|Placeholder $element): string { - return match (get_class($element)) { + return match ($element::class) { FurtherInformation::class => $this->getFurtherInformationElement($element), Title::class => $this->getTitleElement($element), Text::class => $this->getTextElement($element), diff --git a/src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php b/src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php index ea566142..cab17278 100644 --- a/src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php +++ b/src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php @@ -56,21 +56,14 @@ final class TcPdfOutput extends AbstractOutput private const LINE_SPACING_RECEIPT = 3.5; private const LINE_SPACING_PAYMENT_PART = 4.8; - private TCPDF|Fpdi $tcPdf; - private float $offsetX; - private float $offsetY; - public function __construct( QrBill $qrBill, string $language, - TCPDF|Fpdi $tcPdf, - float $offsetX = 0, - float $offsetY = 0 + private TCPDF|Fpdi $tcPdf, + private float $offsetX = 0, + private float $offsetY = 0 ) { parent::__construct($qrBill, $language); - $this->tcPdf = $tcPdf; - $this->offsetX = $offsetX; - $this->offsetY = $offsetY; $this->setQrCodeImageFormat(QrCode::FILE_FORMAT_SVG); } @@ -254,16 +247,14 @@ private function addSeparatorContentIfNotPrintable(): void $this->setX($xmiddle); $this->tcPdf->StartTransform(); $this->tcPdf->Rotate(90); - $this->tcPdf->Cell(0, 10, self::FONT_UNICODE_CHAR_SCISSORS, 0, 0, 'L', false, '', 0, false, 'C'); - $this->tcPdf->StopTransform(); } else { $this->setY($y + 3); $this->setX($xmiddle); $this->tcPdf->StartTransform(); $this->tcPdf->Rotate(-90); - $this->tcPdf->Cell(0, 10, self::FONT_UNICODE_CHAR_SCISSORS, 0, 0, 'L', false, '', 0, false, 'C'); - $this->tcPdf->StopTransform(); } + $this->tcPdf->Cell(0, 10, self::FONT_UNICODE_CHAR_SCISSORS, 0, 0, 'L', false, '', 0, false, 'C'); + $this->tcPdf->StopTransform(); } if ($layout->isDisplayText()) { @@ -336,7 +327,6 @@ private function setTextElement(Text $element, bool $isReceiptPart): void $this->printMultiCell( str_replace('text.', '', $element->getText()), $isReceiptPart ? 54 : 0, - 0, self::ALIGN_BELOW ); @@ -349,7 +339,6 @@ private function setFurtherInformationElement(FurtherInformation $element): void $this->printMultiCell( $element->getText(), 0, - 0, self::BORDER ); } @@ -406,10 +395,9 @@ private function printCell( private function printMultiCell( string $text, int $w = 0, - int $h = 0, int $nextLineAlign = 0 ): void { - $this->tcPdf->MultiCell($w, $h, $text, self::BORDER, self::ALIGN_LEFT, false, $nextLineAlign); + $this->tcPdf->MultiCell($w, 0, $text, self::BORDER, self::ALIGN_LEFT, false, $nextLineAlign); } private function printLine(int $x1, int $y1, int $x2, int $y2): void diff --git a/src/QrBill.php b/src/QrBill.php index 5e23b3e9..c5608e29 100644 --- a/src/QrBill.php +++ b/src/QrBill.php @@ -25,8 +25,6 @@ final class QrBill implements SelfValidatableInterface { use SelfValidatableTrait; - - private Header $header; private ?CreditorInformation $creditorInformation = null; private ?AddressInterface $creditor = null; private ?PaymentAmountInformation $paymentAmountInformation = null; @@ -40,9 +38,8 @@ final class QrBill implements SelfValidatableInterface /** @var AlternativeScheme[] */ private array $alternativeSchemes = []; - private function __construct(Header $header) + private function __construct(private Header $header) { - $this->header = $header; } public static function create(): self diff --git a/src/QrCode/QrCode.php b/src/QrCode/QrCode.php index 2c4907f9..765b8c5c 100644 --- a/src/QrCode/QrCode.php +++ b/src/QrCode/QrCode.php @@ -2,6 +2,8 @@ namespace Sprain\SwissQrBill\QrCode; +use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelMedium; +use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeEnlarge; use Endroid\QrCode\Encoding\Encoding; use Endroid\QrCode\ErrorCorrectionLevel; use Endroid\QrCode\Logo\Logo; @@ -63,14 +65,14 @@ private function __construct(string $data, string $fileFormat, array $unsupporte $data = $this->replaceUnsupportedCharacters($data, $unsupportedCharacterReplacements); $data = $this->cleanUnsupportedCharacters($data); - if (class_exists(ErrorCorrectionLevel\ErrorCorrectionLevelMedium::class)) { + if (class_exists(ErrorCorrectionLevelMedium::class)) { // Endroid 4.x $this->qrCode = BaseQrCode::create($data) ->setEncoding(new Encoding('UTF-8')) - ->setErrorCorrectionLevel(new ErrorCorrectionLevel\ErrorCorrectionLevelMedium()) + ->setErrorCorrectionLevel(new ErrorCorrectionLevelMedium()) ->setSize(self::PX_QR_CODE) ->setMargin(0) - ->setRoundBlockSizeMode(new RoundBlockSizeMode\RoundBlockSizeModeEnlarge()); + ->setRoundBlockSizeMode(new RoundBlockSizeModeEnlarge()); } elseif (method_exists(BaseQrCode::class, 'create')) { // Endroid 5.x $this->qrCode = BaseQrCode::create($data) diff --git a/tests/PaymentPart/Output/FpdfOutput/FpdfOutputTest.php b/tests/PaymentPart/Output/FpdfOutput/FpdfOutputTest.php index b08235a5..b0c332a8 100644 --- a/tests/PaymentPart/Output/FpdfOutput/FpdfOutputTest.php +++ b/tests/PaymentPart/Output/FpdfOutput/FpdfOutputTest.php @@ -29,17 +29,17 @@ public function testValidQrBills(string $name, QrBill $qrBill): void [ 'layout' => (new DisplayOptions())->setPrintable(false), 'format' => QrCode::FILE_FORMAT_PNG, - 'file' => dirname(dirname(dirname(__DIR__))) . '/TestData/FpdfOutput/' . $name . '.pdf' + 'file' => dirname(__DIR__, 3) . '/TestData/FpdfOutput/' . $name . '.pdf' ], [ 'layout' => (new DisplayOptions())->setPrintable(true), 'format' => QrCode::FILE_FORMAT_PNG, - 'file' => dirname(dirname(dirname(__DIR__))) . '/TestData/FpdfOutput/' . $name . '.print.pdf' + 'file' => dirname(__DIR__, 3) . '/TestData/FpdfOutput/' . $name . '.print.pdf' ], [ 'layout' => (new DisplayOptions())->setPrintable(false)->setDisplayScissors(true), 'format' => QrCode::FILE_FORMAT_PNG, - 'file' => dirname(dirname(dirname(__DIR__))) . '/TestData/FpdfOutput/' . $name . '.scissors.pdf' + 'file' => dirname(__DIR__, 3) . '/TestData/FpdfOutput/' . $name . '.scissors.pdf' ], [ 'layout' => (new DisplayOptions())->setPrintable(false)->setDisplayScissors(true)->setPositionScissorsAtBottom(true), @@ -181,11 +181,7 @@ private function getActualPdfContents(string $fileContents): ?string // Extract actual pdf content and ignore all meta data which may differ in different versions of Fpdf $pattern = '/stream(.*?)endstream/s'; preg_match($pattern, $fileContents, $matches); - - if (isset($matches[1])) { - return $matches[1]; - } - return null; + return $matches[1] ?? null; } private function instantiateFpdf($withMemImageSupport = null, $withBundledTrait = null): Fpdf diff --git a/tests/PaymentPart/Output/FpdfOutput/FpdiOutputTest.php b/tests/PaymentPart/Output/FpdfOutput/FpdiOutputTest.php index 2ef123e1..d153a5aa 100644 --- a/tests/PaymentPart/Output/FpdfOutput/FpdiOutputTest.php +++ b/tests/PaymentPart/Output/FpdfOutput/FpdiOutputTest.php @@ -28,17 +28,17 @@ public function testValidQrBills(string $name, QrBill $qrBill): void [ 'layout' => (new DisplayOptions())->setPrintable(false), 'format' => QrCode::FILE_FORMAT_PNG, - 'file' => dirname(dirname(dirname(__DIR__))) . '/TestData/FpdfOutput/' . $name . '.pdf' + 'file' => dirname(__DIR__, 3) . '/TestData/FpdfOutput/' . $name . '.pdf' ], [ 'layout' => (new DisplayOptions())->setPrintable(true), 'format' => QrCode::FILE_FORMAT_PNG, - 'file' => dirname(dirname(dirname(__DIR__))) . '/TestData/FpdfOutput/' . $name . '.print.pdf' + 'file' => dirname(__DIR__, 3) . '/TestData/FpdfOutput/' . $name . '.print.pdf' ], [ 'layout' => (new DisplayOptions())->setPrintable(false)->setDisplayScissors(true), 'format' => QrCode::FILE_FORMAT_PNG, - 'file' => dirname(dirname(dirname(__DIR__))) . '/TestData/FpdfOutput/' . $name . '.scissors.pdf' + 'file' => dirname(__DIR__, 3) . '/TestData/FpdfOutput/' . $name . '.scissors.pdf' ], [ 'layout' => (new DisplayOptions())->setPrintable(false)->setDisplayScissors(true)->setPositionScissorsAtBottom(true), @@ -123,11 +123,7 @@ private function getActualPdfContents(string $fileContents): ?string // Extract actual pdf content and ignore all meta data which may differ in different versions of Fpdf $pattern = '/stream(.*?)endstream/s'; preg_match($pattern, $fileContents, $matches); - - if (isset($matches[1])) { - return $matches[1]; - } - return null; + return $matches[1] ?? null; } private function instantiateFpdi($withMemImageSupport = null, $withBundledTrait = null): Fpdi diff --git a/tests/PaymentPart/Output/TcPdfOutput/FpdiOutputTest.php b/tests/PaymentPart/Output/TcPdfOutput/FpdiOutputTest.php index a15aec67..d433d38e 100644 --- a/tests/PaymentPart/Output/TcPdfOutput/FpdiOutputTest.php +++ b/tests/PaymentPart/Output/TcPdfOutput/FpdiOutputTest.php @@ -91,10 +91,6 @@ private function getActualPdfContents(string $fileContents): ?string $pattern = '/stream(.*?)endstream/s'; preg_match($pattern, $fileContents, $matches); - if (isset($matches[1])) { - return $matches[1]; - } - - return null; + return $matches[1] ?? null; } } diff --git a/tests/PaymentPart/Output/TcPdfOutput/TcPdfOutputTest.php b/tests/PaymentPart/Output/TcPdfOutput/TcPdfOutputTest.php index 34079bd5..6f87caa1 100644 --- a/tests/PaymentPart/Output/TcPdfOutput/TcPdfOutputTest.php +++ b/tests/PaymentPart/Output/TcPdfOutput/TcPdfOutputTest.php @@ -124,10 +124,6 @@ private function getActualPdfContents(string $fileContents): ?string $pattern = '/stream(.*?)endstream/s'; preg_match($pattern, $fileContents, $matches); - if (isset($matches[1])) { - return $matches[1]; - } - - return null; + return $matches[1] ?? null; } }