Skip to content

Commit f9618c4

Browse files
authored
Format code (#5172)
1 parent 39464f0 commit f9618c4

13 files changed

+50
-32
lines changed

src/Concerns/ValidatesAttributes.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ public function isValidFileInstance($value): bool
11351135
/**
11361136
* Require a certain number of parameters to be present.
11371137
*
1138-
* @throws \InvalidArgumentException
1138+
* @throws InvalidArgumentException
11391139
*/
11401140
public function requireParameterCount(int $count, array $parameters, string $rule)
11411141
{
@@ -1217,7 +1217,7 @@ protected function checkDateTimeOrder(string $format, string $first, string $sec
12171217
/**
12181218
* Get a DateTime instance from a string.
12191219
*
1220-
* @return null|\DateTime
1220+
* @return null|DateTime
12211221
*/
12221222
protected function getDateTimeWithOptionalFormat(string $format, ?string $value)
12231223
{
@@ -1234,7 +1234,7 @@ protected function getDateTimeWithOptionalFormat(string $format, ?string $value)
12341234
/**
12351235
* Get a DateTime instance from a string with no format.
12361236
*
1237-
* @return null|\DateTime
1237+
* @return null|DateTime
12381238
*/
12391239
protected function getDateTime(string $value)
12401240
{
@@ -1503,7 +1503,7 @@ protected function getSize(string $attribute, $value): float|int|string
15031503
*
15041504
* @param mixed $first
15051505
* @param mixed $second
1506-
* @throws \InvalidArgumentException
1506+
* @throws InvalidArgumentException
15071507
*/
15081508
protected function compare($first, $second, string $operator): bool
15091509
{

src/Contract/ValidatorFactoryInterface.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
namespace Hyperf\Validation\Contract;
1313

14+
use Closure;
1415
use Hyperf\Contract\ValidatorInterface;
1516

1617
interface ValidatorFactoryInterface
@@ -23,15 +24,15 @@ public function make(array $data, array $rules, array $messages = [], array $cus
2324
/**
2425
* Register a custom validator extension.
2526
*/
26-
public function extend(string $rule, \Closure|string $extension, ?string $message = null);
27+
public function extend(string $rule, Closure|string $extension, ?string $message = null);
2728

2829
/**
2930
* Register a custom implicit validator extension.
3031
*/
31-
public function extendImplicit(string $rule, \Closure|string $extension, ?string $message = null);
32+
public function extendImplicit(string $rule, Closure|string $extension, ?string $message = null);
3233

3334
/**
3435
* Register a custom implicit validator message replacer.
3536
*/
36-
public function replacer(string $rule, \Closure|string $replacer);
37+
public function replacer(string $rule, Closure|string $replacer);
3738
}

src/Middleware/ValidationMiddleware.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Psr\Http\Message\ServerRequestInterface;
2929
use Psr\Http\Server\MiddlewareInterface;
3030
use Psr\Http\Server\RequestHandlerInterface;
31+
use RuntimeException;
3132

3233
class ValidationMiddleware implements MiddlewareInterface
3334
{
@@ -141,6 +142,6 @@ protected function prepareHandler(array|string $handler): array
141142
if (is_array($handler) && isset($handler[0], $handler[1])) {
142143
return $handler;
143144
}
144-
throw new \RuntimeException('Handler not exist.');
145+
throw new RuntimeException('Handler not exist.');
145146
}
146147
}

src/Rules/Dimensions.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
*/
1212
namespace Hyperf\Validation\Rules;
1313

14-
class Dimensions implements \Stringable
14+
use Stringable;
15+
16+
class Dimensions implements Stringable
1517
{
1618
/**
1719
* Create a new dimensions rule instance.

src/Rules/Exists.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
*/
1212
namespace Hyperf\Validation\Rules;
1313

14-
class Exists implements \Stringable
14+
use Stringable;
15+
16+
class Exists implements Stringable
1517
{
1618
use DatabaseRule;
1719

src/Rules/In.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
*/
1212
namespace Hyperf\Validation\Rules;
1313

14-
class In implements \Stringable
14+
use Stringable;
15+
16+
class In implements Stringable
1517
{
1618
/**
1719
* The name of the rule.

src/Rules/NotIn.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
*/
1212
namespace Hyperf\Validation\Rules;
1313

14-
class NotIn implements \Stringable
14+
use Stringable;
15+
16+
class NotIn implements Stringable
1517
{
1618
/**
1719
* The name of the rule.

src/Rules/RequiredIf.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
*/
1212
namespace Hyperf\Validation\Rules;
1313

14-
class RequiredIf implements \Stringable
14+
use Stringable;
15+
16+
class RequiredIf implements Stringable
1517
{
1618
/**
1719
* The condition that validates the attribute.

src/Rules/Unique.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
namespace Hyperf\Validation\Rules;
1313

1414
use Hyperf\Database\Model\Model;
15+
use Stringable;
1516

16-
class Unique implements \Stringable
17+
class Unique implements Stringable
1718
{
1819
use DatabaseRule;
1920

src/ValidationRuleParser.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Hyperf\Validation\Contract\Rule as RuleContract;
1818
use Hyperf\Validation\Rules\Exists;
1919
use Hyperf\Validation\Rules\Unique;
20+
use stdClass;
21+
use Stringable;
2022

2123
class ValidationRuleParser
2224
{
@@ -37,7 +39,7 @@ public function __construct(public array $data)
3739
/**
3840
* Parse the human-friendly rules into a full rules array for the validator.
3941
*
40-
* @return \stdClass
42+
* @return stdClass
4143
*/
4244
public function explode(array $rules)
4345
{
@@ -54,7 +56,7 @@ public function explode(array $rules)
5456
/**
5557
* Merge additional rules into a given attribute(s).
5658
*
57-
* @param array|string|\Stringable $rules
59+
* @param array|string|Stringable $rules
5860
*/
5961
public function mergeRules(array $results, array|string $attribute, mixed $rules = []): array
6062
{
@@ -155,7 +157,7 @@ protected function prepareRule($rule)
155157
/**
156158
* Define a set of rules that apply to each element in an array attribute.
157159
*
158-
* @param array|string|\Stringable $rules
160+
* @param array|string|Stringable $rules
159161
*/
160162
protected function explodeWildcardRules(array $results, string $attribute, mixed $rules): array
161163
{
@@ -179,7 +181,7 @@ protected function explodeWildcardRules(array $results, string $attribute, mixed
179181
/**
180182
* Merge additional rules into a given attribute.
181183
*
182-
* @param array|string|\Stringable $rules
184+
* @param array|string|Stringable $rules
183185
*/
184186
protected function mergeRulesForAttribute(array $results, string $attribute, mixed $rules): array
185187
{

src/Validator.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Hyperf\Validation;
1313

1414
use BadMethodCallException;
15+
use Closure;
1516
use Hyperf\Contract\MessageBag as MessageBagContract;
1617
use Hyperf\Contract\TranslatorInterface;
1718
use Hyperf\Contract\ValidatorInterface as ValidatorContract;
@@ -25,6 +26,7 @@
2526
use Hyperf\Validation\Contract\Rule as RuleContract;
2627
use Psr\Container\ContainerInterface;
2728
use RuntimeException;
29+
use Stringable;
2830

2931
class Validator implements ValidatorContract
3032
{
@@ -84,7 +86,7 @@ class Validator implements ValidatorContract
8486
/**
8587
* The current rule that is validating.
8688
*
87-
* @var string|\Stringable
89+
* @var string|Stringable
8890
*/
8991
protected mixed $currentRule;
9092

@@ -161,7 +163,7 @@ public function __construct(
161163
*
162164
* @param mixed $method
163165
* @param mixed $parameters
164-
* @throws \BadMethodCallException when method does not exist
166+
* @throws BadMethodCallException when method does not exist
165167
*/
166168
public function __call($method, $parameters)
167169
{
@@ -387,7 +389,7 @@ public function getMessageBag(): MessageBagContract
387389
/**
388390
* Determine if the given attribute has a rule in the given set.
389391
*
390-
* @param array|string|\Stringable $rules
392+
* @param array|string|Stringable $rules
391393
*/
392394
public function hasRule(string $attribute, mixed $rules): bool
393395
{
@@ -526,15 +528,15 @@ public function addDependentExtensions(array $extensions)
526528
/**
527529
* Register a custom validator extension.
528530
*/
529-
public function addExtension(string $rule, \Closure|string $extension)
531+
public function addExtension(string $rule, Closure|string $extension)
530532
{
531533
$this->extensions[Str::snake($rule)] = $extension;
532534
}
533535

534536
/**
535537
* Register a custom implicit validator extension.
536538
*/
537-
public function addImplicitExtension(string $rule, \Closure|string $extension)
539+
public function addImplicitExtension(string $rule, Closure|string $extension)
538540
{
539541
$this->addExtension($rule, $extension);
540542

@@ -544,7 +546,7 @@ public function addImplicitExtension(string $rule, \Closure|string $extension)
544546
/**
545547
* Register a custom dependent validator extension.
546548
*/
547-
public function addDependentExtension(string $rule, \Closure|string $extension)
549+
public function addDependentExtension(string $rule, Closure|string $extension)
548550
{
549551
$this->addExtension($rule, $extension);
550552

@@ -568,7 +570,7 @@ public function addReplacers(array $replacers)
568570
/**
569571
* Register a custom validator message replacer.
570572
*/
571-
public function addReplacer(string $rule, \Closure|string $replacer)
573+
public function addReplacer(string $rule, Closure|string $replacer)
572574
{
573575
$this->replacers[Str::snake($rule)] = $replacer;
574576
}
@@ -634,7 +636,7 @@ public function setFallbackMessages(array $messages)
634636
/**
635637
* Get the Presence Verifier implementation.
636638
*
637-
*@throws \RuntimeException
639+
*@throws RuntimeException
638640
*/
639641
public function getPresenceVerifier(): PresenceVerifierInterface
640642
{
@@ -648,7 +650,7 @@ public function getPresenceVerifier(): PresenceVerifierInterface
648650
/**
649651
* Get the Presence Verifier implementation.
650652
*
651-
* @throws \RuntimeException
653+
* @throws RuntimeException
652654
*/
653655
public function getPresenceVerifierFor(?string $connection): PresenceVerifierInterface
654656
{
@@ -930,7 +932,7 @@ protected function attributesThatHaveMessages(): array
930932
/**
931933
* Get a rule and its parameters for a given attribute.
932934
*
933-
* @param array|string|\Stringable $rules
935+
* @param array|string|Stringable $rules
934936
*/
935937
protected function getRule(string $attribute, mixed $rules): ?array
936938
{

src/ValidatorFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class ValidatorFactory implements ValidatorFactoryInterface
6666
/**
6767
* The Validator resolver instance.
6868
*
69-
* @var \Closure
69+
* @var Closure
7070
*/
7171
protected $resolver;
7272

tests/Cases/FormRequestTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Psr\Container\ContainerInterface;
2828
use Psr\Http\Message\ResponseInterface;
2929
use Psr\Http\Message\ServerRequestInterface;
30+
use Throwable;
3031

3132
/**
3233
* @internal
@@ -100,7 +101,7 @@ public function testRewriteGetRules()
100101
$request = new BarSceneRequest($container);
101102
$request->validateResolved();
102103
$this->assertTrue(false);
103-
} catch (\Throwable $exception) {
104+
} catch (Throwable $exception) {
104105
$this->assertInstanceOf(ValidationException::class, $exception);
105106
$this->assertSame('validation.integer', $exception->validator->errors()->first());
106107
}
@@ -131,7 +132,7 @@ public function testSceneForFormRequest()
131132
try {
132133
$request->validateResolved();
133134
$this->assertTrue(false);
134-
} catch (\Throwable $exception) {
135+
} catch (Throwable $exception) {
135136
$this->assertInstanceOf(ValidationException::class, $exception);
136137
}
137138
});
@@ -140,7 +141,7 @@ public function testSceneForFormRequest()
140141
$request = new FooSceneRequest($container);
141142
$request->validateResolved();
142143
$this->assertTrue(false);
143-
} catch (\Throwable $exception) {
144+
} catch (Throwable $exception) {
144145
$this->assertInstanceOf(ValidationException::class, $exception);
145146
}
146147
}

0 commit comments

Comments
 (0)