Skip to content

Commit eb9cc67

Browse files
committed
Remove :examples error placeholder
1 parent c3dc85f commit eb9cc67

File tree

8 files changed

+10
-134
lines changed

8 files changed

+10
-134
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ All notable changes to this project will be documented in this file.
1414
- Lumen is no longer supported
1515
- Validation overrides are no longer supported
1616
- Manual validation is no longer supported
17+
- Error message placeholder `:examples` is no longer provided

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,8 @@ The following placeholders will be automatically filled for you:
118118
|-------------|------------------------------------------------------------|
119119
| :attribute | The name of the field that was under validation |
120120
| :countries | The countries that were validated against (e.g. `NL, BE`)* |
121-
| :examples | Examples of allowed postal codes (e.g. `1234 AB, 4000`)* |
122121

123-
*The `:countries` and `:examples` placeholders may be empty if no valid countries are passed.
122+
*The `:countries` placeholder may be empty if no valid countries are passed.
124123

125124
**Important**: If you believe there is a bug in one of the patterns that this package ships with, please create an
126125
[issue](https://github.com/axlon/laravel-postal-code-validation/issues/new) in the issue tracker.

phpstan-baseline.neon

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,6 @@ parameters:
66
count: 1
77
path: src/Extensions/PostalCodeFor.php
88

9-
-
10-
message: '#^Parameter \#1 \$countryCode of method Axlon\\PostalCodeValidation\\Support\\PostalCodeExamples\:\:get\(\) expects string, mixed given\.$#'
11-
identifier: argument.type
12-
count: 1
13-
path: src/Extensions/PostalCodeFor.php
14-
15-
-
16-
message: '#^Cannot access offset string on mixed\.$#'
17-
identifier: offsetAccess.nonOffsetAccessible
18-
count: 1
19-
path: src/Support/PostalCodeExamples.php
20-
21-
-
22-
message: '#^Method Axlon\\PostalCodeValidation\\Support\\PostalCodeExamples\:\:get\(\) should return string\|null but returns mixed\.$#'
23-
identifier: return.type
24-
count: 1
25-
path: src/Support/PostalCodeExamples.php
26-
27-
-
28-
message: '#^Property Axlon\\PostalCodeValidation\\Support\\PostalCodeExamples\:\:\$examples \(array\<string, string\>\|null\) does not accept mixed\.$#'
29-
identifier: assign.propertyType
30-
count: 1
31-
path: src/Support/PostalCodeExamples.php
32-
339
-
3410
message: '#^Parameter \#1 \$patterns of class Axlon\\PostalCodeValidation\\PostalCodeValidator constructor expects array\<string, string\|null\>, mixed given\.$#'
3511
identifier: argument.type

src/Extensions/PostalCode.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,10 @@
55
namespace Axlon\PostalCodeValidation\Extensions;
66

77
use Axlon\PostalCodeValidation\PostalCodeValidator;
8-
use Axlon\PostalCodeValidation\Support\PostalCodeExamples;
98
use InvalidArgumentException;
109

1110
final class PostalCode
1211
{
13-
/**
14-
* The postal code examples.
15-
*
16-
* @var \Axlon\PostalCodeValidation\Support\PostalCodeExamples
17-
*/
18-
protected $examples;
19-
2012
/**
2113
* The pattern matcher.
2214
*
@@ -28,12 +20,10 @@ final class PostalCode
2820
* Create a new PostalCode validator extension.
2921
*
3022
* @param \Axlon\PostalCodeValidation\PostalCodeValidator $validator
31-
* @param \Axlon\PostalCodeValidation\Support\PostalCodeExamples $examples
3223
* @return void
3324
*/
34-
public function __construct(PostalCodeValidator $validator, PostalCodeExamples $examples)
25+
public function __construct(PostalCodeValidator $validator)
3526
{
36-
$this->examples = $examples;
3727
$this->validator = $validator;
3828
}
3929

@@ -49,24 +39,17 @@ public function __construct(PostalCodeValidator $validator, PostalCodeExamples $
4939
public function replace(string $message, string $attribute, string $rule, array $parameters): string
5040
{
5141
$countries = [];
52-
$examples = [];
5342

5443
foreach ($parameters as $parameter) {
55-
if (($example = $this->examples->get($parameter)) === null) {
56-
continue;
57-
}
58-
5944
$countries[] = $parameter;
60-
$examples[] = $example;
6145
}
6246

6347
$replacements = [
6448
$attribute,
6549
implode(', ', array_unique($countries)),
66-
implode(', ', array_unique($examples)),
6750
];
6851

69-
return str_replace([':attribute', ':countries', ':examples'], $replacements, $message);
52+
return str_replace([':attribute', ':countries'], $replacements, $message);
7053
}
7154

7255
/**

src/Extensions/PostalCodeFor.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,12 @@
55
namespace Axlon\PostalCodeValidation\Extensions;
66

77
use Axlon\PostalCodeValidation\PostalCodeValidator;
8-
use Axlon\PostalCodeValidation\Support\PostalCodeExamples;
98
use Illuminate\Support\Arr;
109
use Illuminate\Validation\Validator;
1110
use InvalidArgumentException;
1211

1312
final class PostalCodeFor
1413
{
15-
/**
16-
* The postal code examples.
17-
*
18-
* @var \Axlon\PostalCodeValidation\Support\PostalCodeExamples
19-
*/
20-
protected $examples;
21-
2214
/**
2315
* The pattern matcher.
2416
*
@@ -30,12 +22,10 @@ final class PostalCodeFor
3022
* Create a new PostalCodeFor validator extension.
3123
*
3224
* @param \Axlon\PostalCodeValidation\PostalCodeValidator $validator
33-
* @param \Axlon\PostalCodeValidation\Support\PostalCodeExamples $examples
3425
* @return void
3526
*/
36-
public function __construct(PostalCodeValidator $validator, PostalCodeExamples $examples)
27+
public function __construct(PostalCodeValidator $validator)
3728
{
38-
$this->examples = $examples;
3929
$this->validator = $validator;
4030
}
4131

@@ -57,28 +47,21 @@ public function replace(
5747
Validator $validator,
5848
): string {
5949
$countries = [];
60-
$examples = [];
6150

6251
foreach ($parameters as $parameter) {
6352
if (($input = Arr::get($validator->getData(), $parameter)) === null) {
6453
continue;
6554
}
6655

67-
if (($example = $this->examples->get($input)) === null) {
68-
continue;
69-
}
70-
7156
$countries[] = $input;
72-
$examples[] = $example;
7357
}
7458

7559
$replacements = [
7660
$attribute,
7761
implode(', ', array_unique($countries)),
78-
implode(', ', array_unique($examples)),
7962
];
8063

81-
return str_replace([':attribute', ':countries', ':examples'], $replacements, $message);
64+
return str_replace([':attribute', ':countries'], $replacements, $message);
8265
}
8366

8467
/**

src/Support/PostalCodeExamples.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

tests/Integration/ReplacerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public function testPostalCodeReplacer(): void
2222
);
2323

2424
Lang::addLines([
25-
'validation.postal_code' => ':attribute invalid, should be a :countries postal code (e.g. :examples)',
25+
'validation.postal_code' => ':attribute invalid, should be a :countries postal code',
2626
], 'en');
2727

2828
self::assertContains(
29-
'postal code invalid, should be a NL postal code (e.g. 1234 AB)',
29+
'postal code invalid, should be a NL postal code',
3030
$validator->errors()->all(),
3131
);
3232
}
@@ -44,11 +44,11 @@ public function testPostalCodeForReplacer(): void
4444
);
4545

4646
Lang::addLines([
47-
'validation.postal_code_for' => ':attribute invalid, should be a :countries postal code (e.g. :examples)',
47+
'validation.postal_code_for' => ':attribute invalid, should be a :countries postal code',
4848
], 'en');
4949

5050
self::assertContains(
51-
'postal code invalid, should be a NL postal code (e.g. 1234 AB)',
51+
'postal code invalid, should be a NL postal code',
5252
$validator->errors()->all(),
5353
);
5454
}

tests/Unit/PostalCodeExamplesTest.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)