Skip to content

Commit

Permalink
Merge pull request #231 from thePanz/updarte-phpstan-level-6
Browse files Browse the repository at this point in the history
Update to phpstan level 6
  • Loading branch information
sprain committed Oct 5, 2023
2 parents ca54b08 + 6802f05 commit 378ae01
Show file tree
Hide file tree
Showing 35 changed files with 139 additions and 74 deletions.
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"require": {
"php": "^8.0.0|^8.1.0|^8.2.0",
"ext-dom": "*",
"ext-bcmath": "*",
"symfony/validator": "^4.4|^5.0|^6.0",
"symfony/intl": "^4.4|^5.0|^6.0",
"kmukku/php-iso11649": "^1.5",
Expand Down Expand Up @@ -41,7 +42,11 @@
},
"autoload": {
"psr-4": {
"Sprain\\SwissQrBill\\": "src",
"Sprain\\SwissQrBill\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Sprain\\Tests\\SwissQrBill\\": "tests"
}
}
Expand Down
5 changes: 3 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/HtmlOutput/html-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
$examplePath = __DIR__ . '/html-example.htm';
file_put_contents($examplePath, $html);

print 'HTML example created here: ' . $examplePath;
print 'HTML example created here: ' . $examplePath;
2 changes: 1 addition & 1 deletion example/TcPdfOutput/tcpdf-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
$examplePath = __DIR__ . "/tcpdf_example.pdf";
$tcPdf->Output($examplePath, 'F');

print "PDF example created here : ".$examplePath;
print "PDF example created here : ".$examplePath;
23 changes: 14 additions & 9 deletions example/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
'Rue du Lac 1268',
'2501 Biel',
'CH'
));
)
);

$qrBill->setCreditorInformation(
QrBill\DataGroup\Element\CreditorInformation::create(
'CH4431999123000889012' // This is a special QR-IBAN. Classic IBANs will not be valid here.
));
)
);

// Add debtor information
// Who has to pay the invoice? This part is optional.
Expand All @@ -44,15 +46,17 @@
'9400',
'Rorschach',
'CH'
));
)
);

// Add payment amount information
// What amount is to be paid?
$qrBill->setPaymentAmountInformation(
QrBill\DataGroup\Element\PaymentAmountInformation::create(
'CHF',
2500.25
));
)
);

// Add payment reference
// This is what you will need to identify incoming payments.
Expand All @@ -65,7 +69,8 @@
QrBill\DataGroup\Element\PaymentReference::create(
QrBill\DataGroup\Element\PaymentReference::TYPE_QR,
$referenceNumber
));
)
);

// Optionally, add some human-readable information about what the bill is for.
$qrBill->setAdditionalInformation(
Expand All @@ -79,10 +84,10 @@
$qrBill->getQrCode()->writeFile(__DIR__ . '/qr.png');
$qrBill->getQrCode()->writeFile(__DIR__ . '/qr.svg');
} catch (Exception $e) {
foreach($qrBill->getViolations() as $violation) {
print $violation->getMessage()."\n";
}
exit;
foreach ($qrBill->getViolations() as $violation) {
print $violation->getMessage()."\n";
}
exit;
}

// Next: Output full payment parts, depending on the format you want to use:
Expand Down
22 changes: 13 additions & 9 deletions example/example_minimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,30 @@
'Rue du Lac 1268',
'2501 Biel',
'CH'
));
)
);

$qrBill->setCreditorInformation(
QrBill\DataGroup\Element\CreditorInformation::create(
'CH9300762011623852957' // This is a classic iban. QR-IBANs will not be valid in this minmal setup.
));
)
);

// Add payment amount information
// The currency must be defined.
$qrBill->setPaymentAmountInformation(
QrBill\DataGroup\Element\PaymentAmountInformation::create(
'CHF'
));
)
);

// Add payment reference
// Explicitly define that no reference number will be used by setting TYPE_NON.
$qrBill->setPaymentReference(
QrBill\DataGroup\Element\PaymentReference::create(
QrBill\DataGroup\Element\PaymentReference::TYPE_NON
));
)
);

// Time to output something!
//
Expand All @@ -48,14 +52,14 @@
$qrBill->getQrCode()->writeFile(__DIR__ . '/qr.png');
$qrBill->getQrCode()->writeFile(__DIR__ . '/qr.svg');
} catch (Exception $e) {
foreach($qrBill->getViolations() as $violation) {
print $violation->getMessage()."\n";
}
exit;
foreach ($qrBill->getViolations() as $violation) {
print $violation->getMessage()."\n";
}
exit;
}

// Next: Output full payment parts, depending on the format you want to use:
//
// - FpdfOutput/fpdf-example.php
// - HtmlOutput/html-example.php
// - TcPdfOutput/tcpdf-example.php
// - TcPdfOutput/tcpdf-example.php
25 changes: 15 additions & 10 deletions example/example_scor.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
'Rue du Lac 1268',
'2501 Biel',
'CH'
));
)
);

$qrBill->setCreditorInformation(
QrBill\DataGroup\Element\CreditorInformation::create(
'CH9300762011623852957' // With SCOR, this is a classic iban. QR-IBANs will not be valid here.
));
)
);

// Add debtor information
// Who has to pay the invoice? This part is optional.
Expand All @@ -37,23 +39,26 @@
'9400',
'Rorschach',
'CH'
));
)
);

// Add payment amount information
// What amount is to be paid?
$qrBill->setPaymentAmountInformation(
QrBill\DataGroup\Element\PaymentAmountInformation::create(
'CHF',
2500.25
));
)
);

// Add payment reference
// This is what you will need to identify incoming payments.
$qrBill->setPaymentReference(
QrBill\DataGroup\Element\PaymentReference::create(
QrBill\DataGroup\Element\PaymentReference::TYPE_SCOR,
QrBill\Reference\RfCreditorReferenceGenerator::generate('I20200631')
));
)
);

// Optionally, add some human-readable information about what the bill is for.
$qrBill->setAdditionalInformation(
Expand All @@ -69,14 +74,14 @@
$qrBill->getQrCode()->writeFile(__DIR__ . '/qr.png');
$qrBill->getQrCode()->writeFile(__DIR__ . '/qr.svg');
} catch (Exception $e) {
foreach($qrBill->getViolations() as $violation) {
print $violation->getMessage()."\n";
}
exit;
foreach ($qrBill->getViolations() as $violation) {
print $violation->getMessage()."\n";
}
exit;
}

// Next: Output full payment parts, depending on the format you want to use:
//
// - FpdfOutput/fpdf-example.php
// - HtmlOutput/html-example.php
// - TcPdfOutput/tcpdf-example.php
// - TcPdfOutput/tcpdf-example.php
14 changes: 9 additions & 5 deletions example/example_zero_amount.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@
'Rue du Lac 1268',
'2501 Biel',
'CH'
));
)
);

$qrBill->setCreditorInformation(
QrBill\DataGroup\Element\CreditorInformation::create(
'CH4431999123000889012' // This is a special QR-IBAN. Classic IBANs will not be valid here.
));
)
);

// Add payment amount information of 0.00
$qrBill->setPaymentAmountInformation(
QrBill\DataGroup\Element\PaymentAmountInformation::create(
'CHF',
0.00
));
)
);

// Add payment reference
$referenceNumber = QrBill\Reference\QrPaymentReferenceGenerator::generate(
Expand All @@ -45,7 +48,8 @@
QrBill\DataGroup\Element\PaymentReference::create(
QrBill\DataGroup\Element\PaymentReference::TYPE_QR,
$referenceNumber
));
)
);

// Add do-not-use-for-payment information
$qrBill->setAdditionalInformation(
Expand All @@ -59,7 +63,7 @@
$qrBill->getQrCode()->writeFile(__DIR__ . '/qr.png');
$qrBill->getQrCode()->writeFile(__DIR__ . '/qr.svg');
} catch (Exception $e) {
foreach($qrBill->getViolations() as $violation) {
foreach ($qrBill->getViolations() as $violation) {
print $violation->getMessage()."\n";
}
exit;
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 5
level: 6
paths:
- src/
ignoreErrors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class ValidCreditorInformationPaymentReferenceCombinationValidator extends
PaymentReference::TYPE_NON => false,
];

public function validate($qrBill, Constraint $constraint): void
public function validate(mixed $qrBill, Constraint $constraint): void
{
if (!$constraint instanceof ValidCreditorInformationPaymentReferenceCombination) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\ValidCreditorInformationPaymentReferenceCombination');
Expand Down
2 changes: 1 addition & 1 deletion src/Constraint/ValidCreditorReferenceValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
final class ValidCreditorReferenceValidator extends ConstraintValidator
{
public function validate($value, Constraint $constraint): void
public function validate(mixed $value, Constraint $constraint): void
{
if (!$constraint instanceof ValidCreditorReference) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\ValidCreditorReference');
Expand Down
8 changes: 5 additions & 3 deletions src/DataGroup/Element/Abstracts/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ protected static function normalizeString(?string $string): ?string

$string = trim($string);
$string = StringModifier::replaceLineBreaksAndTabsWithSpaces($string);
$string = StringModifier::replaceMultipleSpacesWithOne($string);

return $string;
return StringModifier::replaceMultipleSpacesWithOne($string);
}

/**
* @param string[] $lines
* @return string[]
*/
protected static function clearMultilines(array $lines): array
{
$noOfLongLines = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/DataGroup/QrCodeableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
*/
interface QrCodeableInterface
{
/**
* @return list<string|int|null>
*/
public function getQrCodeData(): array;
}
Loading

0 comments on commit 378ae01

Please sign in to comment.