Skip to content

Commit f149e6b

Browse files
authored
Improve readme + Adopt psalm + Update dev dependencies (#95)
1 parent acf8340 commit f149e6b

4 files changed

Lines changed: 39 additions & 23 deletions

File tree

README.md

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ The package provides data validation capabilities.
2727
- Could pass context to validation rule.
2828
- Common rules bundled.
2929

30+
## Requirements
31+
32+
- PHP 7.4 or higher.
33+
34+
## Installation
35+
36+
The package could be installed with composer:
37+
38+
```shell
39+
composer require yiisoft/validator --prefer-dist
40+
```
41+
3042
## General usage
3143

3244
Library could be used in two ways: validating a single value and validating a set of data.
@@ -238,6 +250,8 @@ foreach ($results as $attribute => $result) {
238250
}
239251
```
240252

253+
## Testing
254+
241255
### Unit testing
242256

243257
The package is tested with [PHPUnit](https://phpunit.de/). To run tests:
@@ -248,10 +262,11 @@ The package is tested with [PHPUnit](https://phpunit.de/). To run tests:
248262

249263
### Mutation testing
250264

251-
The package tests are checked with [Infection](https://infection.github.io/) mutation framework. To run it:
265+
The package tests are checked with [Infection](https://infection.github.io/) mutation framework with
266+
[Infection Static Analysis Plugin](https://github.com/Roave/infection-static-analysis-plugin). To run it:
252267

253268
```shell
254-
./vendor/bin/infection
269+
./vendor/bin/roave-infection-static-analysis-plugin
255270
```
256271

257272
### Static analysis
@@ -262,22 +277,21 @@ The code is statically analyzed with [Psalm](https://psalm.dev/). To run static
262277
./vendor/bin/psalm
263278
```
264279

265-
### Support the project
280+
## License
281+
282+
The Yii Validator is free software. It is released under the terms of the BSD License.
283+
Please see [`LICENSE`](./LICENSE.md) for more information.
284+
285+
Maintained by [Yii Software](https://www.yiiframework.com/).
286+
287+
## Support the project
266288

267289
[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective&logoColor=7eadf1&labelColor=555555)](https://opencollective.com/yiisoft)
268290

269-
### Follow updates
291+
## Follow updates
270292

271293
[![Official website](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](https://www.yiiframework.com/)
272294
[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter&logoColor=1DA1F2&labelColor=555555?style=flat)](https://twitter.com/yiiframework)
273295
[![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat&logo=telegram)](https://t.me/yii3en)
274296
[![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat&logo=facebook&logoColor=ffffff)](https://www.facebook.com/groups/yiitalk)
275297
[![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat&logo=slack)](https://yiiframework.com/go/slack)
276-
277-
## License
278-
279-
The Yii Validator is free software. It is released under the terms of the BSD License.
280-
Please see [`LICENSE`](./LICENSE.md) for more information.
281-
282-
Maintained by [Yii Software](https://www.yiiframework.com/).
283-

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "yiisoft/validator",
33
"type": "library",
4-
"description": "Yii validator",
4+
"description": "Yii Validator",
55
"keywords": [
66
"validation",
77
"validator"
@@ -34,10 +34,10 @@
3434
"yiisoft/translator": "dev-master"
3535
},
3636
"require-dev": {
37-
"phpunit/phpunit": "^9.4",
38-
"roave/infection-static-analysis-plugin": "^1.5",
37+
"phpunit/phpunit": "^9.5",
38+
"roave/infection-static-analysis-plugin": "^1.7",
3939
"spatie/phpunit-watcher": "^1.23",
40-
"vimeo/psalm": "^4.2"
40+
"vimeo/psalm": "^4.3"
4141
},
4242
"autoload": {
4343
"psr-4": {

src/ResultSet.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
namespace Yiisoft\Validator;
66

7+
use ArrayIterator;
8+
use InvalidArgumentException;
9+
use IteratorAggregate;
10+
711
/**
812
* ResultSet stores validation result of each attribute from {@link DataSetInterface}.
913
* It is typically obtained by validating data set with {@link Validator}.
1014
*/
11-
final class ResultSet implements \IteratorAggregate
15+
final class ResultSet implements IteratorAggregate
1216
{
1317
/**
1418
* @var Result[]
@@ -34,17 +38,14 @@ public function addResult(
3438
public function getResult(string $attribute): Result
3539
{
3640
if (!isset($this->results[$attribute])) {
37-
throw new \InvalidArgumentException("There is no result for attribute \"$attribute\"");
41+
throw new InvalidArgumentException("There is no result for attribute \"$attribute\"");
3842
}
3943

4044
return $this->results[$attribute];
4145
}
4246

43-
/**
44-
* @return \ArrayIterator|Result[]|\Traversable
45-
*/
46-
public function getIterator()
47+
public function getIterator(): ArrayIterator
4748
{
48-
return new \ArrayIterator($this->results);
49+
return new ArrayIterator($this->results);
4950
}
5051
}

src/Rule/Email.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ protected function validateValue($value, DataSetInterface $dataSet = null): Resu
6969
)) {
7070
$valid = false;
7171
} else {
72+
/** @psalm-var array{name:string,local:string,open:string,domain:string,close:string} $matches */
7273
if ($this->enableIDN) {
7374
$matches['local'] = $this->idnToAscii($matches['local']);
7475
$matches['domain'] = $this->idnToAscii($matches['domain']);

0 commit comments

Comments
 (0)