Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
Key | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * @license MIT |
5 | * @author hazuki3417<hazuki3417@gmail.com> |
6 | * @copyright 2022 hazuki3417 all rights reserved. |
7 | */ |
8 | |
9 | namespace Selen\MongoDB\Validator; |
10 | |
11 | use Selen\Data\ArrayPath; |
12 | use Selen\MongoDB\Validator\Model\ValidateResult; |
13 | use Selen\MongoDB\Validator\Model\ValidatorResult; |
14 | |
15 | class Key |
16 | { |
17 | /** @var ArrayPath */ |
18 | private $arrayPath; |
19 | |
20 | public function __construct(ArrayPath $arrayPath) |
21 | { |
22 | $this->arrayPath = $arrayPath; |
23 | } |
24 | |
25 | /** |
26 | * 値の検証を実行します |
27 | * |
28 | * @param string $key 検証する値を保持しているキー名を渡します |
29 | * @param array<mixed,mixed> $input 検証する値を渡します |
30 | */ |
31 | public function execute(string $key, array $input): ValidatorResult |
32 | { |
33 | $this->arrayPath->setCurrentPath($key); |
34 | |
35 | if (\array_key_exists($key, $input)) { |
36 | return new ValidatorResult(); |
37 | } |
38 | |
39 | $validateResult = new ValidateResult( |
40 | false, |
41 | ArrayPath::toString($this->arrayPath->getPaths()), |
42 | 'field is required.' |
43 | ); |
44 | |
45 | return new ValidatorResult($validateResult); |
46 | } |
47 | } |