Skip to content

Commit 8a4d24e

Browse files
committed
Improve validations/tests and add version number rule
1 parent 06ee77a commit 8a4d24e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+950
-298
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Bug report
33
about: Create a report to help us improve
44
title: ""
55
labels: bug
6-
assignees: vdhicts
6+
assignees: dvdheiden
77

88
---
99

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Feature request
33
about: Suggest an idea for this project
44
title: ""
55
labels: feature
6-
assignees: vdhicts
6+
assignees: dvdheiden
77

88
---
99

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
steps:
1515
- name: Checkout
16-
uses: actions/checkout@v2
16+
uses: actions/checkout@v4
1717

1818
- name: Setup PHP
1919
uses: shivammathur/setup-php@v2

README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ The package includes both English and Dutch translations. The translations can b
3838
Validates the provided [BIC number](https://www.betaalvereniging.nl/en/focus/giro-based-and-online-payments/bank-identifier-code-bic-for-sepa-transactions/).
3939

4040
```php
41-
'field' => [new \BicNumber()],
41+
'field' => [new BicNumber()],
4242
```
4343

4444
### Contains
@@ -89,7 +89,7 @@ When the date is not according to the 'Y-m-d H:i' format then you are able to sp
8989

9090
### DutchPhone
9191

92-
Validates if the value is a valid dutch phone number. Both mobile or landlines are supported. See the `Phone` validation
92+
Validates if the value is a valid Dutch phone number. Both mobile or landlines are supported. See the `Phone` validation
9393
rule to validate a phone number which isn't limited to the Netherlands.
9494

9595
```php
@@ -98,7 +98,7 @@ rule to validate a phone number which isn't limited to the Netherlands.
9898

9999
### DutchPostalCode
100100

101-
Validates if the value is a valid dutch zip code, like `1234AB`.
101+
Validates if the value is a valid Dutch zip code, like `1234AB`.
102102

103103
```php
104104
'field' => [new DutchPostalCode()],
@@ -196,7 +196,7 @@ Validates if the value is a valid version according to the [Semver](https://semv
196196

197197
### VatNumber
198198

199-
Validates if the value is a valid formatted VAT number.
199+
Validates if the value is a properly formatted VAT number.
200200

201201
```php
202202
'field' => [new VatNumber()],
@@ -205,6 +205,16 @@ Validates if the value is a valid formatted VAT number.
205205
**Be aware**: It doesn't check if the number is known in the VAT database. If you need to know the VAT number is truly
206206
legit, check with [VIES](https://ec.europa.eu/taxation_customs/vies/#/vat-validation).
207207

208+
### VersionNumber
209+
210+
Validates if the value is a valid version number. The rule accepts both `x.y.z` and `x.y` formats. The parameter
211+
`requirePatch` allows you to require the `z` part of the version number. This is useful for validation PHP version
212+
numbers for example.
213+
214+
```php
215+
'field' => [new VersionNumber(requirePatch: true)],
216+
```
217+
208218
## Contribution
209219

210220
Any contribution is welcome, but it should be (unit) tested and meet the PSR-12 standard and please create one pull
@@ -218,8 +228,3 @@ instead of using the issue tracker.
218228
## License
219229

220230
This package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).
221-
222-
## About vdhicts
223-
224-
[Vdhicts](https://www.vdhicts.nl) is the name of my personal company. Vdhicts develops and implements IT solutions for
225-
businesses and educational institutions.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"authors": [
1313
{
1414
"name": "Dick van der Heiden",
15-
"email": "info@vdhicts.nl",
16-
"homepage": "https://www.vdhicts.nl",
15+
"email": "dick@goedemiddag.nl",
16+
"homepage": "https://www.goedemiddag.nl",
1717
"role": "Developer"
1818
}
1919
],

pint.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
{
2-
"preset": "laravel",
3-
"rules": {
4-
"array_indentation": false,
5-
"phpdoc_align": false,
6-
"new_with_parentheses": false
7-
}
2+
"preset": "psr12"
83
}

resources/lang/en/messages.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,18 @@
99
'date_has_specific_minutes' => 'The :attribute must have one of :minutes minutes',
1010
'dutch_phone' => 'The :attribute must be a valid dutch phone number',
1111
'dutch_postal_code' => 'The :attribute must be a valid dutch post code',
12-
'hex_color' => 'The :attribute must be a valid Hex color',
1312
'hostname' => 'The :attribute must be a valid hostname',
1413
'iban' => 'The :attribute must be a valid IBAN',
1514
'interval' => 'The :attribute must be an interval',
1615
'maximum_hour_difference' => 'The start and end date differ more then :diff hours',
1716
'mime_type' => 'The :attribute must be a valid MIME',
1817
'not_contains' => 'The :attribute must not contain `:value`',
19-
'not_ends_with' => 'The :attribute must not end with `:value',
20-
'not_starts_with' => 'The :attribute must not start with `:value`',
21-
'password_strength' => 'The :attribute must contains at least one capital letter, one lowercase letter and one number',
2218
'phone' => 'The :attribute must be a valid phone number',
2319
'positive_interval' => 'The :attribute must be a positive interval',
2420
'price_custom_decimal' => 'The :attribute must be a valid price like `10 :separator 95`',
2521
'price' => 'The :attribute must be a valid price like `10,95` or `10.50`',
26-
'semver' => 'The :attribute must be a valid version according to the semver standard',
2722
'secure_url' => 'The :attribute must be a HTTPS url',
23+
'semver' => 'The :attribute must be a valid version according to the semver standard',
2824
'vat_number' => 'The :attribute must be a valid VAT number',
25+
'version' => 'The :attribute must be a valid version like `1.0` or `1.0.0`',
2926
];

resources/lang/nl/messages.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,18 @@
99
'date_has_specific_minutes' => 'Het veld :attribute moet ingesteld zijn op een van :minutes minuten',
1010
'dutch_phone' => 'Het veld :attribute moet een geldig telefoonnummer bevatten',
1111
'dutch_postal_code' => 'Het veld :attribute moet een geldige postcode bevatten',
12-
'hex_color' => 'Het veld :attribute moet een geldige Hex kleur bevatten',
1312
'hostname' => 'Het veld :attribute moet een geldige hostname bevatten',
1413
'iban' => 'Het veld :attribute moet een geldige IBAN bevatten',
1514
'interval' => 'Het veld :attribute moet een interval zijn',
1615
'maximum_hour_difference' => 'De start en eind datum moeten meer dan :diff uur verschil',
1716
'mime_type' => 'Het veld :attribute moet een geldig MIME-type zijn',
1817
'not_contains' => 'Het veld :attribute mag geen `:value` bevatten',
19-
'not_ends_with' => 'Het veld :attribute mag niet eindigen met `:value`',
20-
'not_starts_with' => 'Het veld :attribute mag niet beginnen `:value`',
21-
'password' => 'Het veld :attribute moet minstens een hoofdletter, een kleine letter en een nummer bevatten',
2218
'phone' => 'Het veld :attribute moet een geldig telefoonnummer bevatten',
2319
'positive_interval' => 'Het veld :attribute moet een positieve interval bevatten',
2420
'price_custom_decimal' => 'Het veld :attribute moet een geldig bedrag bevatten, zoals `10 :separator 95`',
2521
'price' => 'Het veld :attribute moet een geldig bedrag bevatten, zoals `10,95` of `10.50`',
2622
'secure_url' => 'Het veld :attribute moet een HTTPS url zijn',
2723
'semver' => 'Het veld :attribute moet een geldige versie zijn volgens de semver standaard',
2824
'vat_number' => 'Het veld :attribute moet een geldig BTW nummer bevatten',
25+
'version' => 'Het veld :attribute moet een geldige versie zijn zoals `1.0` of `1.0.0`',
2926
];

src/Rules/BicNumber.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ class BicNumber extends AbstractRule
88
{
99
public function passes(mixed $value): bool
1010
{
11+
if (! is_string($value)) {
12+
return false;
13+
}
14+
1115
return Regex::match('/^([a-zA-Z]){4}([a-zA-Z]){2}([0-9a-zA-Z]){2}([0-9a-zA-Z]{3})?$/', $value)->hasMatch();
1216
}
1317

src/Rules/Contains.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77
class Contains extends AbstractRule
88
{
99
public function __construct(
10-
private readonly string $needle = ''
11-
) {}
10+
private readonly string $needle = '',
11+
) {
12+
}
1213

1314
public function passes(mixed $value): bool
1415
{
16+
if (! is_string($value)) {
17+
return false;
18+
}
19+
1520
if (trim($this->needle) === '') {
1621
return false;
1722
}

0 commit comments

Comments
 (0)