Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
Type | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
100.00% |
4 / 4 |
|
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\Schema\Validate\Values; |
10 | |
11 | use Selen\Data\Types; |
12 | use Selen\Schema\Validate\Model\ValidateResult; |
13 | use Selen\Schema\Validate\ValueValidateInterface; |
14 | |
15 | class Type implements ValueValidateInterface |
16 | { |
17 | /** @var string */ |
18 | protected $messageFormat = 'Invalid type. expected type %s.'; |
19 | |
20 | /** @var string[] */ |
21 | private $names; |
22 | |
23 | public function __construct(string ...$names) |
24 | { |
25 | $this->names = $names; |
26 | } |
27 | |
28 | public function execute($value, ValidateResult $result): ValidateResult |
29 | { |
30 | if (Types::validate($value, ...$this->names)) { |
31 | return $result; |
32 | } |
33 | |
34 | $mes = \sprintf($this->messageFormat, \implode(', ', $this->names)); |
35 | return $result->setResult(false)->setMessage($mes); |
36 | } |
37 | } |