1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Yiisoft\Yii\Debug\Collector; |
||
6 | |||
7 | use Traversable; |
||
8 | use Yiisoft\Validator\Result; |
||
9 | |||
10 | final class ValidatorCollector implements SummaryCollectorInterface |
||
11 | { |
||
12 | use CollectorTrait; |
||
13 | |||
14 | private array $validations = []; |
||
15 | |||
16 | 1 | public function getCollected(): array |
|
17 | { |
||
18 | 1 | return $this->validations; |
|
19 | } |
||
20 | |||
21 | 1 | public function collect(mixed $value, Result $result, ?iterable $rules = null): void |
|
22 | { |
||
23 | 1 | if (!$this->isActive()) { |
|
24 | return; |
||
25 | } |
||
26 | |||
27 | 1 | $this->validations[] = [ |
|
28 | 'value' => $value, |
||
29 | 1 | 'rules' => $rules instanceof Traversable ? iterator_to_array($rules, true) : (array) $rules, |
|
30 | 1 | 'result' => $result->isValid(), |
|
31 | 1 | 'errors' => $result->getErrors(), |
|
32 | ]; |
||
33 | } |
||
34 | |||
35 | 1 | private function reset(): void |
|
0 ignored issues
–
show
|
|||
36 | { |
||
37 | 1 | $this->validations = []; |
|
38 | } |
||
39 | |||
40 | 1 | public function getSummary(): array |
|
41 | { |
||
42 | 1 | $count = count($this->validations); |
|
43 | 1 | $countValid = count(array_filter($this->validations, fn (array $data) => $data['result'])); |
|
44 | 1 | $countInvalid = $count - $countValid; |
|
45 | |||
46 | return [ |
||
47 | 'validator' => [ |
||
48 | 'total' => $count, |
||
49 | 'valid' => $countValid, |
||
50 | 'invalid' => $countInvalid, |
||
51 | ], |
||
52 | ]; |
||
53 | } |
||
54 | } |
||
55 |
This check looks for private methods that have been defined, but are not used inside the class.