Completed
Push — master ( 7ae754...4444a4 )
by Nate
01:19
created

Domain::rules()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 46
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 46
ccs 0
cts 46
cp 0
rs 8.9411
c 0
b 0
f 0
cc 1
eloc 24
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/domains/license
6
 * @link       https://www.flipboxfactory.com/software/domains/
7
 */
8
9
namespace flipbox\domains\models;
10
11
use Craft;
12
use craft\base\ElementInterface;
13
use flipbox\domains\Domains as DomainsPlugin;
14
use flipbox\domains\fields\Domains;
15
use flipbox\domains\validators\DomainValidator;
16
use flipbox\spark\helpers\ModelHelper;
17
use flipbox\spark\models\Model;
18
use flipbox\spark\traits\ElementAttribute;
19
20
/**
21
 * @author Flipbox Factory <[email protected]>
22
 * @since  1.0.0
23
 */
24
class Domain extends Model
25
{
26
    use ElementAttribute;
27
28
    /**
29
     * @var string
30
     */
31
    public $domain;
32
33
    /**
34
     * @var int|null
35
     */
36
    public $siteId;
37
38
    /**
39
     * @var string|null
40
     */
41
    public $status;
42
43
    /**
44
     * @var int|null
45
     */
46
    public $sortOrder;
47
48
    /**
49
     * @var Domains
50
     */
51
    private $field;
52
53
    /**
54
     * @inheritdoc
55
     */
56
    public function __construct(Domains $field, array $config = [])
57
    {
58
        $this->field = $field;
59
        parent::__construct($config);
60
    }
61
62
    /**
63
     * @return array
64
     */
65
    public function rules(): array
66
    {
67
        return array_merge(
68
            parent::rules(),
69
            $this->elementRules(),
70
            [
71
                [
72
                    [
73
                        'domain',
74
                        'status',
75
                        'elementId'
76
                    ],
77
                    'required'
78
                ],
79
                [
80
                    [
81
                        'siteId',
82
                        'sortOrder'
83
                    ],
84
                    'number',
85
                    'integerOnly' => true
86
                ],
87
                [
88
                    'domain',
89
                    DomainValidator::class
90
                ],
91
                [
92
                    'status',
93
                    'in',
94
                    'range' => array_keys($this->field->getStatuses())
95
                ],
96
                [
97
                    [
98
                        'domain',
99
                        'status',
100
                        'siteId',
101
                        'sortOrder'
102
                    ],
103
                    'safe',
104
                    'on' => [
105
                        ModelHelper::SCENARIO_DEFAULT
106
                    ]
107
                ]
108
            ]
109
        );
110
    }
111
112
    /**
113
     * @return Domains
114
     */
115
    public function getField(): Domains
116
    {
117
        return $this->field;
118
    }
119
120
    /**
121
     * @return array
122
     */
123
    public function attributes()
124
    {
125
        return array_merge(
126
            parent::attributes(),
127
            $this->elementAttributes(),
128
            [
129
                'domain',
130
            ]
131
        );
132
    }
133
134
    /**
135
     * @inheritdoc
136
     */
137
    public function attributeLabels()
138
    {
139
        return array_merge(
140
            parent::attributeLabels(),
141
            $this->elementAttributeLabels(),
142
            [
143
                'domain' => Craft::t('domains', 'Domain'),
144
            ]
145
        );
146
    }
147
}
148