Passed
Pull Request — master (#222)
by Dmitriy
12:29
created

Json   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
dl 0
loc 50
ccs 13
cts 13
cp 1
rs 10
c 1
b 0
f 0
wmc 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Rule;
6
7
use Attribute;
8
use Closure;
9
use Yiisoft\Validator\Rule\Trait\RuleNameTrait;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_TRAIT, expecting T_STRING or '{' on line 9 at column 27
Loading history...
10
use Yiisoft\Validator\Rule\Trait\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