Skip to content

Commit c57bc25

Browse files
authored
Merge pull request #4 from programmatordev/FV-2-rename-getconstraints-method-to-toarray
[BC] Rename getConstraints method to toArray
2 parents 8fffe25 + d9a7fec commit c57bc25

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ offering an easy-to-use and intuitive API to validate user input or other data i
2424
- [validate](#validate)
2525
- [assert](#assert)
2626
- [isValid](#isvalid)
27-
- [getConstraints](#getconstraints)
27+
- [toArray](#toarray)
2828
- [addNamespace](#addnamespace)
2929
- [setTranslator](#settranslator)
3030
- [Custom Constraints](#custom-constraints)
@@ -154,21 +154,21 @@ if (!Validator::email()->isValid($email)) {
154154
}
155155
```
156156

157-
### `getConstraints`
157+
### `toArray`
158158

159159
```php
160160
use Symfony\Component\Validator\Constraint;
161161

162162
/** @return Constraint[] */
163-
getConstraints(): array
163+
toArray(): array
164164
```
165165

166166
Returns an array with all added constraints.
167167

168168
```php
169169
use ProgrammatorDev\FluentValidator\Validator;
170170

171-
$constraints = Validator::notBlank()->email()->getConstraints();
171+
$constraints = Validator::notBlank()->email()->toArray();
172172
```
173173

174174
It is useful for `Composite` constraints (i.e., a constraint that is composed of other constraints)
@@ -180,7 +180,7 @@ use ProgrammatorDev\FluentValidator\Validator;
180180
// validate that array should have at least one value
181181
// and each value should be between 0 and 100
182182
$errors = Validator::count(min: 1)
183-
->all(Validator::range(min: 0, max: 100)->getConstraints())
183+
->all(Validator::range(min: 0, max: 100)->toArray())
184184
->validate($value);
185185
```
186186

src/Validator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function isValid(mixed $value, string|GroupSequence|array|null $groups =
8787
return $violations->count() === 0;
8888
}
8989

90-
public function getConstraints(): array
90+
public function toArray(): array
9191
{
9292
return $this->constraints;
9393
}

tests/ValidatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ public function testIsValid(): void
6767
$this->assertTrue($this->validator->isValid(18));
6868
}
6969

70-
public function testGetConstraints(): void
70+
public function testToArray(): void
7171
{
72-
$constraints = $this->validator->getConstraints();
72+
$constraints = $this->validator->toArray();
7373

7474
$this->assertInstanceOf(NotBlank::class, $constraints[0]);
7575
$this->assertInstanceOf(GreaterThanOrEqual::class, $constraints[1]);

0 commit comments

Comments
 (0)