Conditions | 4 |
Paths | 8 |
Total Lines | 27 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Tests | 5 |
CRAP Score | 10.3998 |
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 | if($description->getAutoPrimaryKey()) { |
||
19 | $pk = $description->getPrimaryKey()[0]; |
||
20 | } |
||
21 | |||
22 | $fields = $description->getFields(); |
||
23 | foreach($fields as $field) { |
||
24 | $this->getFieldRules($rules, $field, $pk); |
||
25 | } |
||
26 | |||
27 | $unique = $description->getUniqueKeys(); |
||
28 | foreach($unique as $constraints) { |
||
29 | $rules['unique'][] = [$constraints['fields']]; |
||
30 | } |
||
31 | |||
32 | $this->setRules($rules); |
||
33 | $this->registerValidation( |
||
34 | 'unique', |
||
35 | '\ntentan\nibii\validations\UniqueValidation', |
||
36 | ['model' => $model, 'mode' => $mode] |
||
37 | ); |
||
38 | } |
||
39 | |||
50 |