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

Json   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 22
ccs 4
cts 5
cp 0.8
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getOptions() 0 8 1
A __construct() 0 6 1
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