Passed
Pull Request — master (#222)
by Dmitriy
02:26
created

Json::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Rule\Json;
6
7
use Attribute;
8
use Closure;
9
use Yiisoft\Validator\Rule\RuleNameTrait;
10
use Yiisoft\Validator\Rule\HandlerClassNameTrait;
11
use Yiisoft\Validator\RuleInterface;
12
13
/**
14
 * Validates that the value is a valid json.
15
 */
16
#[Attribute(Attribute::TARGET_PROPERTY)]
17
final class Json implements RuleInterface
18
{
19
    use HandlerClassNameTrait;
20
    use RuleNameTrait;
21
22
    public function __construct(
23
        public string $message = 'The value is not JSON.',
24
        public bool $skipOnEmpty = false,
25
        public bool $skipOnError = false,
26
        public ?Closure $when = null,
27
    ) {
28
    }
29
30 1
    public function getOptions(): array
31
    {
32
        return [
33
            'message' => [
34 1
                'message' => $this->message,
35
            ],
36 1
            'skipOnEmpty' => $this->skipOnEmpty,
37 1
            'skipOnError' => $this->skipOnError,
38
        ];
39
    }
40
}
41