Skip to content
Merged
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

strategy:
matrix:
php: ['8.1', '8.2', '8.3', '8.4']
php: ['8.1', '8.2', '8.3', '8.4', '8.5']
stability: ['prefer-lowest', 'prefer-stable']

name: PHP Tests ${{ matrix.php }} - ${{ matrix.stability }}
Expand Down
9 changes: 3 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"type": "library",
"license": "MIT",
"require": {
"php": "~8.1.0|~8.2.0|~8.3.0|~8.4.0",
"php": "~8.1.0|~8.2.0|~8.3.0|~8.4.0|~8.5.0",
"ext-dom": "*",
"ext-bcmath": "*",
"symfony/validator": "^4.4|^5.0|^6.0|^7.0",
"symfony/intl": "^4.4|^5.0|^6.0|^7.0",
"symfony/validator": "^6.3|^7.0|^8.0",
"symfony/intl": "^6.3|^7.0|^8.0",
"kmukku/php-iso11649": "^1.5",
"endroid/qr-code": "^4.4.4|^5.0|^6.0",
"symfony/polyfill-intl-icu": "^1.23",
Expand All @@ -35,9 +35,6 @@
"phpunit": "vendor/bin/phpunit",
"rector": "vendor/bin/rector"
},
"conflict": {
"khanamiryan/qrcode-detector-decoder": "1.0.6"
},
"suggest": {
"tecnickcom/tcpdf": "Needed to create pdfs with TcPdfOutput",
"fpdf/fpdf": "Needed to create pdfs with FpdfOutput",
Expand Down
12 changes: 6 additions & 6 deletions src/DataGroup/Element/AdditionalInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ public function getQrCodeData(): array
public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraints('message', [
new Assert\Length([
'max' => 140
])
new Assert\Length(
max: 140
)
]);

$metadata->addPropertyConstraints('billInformation', [
new Assert\Length([
'max' => 140
])
new Assert\Length(
max: 140
)
]);
}
}
6 changes: 3 additions & 3 deletions src/DataGroup/Element/AlternativeScheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraints('parameter', [
new Assert\NotBlank(),
new Assert\Length([
'max' => 100
])
new Assert\Length(
max: 100
)
]);
}
}
8 changes: 4 additions & 4 deletions src/DataGroup/Element/CreditorInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public static function loadValidatorMetadata(ClassMetadata $metadata): void
$metadata->addPropertyConstraints('iban', [
new Assert\NotBlank(),
new Assert\Iban(),
new Assert\Regex([
'pattern' => '/^(CH|LI)/',
'match' => true
])
new Assert\Regex(
pattern: '/^(CH|LI)/',
match: true
)
]);
}
}
24 changes: 12 additions & 12 deletions src/DataGroup/Element/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,28 @@ public static function loadValidatorMetadata(ClassMetadata $metadata): void
// Fixed length, three-digit, alphanumeric
$metadata->addPropertyConstraints('qrType', [
new Assert\NotBlank(),
new Assert\Regex([
'pattern' => '/^[a-zA-Z0-9]{3}$/',
'match' => true
])
new Assert\Regex(
pattern: '/^[a-zA-Z0-9]{3}$/',
match: true
)
]);

// Fixed length, four-digit, numeric
$metadata->addPropertyConstraints('version', [
new Assert\NotBlank(),
new Assert\Regex([
'pattern' => '/^\d{4}$/',
'match' => true
])
new Assert\Regex(
pattern: '/^\d{4}$/',
match: true
)
]);

// One-digit, numeric
$metadata->addPropertyConstraints('coding', [
new Assert\NotBlank(),
new Assert\Regex([
'pattern' => '/^\d{1}$/',
'match' => true
])
new Assert\Regex(
pattern: '/^\d{1}$/',
match: true
)
]);
}
}
10 changes: 5 additions & 5 deletions src/DataGroup/Element/PaymentAmountInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ public function getQrCodeData(): array
public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraints('amount', [
new Assert\Range([
'min' => 0,
'max'=> 999999999.99
]),
new Assert\Range(
min: 0,
max: 999999999.99
),
]);

$metadata->addPropertyConstraints('currency', [
new Assert\Choice([
new Assert\Choice(choices: [
self::CURRENCY_CHF,
self::CURRENCY_EUR
])
Expand Down
49 changes: 23 additions & 26 deletions src/DataGroup/Element/PaymentReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,39 +72,36 @@ public static function loadValidatorMetadata(ClassMetadata $metadata): void
$metadata->setGroupSequenceProvider(true);

$metadata->addPropertyConstraints('type', [
new Assert\NotBlank([
'groups' => ['default']
]),
new Assert\Choice([
'groups' => ['default'],
'choices' => [
new Assert\NotBlank(groups: ['default']),
new Assert\Choice(
groups: ['default'],
choices: [
self::TYPE_QR,
self::TYPE_SCOR,
self::TYPE_NON
]
])
)
]);

$metadata->addPropertyConstraints('reference', [
/** @phpstan-ignore-next-line because docs do not match bc compatible syntax */
new Assert\Type([
'type' => 'alnum',
'groups' => [self::TYPE_QR]
]),
new Assert\NotBlank([
'groups' => [self::TYPE_QR, self::TYPE_SCOR]
]),
new Assert\Length([
'min' => 27,
'max' => 27,
'groups' => [self::TYPE_QR]
]),
new Assert\Blank([
'groups' => [self::TYPE_NON]
]),
new ValidCreditorReference([
'groups' => [self::TYPE_SCOR]
])
new Assert\Type(
type: 'alnum',
groups: [self::TYPE_QR]
),
new Assert\NotBlank(
groups: [self::TYPE_QR, self::TYPE_SCOR]
),
new Assert\Length(
min: 27,
max: 27,
groups: [self::TYPE_QR]
),
new Assert\Blank(
groups: [self::TYPE_NON]
),
new ValidCreditorReference(
groups: [self::TYPE_SCOR]
)
]);
}

Expand Down
30 changes: 15 additions & 15 deletions src/DataGroup/Element/StructuredAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,35 +166,35 @@ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraints('name', [
new Assert\NotBlank(),
new Assert\Length([
'max' => 70
])
new Assert\Length(
max: 70
)
]);

$metadata->addPropertyConstraints('street', [
new Assert\Length([
'max' => 70
])
new Assert\Length(
max: 70
)
]);

$metadata->addPropertyConstraints('buildingNumber', [
new Assert\Length([
'max' => 16
])
new Assert\Length(
max: 16
)
]);

$metadata->addPropertyConstraints('postalCode', [
new Assert\NotBlank(),
new Assert\Length([
'max' => 16
])
new Assert\Length(
max: 16
)
]);

$metadata->addPropertyConstraints('city', [
new Assert\NotBlank(),
new Assert\Length([
'max' => 35
])
new Assert\Length(
max: 35
)
]);

$metadata->addPropertyConstraints('country', [
Expand Down
12 changes: 6 additions & 6 deletions src/QrBill.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,12 @@ public static function loadValidatorMetadata(ClassMetadata $metadata): void
]);

$metadata->addPropertyConstraints('alternativeSchemes', [
new Assert\Count([
'max' => 2
]),
new Assert\Valid([
'traverse' => true
])
new Assert\Count(
max: 2
),
new Assert\Valid(
traverse: true
)
]);
}
}
24 changes: 12 additions & 12 deletions src/Reference/QrPaymentReferenceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraints('customerIdentificationNumber', [
// Only numbers are allowed (including leading zeros)
new Assert\Regex([
'pattern' => '/^\d*$/',
'match' => true
]),
new Assert\Length([
'max' => 11
]),
new Assert\Regex(
pattern: '/^\d*$/',
match: true
),
new Assert\Length(
max: 11
),
]);

$metadata->addPropertyConstraints('referenceNumber', [
new Assert\Regex([
'pattern' => '/^\d*$/',
'match' => true,
'message' => 'The reference number must not contain any non-numeric characters.'
]),
new Assert\Regex(
pattern: '/^\d*$/',
match: true,
message: 'The reference number must not contain any non-numeric characters.'
),
new Assert\NotBlank()
]);

Expand Down
16 changes: 8 additions & 8 deletions src/Reference/RfCreditorReferenceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public function doGenerate(): string
public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraints('reference', [
new Assert\Regex([
'pattern' => '/^[a-zA-Z0-9]*$/',
'match' => true
]),
new Assert\Length([
'min' => 1,
'max' => 21 // 25 minus 'RF' prefix minus 2-digit check sum
]),
new Assert\Regex(
pattern: '/^[a-zA-Z0-9]*$/',
match: true
),
new Assert\Length(
min: 1,
max: 21 // 25 minus 'RF' prefix minus 2-digit check sum
),
new Assert\NotBlank()
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,10 @@ public function testInvalidCombinations(bool $containsQrIban, string $paymentRef
$this->getPaymentReferenceMock($paymentReferenceType)
);

$this->validator->validate($qrBillMock, new ValidCreditorInformationPaymentReferenceCombination([
'message' => 'myMessage',
]));
$constraint = new ValidCreditorInformationPaymentReferenceCombination();
$this->validator->validate($qrBillMock, $constraint);

$this->buildViolation('myMessage')
$this->buildViolation($constraint->message)
->setParameter('{{ referenceType }}', $qrBillMock->getPaymentReference()->getType())
->setParameter('{{ iban }}', $qrBillMock->getCreditorInformation()->getIban())
->assertRaised();
Expand Down
7 changes: 3 additions & 4 deletions tests/Constraints/ValidCreditorReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ public static function getValidCreditorReferences()
#[DataProvider('getInvalidCreditorReferences')]
public function testInvalidCreditorReferences($creditorReference)
{
$this->validator->validate($creditorReference, new ValidCreditorReference([
'message' => 'myMessage',
]));
$constraint = new ValidCreditorReference();
$this->validator->validate($creditorReference, $constraint);

$this->buildViolation('myMessage')
$this->buildViolation($constraint->message)
->setParameter('{{ string }}', $creditorReference)
->assertRaised();
}
Expand Down