Passed
Pull Request — master (#132)
by Dmitriy
05:52 queued 02:50
created

ValidatorCollector::getCollected()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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 CollectorInterface, IndexCollectorInterface
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, iterable $rules, Result $result): 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
Unused Code introduced by
The method reset() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
36
    {
37 1
        $this->validations = [];
38
    }
39
40 1
    public function getIndexData(): 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
                'count.total' => $count,
49
                'count.valid' => $countValid,
50
                'count.invalid' => $countInvalid,
51
            ],
52
        ];
53
    }
54
}
55