Skip to content

Commit c797f1a

Browse files
committed
Deprecation of Rule
1 parent dda7bd0 commit c797f1a

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

src/Commands/ExportPostmanCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Console\Command;
77
use Illuminate\Contracts\Config\Repository;
88
use Illuminate\Contracts\Validation\Rule;
9+
use Illuminate\Contracts\Validation\ValidationRule;
910
use Illuminate\Foundation\Http\FormRequest;
1011
use Illuminate\Routing\Router;
1112
use Illuminate\Support\Facades\Storage;
@@ -358,7 +359,7 @@ protected function parseRulesIntoHumanReadable($attribute, $rules): string
358359
if (! $this->config['rules_to_human_readable']) {
359360
foreach ($rules as $i => $rule) {
360361
// because we don't support custom rule classes, we remove them from the rules
361-
if (is_subclass_of($rule, Rule::class)) {
362+
if (is_subclass_of($rule, Rule::class) || is_subclass_of($rule, ValidationRule::class)) {
362363
unset($rules[$i]);
363364
}
364365
}
@@ -523,7 +524,7 @@ protected function handleEdgeCases(array $messages): array
523524
*/
524525
protected function safelyStringifyClassBasedRule($probableRule): string
525526
{
526-
if (! is_object($probableRule) || is_subclass_of($probableRule, Rule::class) || ! method_exists($probableRule, '__toString')) {
527+
if (! is_object($probableRule) || is_subclass_of($probableRule, Rule::class) || is_subclass_of($probableRule, ValidationRule::class) || ! method_exists($probableRule, '__toString')) {
527528
return '';
528529
}
529530

tests/Fixtures/UppercaseRule.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,23 @@
22

33
namespace AndreasElia\PostmanGenerator\Tests\Fixtures;
44

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

7-
class UppercaseRule implements Rule
8+
class UppercaseRule implements ValidationRule
89
{
910
/**
10-
* Determine if the validation rule passes.
11+
* Run the validation rule.
1112
*
1213
* @param string $attribute
1314
* @param mixed $value
14-
* @return bool
15+
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
16+
* @return void
1517
*/
16-
public function passes($attribute, $value)
18+
public function validate(string $attribute, mixed $value, Closure $fail): void
1719
{
18-
return strtoupper($value) === $value;
19-
}
20-
21-
/**
22-
* Get the validation error message.
23-
*
24-
* @return string
25-
*/
26-
public function message()
27-
{
28-
return 'The :attribute must be uppercase.';
20+
if (strtoupper($value) !== $value) {
21+
$fail("The {$attribute} must be uppercase.");
22+
}
2923
}
3024
}

0 commit comments

Comments
 (0)