Skip to content

Commit 8d989a7

Browse files
committed
Create a few classes the will be present in the next version
This commit will deprecate some classes in favor of a couple of news ones. If there are no customisations to `assert()`, `check()`, and other methods, the migration should be pretty easy on users.
1 parent 3c04d1d commit 8d989a7

11 files changed

Lines changed: 98 additions & 11 deletions

CONTRIBUTING.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ create a validator that validates if a string is equal to "Hello World".
4444

4545
The rule itself needs to implement the `Validatable` interface but, it is
4646
convenient to just extend the `AbstractRule` class.
47-
Doing that, you'll only need to declare one method: `validate($input)`.
47+
Doing that, you'll only need to declare one method: `isValid(mixed $input): bool`.
4848
This method must return `true` or `false`.
4949

5050
If your validator class is `HelloWorld`, it will be available as `v::helloWorld()`
@@ -62,17 +62,16 @@ declare(strict_types=1);
6262

6363
namespace Respect\Validation\Rules;
6464

65+
use Respect\Validation\Rules\Core\Simple;
66+
6567
/**
6668
* Explain in one sentence what this rule does.
6769
*
6870
* @author Your Name <youremail@yourdomain.tld>
6971
*/
70-
final class HelloWorld extends AbstractRule
72+
final class HelloWorld extends Simple
7173
{
72-
/**
73-
* {@inheritDoc}
74-
*/
75-
public function validate($input): bool
74+
public function isValid(mixed $input): bool
7675
{
7776
return $input === 'Hello World';
7877
}
@@ -90,8 +89,8 @@ are able to use any methods of it. By extending `RuleTestCase` you should
9089
implement two methods that should return a [data provider][] with the rule as
9190
first item of the arrays:
9291

93-
- `providerForValidInput`: Will test when `validate()` should return `true`
94-
- `providerForInvalidInput`: Will test when `validate()` should return `false`
92+
- `providerForValidInput`: Will test when `isValid()` should return `true`
93+
- `providerForInvalidInput`: Will test when `isValid()` should return `false`
9594

9695
```php
9796
<?php

docs/06-custom-rules.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ validate method will be executed. Here's how the class should look:
1010
```php
1111
namespace My\Validation\Rules;
1212

13-
use Respect\Validation\Rules\AbstractRule;
13+
use Respect\Validation\Rules\Core\Simple;
1414

15-
final class Something extends AbstractRule
15+
final class Something extends Simple
1616
{
17-
public function validate($input): bool
17+
public function isValid(mixed $input): bool
1818
{
1919
// Do something here with the $input and return a boolean value
2020
}

library/Rules/AbstractComposite.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
2323
* @author Henrique Moody <henriquemoody@gmail.com>
2424
* @author Wojciech Frącz <fraczwojciech@gmail.com>
25+
*
26+
* @deprecated This class is deprecated, and will be removed in the next major version. Use {@see \Respect\Validation\Rules\Core\Composite} instead.
2527
*/
2628
abstract class AbstractComposite extends AbstractRule
2729
{

library/Rules/AbstractEnvelope.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* having an custom message.
2020
*
2121
* @author Henrique Moody <henriquemoody@gmail.com>
22+
*
23+
* @deprecated This class is deprecated, and will be removed in the next major version. Use {@see \Respect\Validation\Rules\Core\Envelop} instead.
2224
*/
2325
abstract class AbstractEnvelope extends AbstractRule
2426
{

library/Rules/AbstractRule.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* @author Henrique Moody <henriquemoody@gmail.com>
1919
* @author Nick Lombard <github@jigsoft.co.za>
2020
* @author Vicente Mendoza <vicentemmor@yahoo.com.mx>
21+
*
22+
* @deprecated This class is deprecated, and will be removed in the next major version. Use {@see \Respect\Validation\Rules\Core\Simple} instead.
2123
*/
2224
abstract class AbstractRule implements Validatable
2325
{

library/Rules/AbstractWrapper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*
1717
* @author Alasdair North <alasdair@runway.io>
1818
* @author Henrique Moody <henriquemoody@gmail.com>
19+
*
20+
* @deprecated This class is deprecated, and will be removed in the next major version. Use {@see \Respect\Validation\Rules\Core\Wrapper} instead.
1921
*/
2022
abstract class AbstractWrapper extends AbstractRule
2123
{

library/Rules/Core/Composite.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Respect\Validation\Rules\Core;
11+
12+
use Respect\Validation\Rules\AbstractComposite;
13+
use Respect\Validation\Validatable;
14+
15+
abstract class Composite extends AbstractComposite
16+
{
17+
public function __construct(Validatable $rule1, Validatable $rule2, Validatable ...$rules)
18+
{
19+
parent::__construct($rule1, $rule2, ...$rules);
20+
}
21+
}

library/Rules/Core/Envelope.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Respect\Validation\Rules\Core;
11+
12+
use Respect\Validation\Rules\AbstractEnvelope;
13+
14+
abstract class Envelope extends AbstractEnvelope
15+
{
16+
}

library/Rules/Core/Simple.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Respect\Validation\Rules\Core;
11+
12+
use Respect\Validation\Rules\AbstractRule;
13+
14+
abstract class Simple extends AbstractRule
15+
{
16+
abstract public function isValid(mixed $input): bool;
17+
18+
/**
19+
* @deprecated Calling `validate()` directly from rules is deprecated. Please use {@see Validator::isValid()} instead.
20+
*/
21+
public function validate($input): bool
22+
{
23+
return $this->isValid($input);
24+
}
25+
}

library/Rules/Core/Wrapper.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Respect\Validation\Rules\Core;
11+
12+
use Respect\Validation\Rules\AbstractWrapper;
13+
14+
abstract class Wrapper extends AbstractWrapper
15+
{
16+
}

0 commit comments

Comments
 (0)