Skip to content

Commit aa58266

Browse files
authored
Cleanup and minor refactoring (#324)
* Cleanup and minor refactoring * Revert deletion of CustomUrlRule used in tests
1 parent 27e4546 commit aa58266

8 files changed

Lines changed: 16 additions & 16 deletions

src/Validator.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ public function validate(
8080
foreach ($rules ?? [] as $attribute => $attributeRules) {
8181
$result = new Result();
8282

83-
$tempRule = is_iterable($attributeRules) ? $attributeRules : [$attributeRules];
84-
$attributeRules = $this->normalizeRules($tempRule);
83+
if (!is_iterable($attributeRules)) {
84+
$attributeRules = [$attributeRules];
85+
}
86+
87+
$attributeRules = $this->normalizeRules($attributeRules);
8588

8689
if (is_int($attribute)) {
8790
$validatedData = $data->getData();

tests/DataSet/PHP80/ObjectDataSet80Test.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
use Yiisoft\Validator\Tests\Data\TitleTrait;
1717
use Yiisoft\Validator\Tests\Stub\FakeValidatorFactory;
1818
use Yiisoft\Validator\Tests\Stub\NotRuleAttribute;
19-
use Yiisoft\Validator\Tests\Stub\ObjectWithCallbackMethod;
20-
use Yiisoft\Validator\Tests\Stub\ObjectWithNonExistingCallbackMethod;
21-
use Yiisoft\Validator\Tests\Stub\ObjectWithNonPublicCallbackMethod;
22-
use Yiisoft\Validator\Tests\Stub\ObjectWithNonStaticCallbackMethod;
19+
use Yiisoft\Validator\Tests\Stub\ObjectWithCallbackMethod\ObjectWithCallbackMethod;
20+
use Yiisoft\Validator\Tests\Stub\ObjectWithCallbackMethod\ObjectWithNonExistingCallbackMethod;
21+
use Yiisoft\Validator\Tests\Stub\ObjectWithCallbackMethod\ObjectWithNonPublicCallbackMethod;
22+
use Yiisoft\Validator\Tests\Stub\ObjectWithCallbackMethod\ObjectWithNonStaticCallbackMethod;
2323

2424
final class ObjectDataSet80Test extends TestCase
2525
{

tests/Stub/ObjectWithCallbackMethod.php renamed to tests/Stub/ObjectWithCallbackMethod/ObjectWithCallbackMethod.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Yiisoft\Validator\Tests\Stub;
5+
namespace Yiisoft\Validator\Tests\Stub\ObjectWithCallbackMethod;
66

77
use Yiisoft\Validator\Result;
88
use Yiisoft\Validator\Rule\Callback;

tests/Stub/ObjectWithNonExistingCallbackMethod.php renamed to tests/Stub/ObjectWithCallbackMethod/ObjectWithNonExistingCallbackMethod.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Yiisoft\Validator\Tests\Stub;
5+
namespace Yiisoft\Validator\Tests\Stub\ObjectWithCallbackMethod;
66

77
use Yiisoft\Validator\Rule\Callback;
88

tests/Stub/ObjectWithNonPublicCallbackMethod.php renamed to tests/Stub/ObjectWithCallbackMethod/ObjectWithNonPublicCallbackMethod.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Yiisoft\Validator\Tests\Stub;
5+
namespace Yiisoft\Validator\Tests\Stub\ObjectWithCallbackMethod;
66

77
use Yiisoft\Validator\Result;
88
use Yiisoft\Validator\Rule\Callback;

tests/Stub/ObjectWithNonStaticCallbackMethod.php renamed to tests/Stub/ObjectWithCallbackMethod/ObjectWithNonStaticCallbackMethod.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Yiisoft\Validator\Tests\Stub;
5+
namespace Yiisoft\Validator\Tests\Stub\ObjectWithCallbackMethod;
66

77
use Yiisoft\Validator\Result;
88
use Yiisoft\Validator\Rule\Callback;

tests/Stub/PiHandler.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@
1010

1111
final class PiHandler implements RuleHandlerInterface
1212
{
13-
/**
14-
* @inheritDoc
15-
*/
16-
public function validate(mixed $value, object $rule, ?ValidationContext $context = null): Result
13+
public function validate(mixed $value, object $rule, ValidationContext $context): Result
1714
{
1815
$result = new Result();
1916

2017
if (!(\abs($value - M_PI) < PHP_FLOAT_EPSILON)) {
21-
$result->addError('Value must be Pi.', ['value' => $value]);
18+
$result->addError('Value must be Pi.');
2219
}
2320

2421
return $result;

tests/Stub/RuleHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
final class RuleHandler implements RuleHandlerInterface
1212
{
13-
public function validate(mixed $value, object $rule, ?ValidationContext $context = null): Result
13+
public function validate(mixed $value, object $rule, ValidationContext $context): Result
1414
{
1515
return new Result();
1616
}

0 commit comments

Comments
 (0)