Skip to content

Commit 1ac1412

Browse files
committed
feat: refactor UkTaxCode to implement ValidationRule
1 parent 9b6d446 commit 1ac1412

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
},
1818
"require-dev": {
1919
"pestphp/pest": "^3.7",
20-
"worksome/coding-style": "^3.1"
20+
"worksome/coding-style": "^3.1",
21+
"orchestra/testbench": "^9.11"
2122
},
2223
"autoload": {
2324
"psr-4": {

phpstan-baseline.neon

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +0,0 @@
1-
parameters:
2-
ignoreErrors:
3-
-
4-
message: '''
5-
#^Class Worksome\\UkTaxCodeValidator\\UkTaxCode implements deprecated interface Illuminate\\Contracts\\Validation\\Rule\:
6-
see ValidationRule$#
7-
'''
8-
identifier: class.implementsDeprecatedInterface
9-
count: 1
10-
path: src/UkTaxCode.php

src/UkTaxCode.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@
22

33
namespace Worksome\UkTaxCodeValidator;
44

5-
use Illuminate\Contracts\Validation\Rule;
5+
use Closure;
6+
use Illuminate\Contracts\Validation\ValidationRule;
67

7-
class UkTaxCode implements Rule
8+
class UkTaxCode implements ValidationRule
89
{
9-
public function passes($attribute, $value)
10+
public function validate(string $attribute, mixed $value, Closure $fail): void
1011
{
1112
$engine = new Engine();
1213
$response = $engine->validate($value);
1314

14-
return $response->isValid();
15-
}
16-
17-
public function message(): string
18-
{
19-
return 'The :attribute must be a valid UK tax code.';
15+
if (! $response->isValid()) {
16+
$fail('The :attribute must be a valid UK tax code.');
17+
}
2018
}
2119
}

0 commit comments

Comments
 (0)