Conditions | 4 |
Paths | 8 |
Total Lines | 27 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Tests | 19 |
CRAP Score | 4 |
Changes | 4 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
12 | 10 | public function __construct($model, $mode) { |
|
13 | 10 | $pk = null; |
|
14 | 10 | $rules = []; |
|
15 | 10 | $this->model = $model; |
|
16 | 10 | $description = $model->getDescription(); |
|
17 | |||
18 | 10 | if($description->getAutoPrimaryKey()) { |
|
19 | 10 | $pk = $description->getPrimaryKey()[0]; |
|
20 | } |
||
21 | |||
22 | 10 | $fields = $description->getFields(); |
|
23 | 10 | foreach($fields as $field) { |
|
24 | 10 | $this->getFieldRules($rules, $field, $pk); |
|
25 | } |
||
26 | |||
27 | 10 | $unique = $description->getUniqueKeys(); |
|
28 | 10 | foreach($unique as $constraints) { |
|
29 | 6 | $rules['unique'][] = [$constraints['fields']]; |
|
30 | } |
||
31 | |||
32 | 10 | $this->setRules($rules); |
|
33 | 10 | $this->registerValidation( |
|
34 | 10 | 'unique', |
|
35 | 10 | '\ntentan\nibii\validations\UniqueValidation', |
|
36 | 10 | ['model' => $model, 'mode' => $mode] |
|
37 | ); |
||
38 | 10 | } |
|
39 | |||
50 |