Passed
Push — master ( f2dea1...58a092 )
by Nate
04:47
created

RecordWithHandle   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 0
dl 0
loc 68
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B handleRules() 0 42 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipbox/spark/blob/master/LICENSE
6
 * @link       https://github.com/flipbox/spark
7
 */
8
9
namespace flipbox\spark\records\traits;
10
11
use craft\validators\HandleValidator;
12
use flipbox\spark\helpers\RecordHelper;
13
14
/**
15
 * @property string $handle
16
 *
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.2.0
19
 */
20
trait RecordWithHandle
21
{
22
23
    /**
24
     * @var array
25
     */
26
    protected $reservedHandleWords = [
27
        'id',
28
        'uid',
29
    ];
30
31
    /**
32
     * @var int
33
     */
34
    protected $handleLength = 150;
35
36
    /**
37
     * @var string Handle
38
     */
39
    public $handle;
40
41
    /**
42
     * @inheritdoc
43
     */
44
    protected function handleRules()
45
    {
46
47
        return [
48
            [
49
                [
50
                    'handle'
51
                ],
52
                HandleValidator::class,
53
                'reservedWords' => $this->reservedHandleWords
54
            ],
55
            [
56
                [
57
                    'handle'
58
                ],
59
                'unique'
60
            ],
61
            [
62
                [
63
                    'handle'
64
                ],
65
                'required'
66
            ],
67
            [
68
                [
69
                    'handle'
70
                ],
71
                'string',
72
                'max' => $this->handleLength
73
            ],
74
            [
75
                [
76
                    'handle'
77
                ],
78
                'safe',
79
                'on' => [
80
                    RecordHelper::SCENARIO_DEFAULT
81
                ]
82
            ]
83
        ];
84
85
    }
86
87
}
88