HandleRulesTrait::handleRules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 0
cts 34
cp 0
rs 9.376
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipboxfactory/craft-ember/blob/master/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-ember/
7
 */
8
9
namespace flipbox\craft\ember\models;
10
11
use craft\validators\HandleValidator;
12
use yii\base\Model;
13
14
/**
15
 * @property string|null $handle
16
 *
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 2.0.0
19
 */
20
trait HandleRulesTrait
21
{
22
    /**
23
     * @var array
24
     */
25
    protected $reservedHandleWords = [
26
        'id',
27
        'uid',
28
    ];
29
30
    /**
31
     * @var int
32
     */
33
    protected $handleLength = 150;
34
35
    /**
36
     * @inheritdoc
37
     */
38
    public function handleRules()
39
    {
40
        return [
41
            [
42
                [
43
                    'handle'
44
                ],
45
                HandleValidator::class,
46
                'reservedWords' => $this->reservedHandleWords
47
            ],
48
            [
49
                [
50
                    'handle'
51
                ],
52
                'required'
53
            ],
54
            [
55
                [
56
                    'handle'
57
                ],
58
                'string',
59
                'max' => $this->handleLength
60
            ],
61
            [
62
                [
63
                    'handle'
64
                ],
65
                'safe',
66
                'on' => [
67
                    Model::SCENARIO_DEFAULT
68
                ]
69
            ]
70
        ];
71
    }
72
}
73