Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
ArrayNotEmpty | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
execute | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | /** |
4 | * @license MIT |
5 | * @author hazuki3417<hazuki3417@gmail.com> |
6 | * @copyright 2023 hazuki3417 all rights reserved. |
7 | */ |
8 | |
9 | namespace Selen\Schema\Validate\Values; |
10 | |
11 | use Selen\Schema\Validate\Model\ValidateResult; |
12 | use Selen\Schema\Validate\ValueValidateInterface; |
13 | |
14 | class ArrayNotEmpty implements ValueValidateInterface |
15 | { |
16 | public function execute($value, ValidateResult $result): ValidateResult |
17 | { |
18 | if (!\is_array($value)) { |
19 | $mes = 'Skip validation. Executed only when the value is of array type.'; |
20 | return $result->setResult(true)->setMessage($mes); |
21 | } |
22 | |
23 | if (empty($value)) { |
24 | $mes = 'Invalid value. Must have at least one element.'; |
25 | return $result->setResult(false)->setMessage($mes); |
26 | } |
27 | |
28 | return $result->setResult(true); |
29 | } |
30 | } |